[CMake] Regarding enviroment variables directly used in executables

Ravi Raman ravi.raman at Xoriant.Com
Thu Aug 14 08:55:11 EDT 2014


Hi David,

In our cmake project, we have the following scenario:


1.       add_custom_command() call is as follows:
                add_custom_command(TARGET ${TESTTARGETNAME}
                                                                  POST_BUILD
                                                                  COMMENT "Test target 1..."
                                                                  COMMAND python ${CMAKE_SOURCE_DIR}/testthetargets.bat "TestTarget1" "${TESTBIN}"
                                                                 )


2.       The code in the batch file testthetargets.bat is as follows:

It invokes a project specific executable testtarget1.exe.

The source code of  testtarget1.exe has calls to get few environment variables using getenv() function call.



For example, a sample getenv() call is as follows:

target2_exe_path = getenv("TARGET2_EXE_PATH");



So, here the above getenv() call is supposed to get the value of environment variable TARGET2_EXE_PATH.

Issue we are facing is as follows:

1.       We set environment variable TARGET2_EXE_PATH using the following cmake SET command before the add_custom_command() execution:

SET(ENV{TARGET2_EXE_PATH} "C:/Test/Target2")

2.       But when the add_custom_command() gets executed, we observe that the environment variable TARGET2_EXE_PATH is not getting reflected in the above getenv() call in the source code of  testtarget1.exe. The getenv() call returns an empty string.

But this issue does not occur when TARGET2_EXE_PATH environment variable is set from Windows directly (i.e. from System Properties -> Advanced -> Environment Variables). In that case, TARGET2_EXE_PATH gets reflected in the above getenv() call.

So, basically the call to SET(ENV{TARGET2_EXE_PATH} "C:/Test/Target2") has no impact on the call to getenv() in the source code.

Kindly let us know if there is any other way in this case other than setting the TARGET2_EXE_PATH environment variable from Windows directly ?

Thanks & Regards

Ravi Raman
Xoriant Solutions Pvt. Ltd
4th Floor, Winchester, Hiranandani Business Park, Powai, Mumbai 400076, INDIA.
Tel: +91 22 30511000,9930100026 Extn: 2144 Voip No. 4088344495/96/97/98 Voip Extn:1178| Fax: +91 22 30511111
ravi.raman at xoriant.com<mailto:ram.singh at xoriant.com>| http://www.xoriant.com<http://www.xoriant.com/>





-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20140814/f6beb2bc/attachment-0001.html>


More information about the CMake mailing list