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 )
Simon source share