[cmake-developers] Setting up environment using ExternalProject_Add

Ruslan Baratov ruslan_baratov at yahoo.com
Tue Aug 18 12:45:24 EDT 2015


On 11-Aug-15 07:49, James Johnston wrote:
> I have found it annoyingly difficult to set up an environment for a build
> when using ExternalProject_Add.

I can confirm that there is an additional mess with the environment 
sometimes and not just about setting it (like vcvarsall.bat for Visual 
Studio) but with *un*setting them too. In short environment variables 
for the ExternalProject_Add are not the same as a user's environment. 
I've found myself some problems with Xcode which add tons of new 
variables but there are even cases for Makefiles (e.g. 
stackoverflow.com/questions/25160405/). I will not say it's an 
"annoying" thing for me but if there will be some mechanism to control 
it (better globally or even something "from the box") 
ExternalProject_Add code can be simplified. I'm personally using next 
patterns:

     CONFIGURE_COMMAND
"@MSVC_VCVARSALL@""@MSVC_ARCH@" # Set Visual Studio environment
     COMMAND
     ... # real configure command (like bootstrap.bat or configure.bat)


     BUILD_COMMAND
     . /path/to/clear-all.sh && make # run make in a clean environment
    INSTALL_COMMAND
    . /path/to/clear-all.sh && make install # same for make install

     include(/path/to/clear-all.cmake)
     execute_process(COMMAND make @make_params@ ...) # run make in a 
clean environment

Cheers, Ruslo


More information about the cmake-developers mailing list