MantisBT - CMake
View Issue Details
0015076CMake(No Category)public2014-08-10 16:532016-06-10 14:31
Piotr Dziwinski 
Kitware Robot 
normalminoralways
closedmoved 
LinuxArch Linux
CMake 3.0 
 
0015076: CMake does not support source/build trees with ';' in the path
While discussing use of proper quoting of variables in CMake (https://github.com/colobot/colobot/issues/317 [^]), I happened to notice this bug. If you run CMake with a binary directory which contains special characters like semicolons, CMake fails with errors coming from core CMake modules for checking compiler and platform:

CMake Error at /usr/share/cmake-3.0/Modules/CMakeDetermineCompilerId.cmake:107 (file):
  file Internal CMake error when trying to open file:
  /tmp/cmake-test/directory with semicolons a for writing.
Call Stack (most recent call first):
  /usr/share/cmake-3.0/Modules/CMakeDetermineCompilerId.cmake:117 (CMAKE_DETERMINE_COMPILER_ID_WRITE)
  /usr/share/cmake-3.0/Modules/CMakeDetermineCompilerId.cmake:39 (CMAKE_DETERMINE_COMPILER_ID_BUILD)
  /usr/share/cmake-3.0/Modules/CMakeDetermineCCompiler.cmake:108 (CMAKE_DETERMINE_COMPILER_ID)
  CMakeLists.txt:2 (project)


There are many more such errors coming from modules like CMakeDetermineSystem, CMakeDetermineCCompiler, CMakeTestCCompiler, etc.

The problem seems to be caused by improper quoting of ${CMAKE_BINARY_DIR} and related variables within those modules. I have attached a diff that solves the problem in provided simple case of C/C++ project, but I see that same issue occurs in many other places in CMake modules.
$ cat > CMakeLists.txt <<EOF
cmake_minimum_required(VERSION 2.8)
project(test C CXX)
add_executable(test_proj test_proj.cpp)
EOF

$ echo "int main() { return 0; }" > test_proj.cpp

$ mkdir "directory with semicolons a;b;c"

$ cd "directory with semicolons a;b;c"

$ cmake ../
No tags attached.
diff binary_dir_quoting_fix.diff (21,634) 2014-08-10 16:53
https://public.kitware.com/Bug/file/5226/binary_dir_quoting_fix.diff
Issue History
2014-08-10 16:53Piotr DziwinskiNew Issue
2014-08-10 16:53Piotr DziwinskiFile Added: binary_dir_quoting_fix.diff
2014-08-11 10:22Brad KingNote Added: 0036592
2014-08-11 12:07Piotr DziwinskiNote Added: 0036596
2014-08-11 12:52Brad KingNote Added: 0036597
2014-08-11 16:35Markus ElfringNote Added: 0036599
2014-08-12 09:31Brad KingNote Added: 0036601
2014-08-12 09:32Brad KingSummaryCMAKE_BINARY_DIR is not quoted properly in core CMake modules => CMake does not support source/build trees with ';' in the path
2014-08-16 12:04Markus ElfringNote Added: 0036622
2014-08-18 09:39Brad KingNote Added: 0036630
2014-08-18 11:40Markus ElfringNote Added: 0036636
2016-06-10 14:29Kitware RobotNote Added: 0042604
2016-06-10 14:29Kitware RobotStatusnew => resolved
2016-06-10 14:29Kitware RobotResolutionopen => moved
2016-06-10 14:29Kitware RobotAssigned To => Kitware Robot
2016-06-10 14:31Kitware RobotStatusresolved => closed

Notes
(0036592)
Brad King   
2014-08-11 10:22   
We simply do not support running with directories containing ';'. Many projects construct ;-separated lists of full paths to source files. As documented here:

 http://www.cmake.org/cmake/help/v3.0/manual/cmake-language.7.html#lists [^]

the ;-lists are flattened so it is not safe to have a ';' in a list element value.

At most we should consider detecting when the path to the source or build tree contains ';' and report an error immediately.
(0036596)
Piotr Dziwinski   
2014-08-11 12:07   
All right, in that case I think an informative error message right at the beginning would be helpful.

And by the way, is semicolon the only not allowed character? I think the documentation should state clearly what characters are allowed and what are not.
(0036597)
Brad King   
2014-08-11 12:52   
Re 0015076:0036596: The ';' is the only character that is fundamentally disallowed by the CMake language, but lots of native tools have trouble with other characters or require special escaping that CMake does not always know. Also on Windows the filesystem does not even support many special characters, and CMake was designed to work with projects meant to work across many platforms. In general you should stick with '[A-Za-z0-9_ -]' (yes there is a space in there) because that is what is represented by our test machines.
(0036599)
Markus Elfring   
2014-08-11 16:35   
Is it eventually supported to "escape" semicolons within CMake strings?
(0036601)
Brad King   
2014-08-12 09:31   
Re 0015076:0036599: You can read about escaping in the cmake-language(7) manual I linked in 0015076:0036592. No further support for handling of ';' is likely to be added. CMake is not a general-purpose data-processing language.
(0036622)
Markus Elfring   
2014-08-16 12:04   
Does the wording "The sequence \; does not divide a value but is replaced by ; in the resulting element." in the current documentation mean that the string of a corresponding list element can get a semicolon?
(0036630)
Brad King   
2014-08-18 09:39   
Re 0015076:0036622: Yes, but list construction does not add the escapes so it flattens lists. In practice the only way to pass around lists whose elements have ';' is to use a different character (or sequence of characters) as a placeholder that is replaced with ';' when needed. See the LIST_SEPARATOR argument in the ExternalProject module for example.
(0036636)
Markus Elfring   
2014-08-18 11:40   
Thanks that you acknowledged the support for escaping of semicolons.

So I would expect that semicolons will be preserved if they were properly escaped in a CMake list element before. I hope that remaining source code places which did not consider the processing for this special character completely can be improved.
(0042604)
Kitware Robot   
2016-06-10 14:29   
Resolving issue as `moved`.

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.