MantisBT - CMake
View Issue Details
0015744CMakeCMakepublic2015-09-15 13:212016-05-02 08:30
Thiago M. 
Clinton Stimpson 
normalmajoralways
closedno change required 
Red Hat Enterprise Linux6
CMake 3.3.1 
 
0015744: Spaces in paths with non-ASCII characters are not escaped when using Ninja
When using CMake with the Ninja generator to build some source code that is inside a path that contains both spaces and non-ASCII characters, the path is used without escaping the spaces inside the generated Ninja rules files.
1) Create a sources folder in a path which contains both spaces and non-ASCII characters. Ex:
   `make /tmp/CMake Ninja Spaces/Código`
2) Inside the source folder, create a `CMakeLists.txt` with an `add_executable(main main.cpp)`.
3) Run CMake using the Ninja generator.
4) Check the generated `build.ninja` file.
   It should have spaces in paths escaped with `$`, like:
       build CMakeFiles/CMakeNinjaSpaces.dir/main.cpp.o: CXX_COMPILER__CMakeNinjaSpaces /tmp/CMake$ Ninja$ Spaces/Código/main.cpp
   However, it has variables names `identX` with unescaped paths:
       ident0 = /tmp/CMake Ninja Spaces/Código/main.cpp
       build CMakeFiles/CMakeNinjaSpaces.dir/main.cpp.o: CXX_COMPILER__CMakeNinjaSpaces $ident0
The unescaped paths make Ninja rebuild and relink everything whenever it runs, making incremental builds and the edit-build-test cicle impossible.

Steps to reproduce (cont.):
5) Run Ninja on the generated `build.ninja` file.
   It outputs the progress of files being build:
       [1/2] Building CXX object CMakeFiles/CMakeNinjaSpaces.dir/main.cpp.o
       [2/2] Linking CXX executable CMakeNinjaSpaces
6) Run Ninja again.
   It should do nothing and print:
       `ninja: no work to do.`
   However, it does rebuild and relink everything, showing again the progress messages described in step 5.
ninja, Unicode
? build.ninja (7,117) 2015-09-15 13:21
https://public.kitware.com/Bug/file/5528/*
Issue History
2015-09-15 13:21Thiago M.New Issue
2015-09-15 13:21Thiago M.File Added: build.ninja
2015-09-15 13:31Thiago M.Tag Attached: ninja
2015-09-15 13:31Thiago M.Tag Attached: Unicode
2016-01-01 23:26Clinton StimpsonNote Added: 0040037
2016-01-04 07:15Thiago M.Note Added: 0040049
2016-01-05 23:31Clinton StimpsonStatusnew => resolved
2016-01-05 23:31Clinton StimpsonResolutionopen => no change required
2016-01-05 23:31Clinton StimpsonAssigned To => Clinton Stimpson
2016-05-02 08:30Robert MaynardNote Added: 0040991
2016-05-02 08:30Robert MaynardStatusresolved => closed

Notes
(0040037)
Clinton Stimpson   
2016-01-01 23:26   
I'm seeing this output from Ninja.

$ ninja-build -d explain
ninja explain: /tmp/CMake Ninja Spaces/C is dirty
ninja explain: digo/main.cpp is dirty
ninja explain: CMakeFiles/main.dir/main.cpp.o is dirty
ninja explain: main is dirty
[2/2] Linking CXX executable main

Perhaps this is a Ninja bug. For example, here is a currently open bug where non-ascii characters are treated as whitespace, which fits my observation above.
https://github.com/ninja-build/ninja/issues/811 [^]
(0040049)
Thiago M.   
2016-01-04 07:15   
Clinton, it seems you're right: I've tested the same build.ninja file generated by CMake with Ninja master (commit c2e810ca4314f112cb65fabd35583b10136faea2 on their Git) and it indeed worked correctly.
(0040991)
Robert Maynard   
2016-05-02 08:30   
Closing resolved issues that have not been updated in more than 4 months.