View Issue Details Jump to Notes ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0015076CMake(No Category)public2014-08-10 16:532016-06-10 14:31
ReporterPiotr Dziwinski 
Assigned ToKitware Robot 
PrioritynormalSeverityminorReproducibilityalways
StatusclosedResolutionmoved 
PlatformLinuxOSArch LinuxOS Version
Product VersionCMake 3.0 
Target VersionFixed in Version 
Summary0015076: CMake does not support source/build trees with ';' in the path
DescriptionWhile 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.
Steps To Reproduce$ 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 ../
TagsNo tags attached.
Attached Filesdiff file icon binary_dir_quoting_fix.diff [^] (21,634 bytes) 2014-08-10 16:53 [Show Content]

 Relationships

  Notes
(0036592)
Brad King (manager)
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 (reporter)
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 (manager)
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 (reporter)
2014-08-11 16:35

Is it eventually supported to "escape" semicolons within CMake strings?
(0036601)
Brad King (manager)
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 (reporter)
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 (manager)
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 (reporter)
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 (administrator)
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.

 Issue History
Date Modified Username Field Change
2014-08-10 16:53 Piotr Dziwinski New Issue
2014-08-10 16:53 Piotr Dziwinski File Added: binary_dir_quoting_fix.diff
2014-08-11 10:22 Brad King Note Added: 0036592
2014-08-11 12:07 Piotr Dziwinski Note Added: 0036596
2014-08-11 12:52 Brad King Note Added: 0036597
2014-08-11 16:35 Markus Elfring Note Added: 0036599
2014-08-12 09:31 Brad King Note Added: 0036601
2014-08-12 09:32 Brad King Summary CMAKE_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:04 Markus Elfring Note Added: 0036622
2014-08-18 09:39 Brad King Note Added: 0036630
2014-08-18 11:40 Markus Elfring Note Added: 0036636
2016-06-10 14:29 Kitware Robot Note Added: 0042604
2016-06-10 14:29 Kitware Robot Status new => resolved
2016-06-10 14:29 Kitware Robot Resolution open => moved
2016-06-10 14:29 Kitware Robot Assigned To => Kitware Robot
2016-06-10 14:31 Kitware Robot Status resolved => closed


Copyright © 2000 - 2018 MantisBT Team