MantisBT - CMake
View Issue Details
0014306CMakeCMakepublic2013-07-24 03:452016-06-10 14:31
ycollet 
Kitware Robot 
normalminoralways
closedmoved 
x86Linux
CMake 2.8.9 
 
0014306: environment variable set in a add_custom_target is forgotten
Under windows, I set an environment variable and then launch a batch file which displays the value of the environment variable.

add_custom_target(test_env_var
                  COMMAND set MYENVVAR=this_is_a_test
                  COMMAND ${CMAKE_SOURCE_DIR}/echo.bat)

The variable is correctly displayed.

Under linux, I tried to do the same

add_custom_target(test_env_var
                  COMMAND export MYENVVAR=this_is_a_test
                  COMMAND ${CMAKE_SOURCE_DIR}/echo.sh)

The shell script displays an empty variable.
To be able to display the environment variable, I must do like this:

add_custom_target(test_env_var
                  COMMAND export MYENVVAR=this_is_a_test && ${CMAKE_SOURCE_DIR}/echo.sh)

And then it works.

Under linux, it's like a new shell is started each time a COMMAND is met.
Under windows, it's like a shell is started at the first COMMAND and the same shell is reused for each COMMAND.
I added an archive with the test case.
No tags attached.
zip tmp.zip (991) 2013-07-24 03:45
https://public.kitware.com/Bug/file/4823/tmp.zip
Issue History
2013-07-24 03:45ycolletNew Issue
2013-07-24 03:45ycolletFile Added: tmp.zip
2013-07-24 13:53Brad KingNote Added: 0033595
2013-07-24 13:53Brad KingStatusnew => backlog
2016-06-10 14:29Kitware RobotNote Added: 0042323
2016-06-10 14:29Kitware RobotStatusbacklog => resolved
2016-06-10 14:29Kitware RobotResolutionopen => moved
2016-06-10 14:29Kitware RobotAssigned To => Kitware Robot
2016-06-10 14:31Kitware RobotStatusresolved => closed

Notes
(0033595)
Brad King   
2013-07-24 13:53   
This is a platform-specific behavior that CMake does not abstract. There is work here on providing environment support in custom commands:

 https://github.com/Kitware/CMake/pull/31 [^]

Meanwhile you'll have to work around this by setting the environment variable in a script that launches the real process.
(0042323)
Kitware Robot   
2016-06-10 14:29   
Resolving issue as `moved`.

This issue tracker is no longer used. Further discussion of this issue may take place in the current CMake Issues page linked in the banner at the top of this page.