I cannot get the environment in the custom target shell

I cannot get the environment in the custom target shell.

CMakeList.txt

set( ENV{TEST_VAR} "Hello" ) add_custom_target( test COMMAND ./test.sh WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} ) 

test.sh

 echo test:${TEST_VAR} 

when trying to "do a test", the shell cannot get $ {TEST_VAR}.

Thanks.

+6
source share
1 answer

You should use the trick because the SET environment variables in CMakeLists.txt are only valid for cmake itself, so you cannot use this method to set the environment variable that may be required for a user command:

test.cmake

 set( ENV{TEST_VAR} "Hello" ) execute_process( COMMAND ./test.sh WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} ) 

CMakeLists.txt

 add_custom_target( test COMMAND ${CMAKE_COMMAND} -P test.cmake ) 
+6
source

Source: https://habr.com/ru/post/910969/


All Articles