[CMake] execute a script before and after configuration

Eric Noulard eric.noulard at gmail.com
Sat Jan 21 14:11:03 EST 2012


2012/1/21 Dominik Szczerba <dominik at itis.ethz.ch>:
>> Running something from the command line does not mean it doesn't change the
>> environment.
>>
>> Would you try
>>
>> $ env > env1.txt
>> $ module unload sysmodule_you_dont_want
>> $ env > env2.txt
>> $ cmake -E compare_files env1.txt env2.txt
>>
>> I'd be surprise if nothing changed but I may be wrong.
>
> You are of course right, but this is not the scenario here. If you put
> "module un/load XXX" into a bash script, and call it from command
> line, it will only modify the env for this script/process. On the
> return your original env will not be changed.

The very same scenario is happening with CMake.

> To change it,  you need
> to "source" your script, but that is what seems to do nothing with
> cmake.

Yes that's precisely the point CMake is not behaving like a shell at ALL
with respect to env var.

Re-read my other message.

When cmake executes a command (using e.g. execute_process)
it "forks" that is a NEW process which is a child of current cmake process
is created, then the command/executable is run within the child
(or replace the child http://en.wikipedia.org/wiki/Fork-exec)
then the child terminates and CMake continue with other
command with may be other child process.

So when you "COMMAND module unload blah" this only
affect the current child.

That's the same difference between "sourcing" a script and "running it"
with CMake you have no way to "source a shell script" because CMake
is not the shell.



More information about the CMake mailing list