Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. CMake and external libraries with Creator
Forum Updated to NodeBB v4.3 + New Features

CMake and external libraries with Creator

Scheduled Pinned Locked Moved Unsolved Qt Creator and other tools
3 Posts 2 Posters 873 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • mzimmersM Offline
    mzimmersM Offline
    mzimmers
    wrote on last edited by mzimmers
    #1

    Hi all -

    I'm editing a CMakeLists.txt file for a project that uses a third-party library. The location of this library is subject to change, so I'm trying to do something like this:

    if(DEFINED ENV{XXX_LIBRARY_PATH})
        set(LIBRARY_PATH $ENV{XXX_LIBRARY_PATH})
    else()
        message(FATAL_ERROR "Error: environment variable XXX_LIBRARY_PATH' not set; exiting." )
    endif()
    
    include_directories("."
    "${LIBRARY_PATH}/include"
    

    where XXX_LIBRARY_PATH is an environment variable. This works when I run cmake from the CLI, but I'm not picking up my environment variable when I run cmake from Creator.

    I've tried defining it in .bashrc, and in .profile -- neither works. Can someone tell me what I'm doing wrong?

    Thanks...

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mchinand
      wrote on last edited by
      #2

      You can use something like this:

      set(XXX_LIBRARY_PATH "/usr/local/defaultlibrarypath" CACHE PATH "Path to library XXX")

      where "/usr/local/defaultlibrarypath" is a default location (you might be able to still use an environment variable like you do above, I'm not positive), but then you can modify the location locally using QtCreator's Project->Build settings. This allows you to have a local library path setting without having to modify the CMakeLists.txt file.

      mzimmersM 1 Reply Last reply
      2
      • M mchinand

        You can use something like this:

        set(XXX_LIBRARY_PATH "/usr/local/defaultlibrarypath" CACHE PATH "Path to library XXX")

        where "/usr/local/defaultlibrarypath" is a default location (you might be able to still use an environment variable like you do above, I'm not positive), but then you can modify the location locally using QtCreator's Project->Build settings. This allows you to have a local library path setting without having to modify the CMakeLists.txt file.

        mzimmersM Offline
        mzimmersM Offline
        mzimmers
        wrote on last edited by mzimmers
        #3

        @mchinand I think this is a good approach. Here's what I've done:

        // somewhere in bash-land
        export XXX_LIBRARY_PATH="/home/mzimmers/wiced/sdk/WICED-Studio-6.6/43xxx_Wi-Fi/"
        
        // added to Build Settings -> Initial CMake parameters
        -DLIBRARY_PATH="$ENV{XXX_LIBRARY_PATH}"
        
        // in my CMakeLists.txt file
        set (LIBRARY_PATH "/xxx/" CACHE PATH "Path to SDK libraries") # default location in case no env variable exists.
        

        cmake seems to accept all of this. The missing ingredient seemed to be the cmake parameter that acts as the middleman between the environment variable and the variable in the configuration file. Thanks for the help.

        EDIT: I need to re-open this. While CMake does indeed accept this, it doesn't appear to decode the environment variable.
        qt.PNG

        In my configuration file:

        message ("LIBRARY_PATH is " ${LIBRARY_PATH})
        

        Outputs:

        LIBRARY_PATH is "$ENV{FLUIDRA_LIBRARY_PATH}"
        

        I'm guessing it's syntax error on my part in the CMake parameter...can someone tell me what I might be doing wrong? Thanks...

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved