[cmake-developers] [CMake 0015076]: CMAKE_BINARY_DIR is not quoted properly in core CMake modules

Mantis Bug Tracker mantis at public.kitware.com
Sun Aug 10 16:53:57 EDT 2014


The following issue has been SUBMITTED. 
====================================================================== 
http://www.cmake.org/Bug/view.php?id=15076 
====================================================================== 
Reported By:                Piotr Dziwinski
Assigned To:                
====================================================================== 
Project:                    CMake
Issue ID:                   15076
Category:                   (No Category)
Reproducibility:            always
Severity:                   minor
Priority:                   normal
Status:                     new
====================================================================== 
Date Submitted:             2014-08-10 16:53 EDT
Last Modified:              2014-08-10 16:53 EDT
====================================================================== 
Summary:                    CMAKE_BINARY_DIR is not quoted properly in core
CMake modules
Description: 
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.


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 ../
====================================================================== 

Issue History 
Date Modified    Username       Field                    Change               
====================================================================== 
2014-08-10 16:53 Piotr DziwinskiNew Issue                                    
2014-08-10 16:53 Piotr DziwinskiFile Added: binary_dir_quoting_fix.diff         
          
======================================================================



More information about the cmake-developers mailing list