[CMake] Adding custom directories to PATH enviroment
Michael Wild
themiwi at gmail.com
Wed Apr 13 06:28:42 EDT 2011
On 04/13/2011 11:51 AM, Gabriele Greco wrote:
> Hi,
>
> I've started using cmake on my projects since a few weeks so I'm still a
> beginner.
>
> The system works very well I only have a problem.
>
> I need to have a directory inside the project tree included in the
> command search path (the enviroment variable PATH).
>
> I tried with:
>
> set(ENV{PATH} "${PROJECT_SOURCE_DIR}/ext_bin/DFC:$ENV{PATH}")
>
> but as I found googling around this command works only in the "cmake"
> stage, but not on the generated makefiles.
>
> There is a way to tell CMake to make a change to an enviroment variable
> that is effective also inside the generated makefiles?
>
> --
> Gabriele Greco, DARTS Engineering
Wrap the command in a CMake-script. Something like this:
foo_wrapper.cmake.in:
---------------------
set(ENV{PATH} "@PROJECT_SOURCE_DIR@/ext_bin/DFC:$ENV{PATH}")
execute_process(COMMAND foo)
And then configure and run it like this:
CMakeLists.txt:
---------------
# ...
configure_file(foo_wrapper.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/foo_wrapper.cmake" @ONLY)
add_custom_command(OUTPUT bar
COMMAND "${CMAKE_COMMAND}" -P
"${CMAKE_CURRENT_BINARY_DIR}/foo_wrapper.cmake"
COMMENT "Creating bar")
If you need to pass the script variables using the -D flags, make sure
to pass them before the -P flag, otherwise they are silently ignored.
I hope you get the idea.
Michael
More information about the CMake
mailing list