[CMake] Set environment variables for a custom command

Brad King brad.king at kitware.com
Fri Mar 3 17:48:05 EST 2006


Anton Deguet wrote:
> Is it possible to define some environment variables for each
> ADD_CUSTOM_COMMAND / POST_BUILD?

For some generators it is tricky to set the environment in which a 
custom command runs, but it may be possible.  In the worst case we add 
an "env" option to the "cmake -E" mode.  Then you could do something like

ADD_CUSTOM_COMMAND(TARGET myExec
   POST_BUILD
   COMMAND ${CMAKE_COMMAND} -E env
   "PATH=${LIBRARY_OUTPUT_PATH}/${CMAKE_CFG_INTDIR}"
   "PYTHONPATH=${MY_PYTHON_PATH}/${CMAKE_CFG_INTDIR}"
   myExec -CTestList
)

I'm not sure when we can get to this but to avoid forgetting about it 
please submit a feature request here:

http://www.cmake.org/Bug

Meanwhile you can write your own small executable (even in plain C) that 
can serve as an environment-setting front-end for custom commands.

-Brad


More information about the CMake mailing list