View Issue Details Jump to Notes ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0014306CMakeCMakepublic2013-07-24 03:452016-06-10 14:31
Reporterycollet 
Assigned ToKitware Robot 
PrioritynormalSeverityminorReproducibilityalways
StatusclosedResolutionmoved 
Platformx86OSLinuxOS Version
Product VersionCMake 2.8.9 
Target VersionFixed in Version 
Summary0014306: environment variable set in a add_custom_target is forgotten
DescriptionUnder 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.
Steps To ReproduceI added an archive with the test case.
TagsNo tags attached.
Attached Fileszip file icon tmp.zip [^] (991 bytes) 2013-07-24 03:45

 Relationships

  Notes
(0033595)
Brad King (manager)
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 (administrator)
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.

 Issue History
Date Modified Username Field Change
2013-07-24 03:45 ycollet New Issue
2013-07-24 03:45 ycollet File Added: tmp.zip
2013-07-24 13:53 Brad King Note Added: 0033595
2013-07-24 13:53 Brad King Status new => backlog
2016-06-10 14:29 Kitware Robot Note Added: 0042323
2016-06-10 14:29 Kitware Robot Status backlog => resolved
2016-06-10 14:29 Kitware Robot Resolution open => moved
2016-06-10 14:29 Kitware Robot Assigned To => Kitware Robot
2016-06-10 14:31 Kitware Robot Status resolved => closed


Copyright © 2000 - 2018 MantisBT Team