Discussion:
[CMake] Set environment variables for a custom command
Anton Deguet
2006-03-02 21:20:19 UTC
Permalink
Hello,

Is it possible to define some environment variables for each
ADD_CUSTOM_COMMAND / POST_BUILD?

In my case, I compile and build a single test driver for multiple test
cases. Once the test driver is compiled, CMake automatically run it
with a special option to generate a list of test cases compatible with
CTest. I am running into two problems with this post built target:

-1- On Windows, I am using DLLs and these DLLs are not in the same
directory. Furthermore, I have some Debug DLLs and some Release DLLs
therefore I would need some kind of PATH=/myPathToLibs/$(IntDir) (for MS
Visual Studio only). On Unix, I am currently using rpath even thought I
believe that a solution based on LD_LIBRARY_PATH would be better.

-2- My test program also requires to set PYTHONPATH. Again, my SWIG
generated code is compiled in Release/Debug mode therefore I would like
this variable to be defined using $(IntDir).


Since our code is currently supported on Linux (gmake/gcc, gmake/icc),
Windows (MS Visual Studio, MS nmake) and Mac OS X (gmake/gcc,
XCode/gcc), I need a portable solution able to handle multiple
configurations.

Is there such a thing as:
ADD_CUSTOM_COMMAND(TARGET ...
POST_BUILD
COMMAND ... ARGS ...
ENV varName varValue [APPEND]
...)

I would use it as:
ADD_CUSTOM_COMMAND(TARGET myExec
POST_BUILD
COMMAND myExec ARGS -CTestList
ENV PATH ${LIBRARY_OUTPUT_PATH}/${CMAKE_CFG_INTDIR} APPEND
ENV PYTHONPATH ${MY_PYTHON_PATH}/${CMAKE_CFG_INTDIR} APPEND
)


Thank you,

Anton Deguet
--
Anton Deguet <***@jhu.edu>
ERC CISST Johns Hopkins University
Brad King
2006-03-03 22:48:05 UTC
Permalink
Post by Anton Deguet
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

Loading...