[CMake] Set environment variables for a custom command

Anton Deguet anton.deguet at jhu.edu
Thu Mar 2 16:20:19 EST 2006


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 <anton.deguet at jhu.edu>
ERC CISST Johns Hopkins University


More information about the CMake mailing list