MantisBT - CMake
View Issue Details
0015927CMakeCMakepublic2016-01-19 10:072016-06-10 14:21
Gehua Yang 
 
normalminoralways
closedno change required 
Windows
CMake 3.4.1 
 
0015927: Escape semicolon ";" in CMake/CTest variables?
My CMake-Controlled private build depends on a couple external libraries. On Windows, the build needs to find the dll files of external libraries in order to run the automated tests. The solution I came up with is to add those folders to the PATH environment variable for the build. Here is what I did in the CTest script (using CMake 3.4.1 for Windows):

SET(MYPATH "$ENV{PATH}\;C:\\Gehua\\Code\\tbb\\tbb43_20150611oss\\bin\\intel64\\vc14")
# set any extra envionment variables here
# a. TBB path is needed to run tests
# b. Use the "true" command-line plink for git's ssh use.
SET (CTEST_ENVIRONMENT
  "GIT_SSH=c:\\Program Files (x86)\\PuTTY\\plink.exe"
  "PATH=${MYPATH}"
  )
MESSAGE(STATUS "env=${CTEST_ENVIRONMENT}")

Here is the output from running the build from the code above:

-- env=GIT_SSH=c:\Program Files (x86)\PuTTY\plink.exe;PATH=C:\ProgramData\Oracle\Java\javapath;C:\Program Files\Broadcom\Broadcom 802.11 Network Adapter;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;%USERPROFILE%\.dnx\bin;C:\Program Files (x86)\Skype\Phone\;C:\Program Files\IDM Computer Solutions\UltraCompare;C:\Program Files\IDM Computer Solutions\UltraFinder\\;C:\Gehua\Code\tbb\tbb43_20150611oss\bin\intel64\vc14


But this change does NOT work for the tests. The tests failed without execution. I suspected that it still did not find the depending dll files. So I added the following code in a simple test file:

  std::cout << "env PATH=" << getenv ("PATH") << '\n';
  std::cout << "env GIT_SSH=" << getenv ("GIT_SSH") << '\n';

The output is :

env PATH=C:\ProgramData\Oracle\Java\javapath
env GIT_SSH=c:\Program Files (x86)\PuTTY\plink.exe


As one can see, The PATH variable content was truncated at the semicolon mark (";"). It is not surprising outcome as CMake use semicolon as delimiter of list elements. But in this particular case, I am seeking for a way to escape the semicolons so that CMake/CTest treats it as an integral part of the string. Is there a way to do it?
SET(MYPATH "$ENV{PATH}\;C:\\Gehua\\Code\\tbb\\tbb43_20150611oss\\bin\\intel64\\vc14")
# set any extra envionment variables here
# a. TBB path is needed to run tests
# b. Use the "true" command-line plink for git's ssh use.
SET (CTEST_ENVIRONMENT
  "GIT_SSH=c:\\Program Files (x86)\\PuTTY\\plink.exe"
  "PATH=${MYPATH}"
  )
MESSAGE(STATUS "env=${CTEST_ENVIRONMENT}")


But the result is:
PATH=C:\ProgramData\Oracle\Java\javapath
GIT_SSH=c:\Program Files (x86)\PuTTY\plink.exe
No tags attached.
Issue History
2016-01-19 10:07Gehua YangNew Issue
2016-01-19 10:13Brad KingNote Added: 0040259
2016-01-19 15:25Gehua YangNote Added: 0040271
2016-01-20 10:29Brad KingStatusnew => resolved
2016-01-20 10:29Brad KingResolutionopen => no change required
2016-06-10 14:21Kitware RobotNote Added: 0041281
2016-06-10 14:21Kitware RobotStatusresolved => closed

Notes
(0040259)
Brad King   
2016-01-19 10:13   
The CTEST_ENVIRONMENT setting is an undocumented legacy variable left from early ctest scripts that worked declaratively. For modern ctest scripts you can just

  set(ENV{PATH} "...")

and the environment setting will affect everything after that.
(0040271)
Gehua Yang   
2016-01-19 15:25   
Thanks for the info. I will try that.

Gary
(0041281)
Kitware Robot   
2016-06-10 14:21   
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.