Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I can not get environment at custom target shell

Tags:

cmake

I can not get environment at 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 try to "make test", shell can't get ${TEST_VAR}.

Thank you.

like image 437
jongwon.kwak Avatar asked Mar 17 '12 05:03

jongwon.kwak


1 Answers

You have to use a trick because environment variables SET in the CMakeLists.txt only take effect for cmake itself, so you cannot use this method to set an environment variable that a custom command might need:

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 )
like image 63
Simon Avatar answered Oct 28 '22 01:10

Simon