Search code examples
cmakeenvironment-variablesinclude-path

Use environment variable to set `include_directories`


I have an environment variable that contains paths to manually 'installed' header only libraries:

export INCLUDE_PATH="/some/path":"${INCLUDE_PATH}"

I want to use this in my CMakeLists.txt. But when I do:

include_directories("$ENV{INCLUDE_PATH}")

the paths appear not be properly added (no CMake error, but the compiler does not know where to look).


Solution

  • You can try to replace the ':' char to ';'. The ';' is the way CMake deals with lists.

    string(REPLACE ":" ";" INCLUDE_LIST $ENV{INCLUDE_PATH})
    
    include_directories(${INCLUDE_LIST})