CMake and external libraries with Creator
-
wrote on 2 Sept 2021, 20:21 last edited by mzimmers 9 Feb 2021, 20:23
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...
-
wrote on 3 Sept 2021, 13:35 last edited by
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.
-
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.
wrote on 3 Sept 2021, 17:12 last edited by mzimmers 9 Jun 2021, 14:01@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.
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/3