View Issue Details Jump to Notes ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0015792CMakeCMakepublic2015-10-15 04:492016-03-07 09:12
ReporterPavel Solodovnikov 
Assigned To 
PrioritynormalSeveritymajorReproducibilityalways
StatusclosedResolutionwon't fix 
PlatformLinuxOSOS Version
Product VersionCMake 3.4 
Target VersionFixed in Version 
Summary0015792: Bad escaping of parentheses in POST_BUILD events if Ninja generator used
DescriptionCMake generates wrong post-build events if it contains parentheses: they are not escaped at all (e.g., copy some build artefacts to a directory that contains parens).

I've attached a small example to reproduce the issue.

================= BEGIN EXAMPLE
    cmake_minimum_required(VERSION 2.8.11)

    project(example)
    add_library(ex abc.cpp)
    add_custom_command(TARGET ex POST_BUILD VERBATIM COMMAND cp -f "libex.a" "mydir (abc)")
================= END EXAMPLE

After running cmake, we can easily observe that parentheses are not escaped properly in post build event:

57 build libex.a: CXX_STATIC_LIBRARY_LINKER__ex CMakeFiles/ex.dir/abc.cpp.o
   OBJECT_DIR = CMakeFiles/ex.dir
   POST_BUILD = cd /mnt/sources/work/cmake_parens_test && cp -f libex.a mydir\ (abc)
   PRE_LINK = :
   TARGET_COMPILE_PDB = CMakeFiles/ex.dir/
   TARGET_FILE = libex.a
   TARGET_PDB = libex.pdb

It leads to build errors since it's not valid shell syntax:

FAILED: : && /home/prog/Downloads/cmake-3.4.0-rc1-Linux-i386/bin/cmake -E remove libex.a && /bin/ar qc libex.a CMakeFiles/ex.dir/abc.cpp.o && /bin/ranlib libex.a && cd /mnt/sources/work/cmake_parens_test && cp -f libex.a mydir\ (abc)
/bin/sh: -c: line 0: syntax error near unexpected token `('
/bin/sh: -c: line 0: `: && /home/prog/Downloads/cmake-3.4.0-rc1-Linux-i386/bin/cmake -E remove libex.a && /bin/ar qc libex.a CMakeFiles/ex.dir/abc.cpp.o && /bin/ranlib libex.a && cd /mnt/sources/work/cmake_parens_test && cp -f libex.a mydir\ (abc)'
ninja: build stopped: subcommand failed.

It is possible to workaround this by using VERBATIM option in POST_BUILD event, though.

Tested with the latest CMake v.3.4.0 rc1 (I just couldn't select it in "Product Version" dropdown list, so I left CMake 3.3.2 there).
Steps To Reproduce1) Extract attached example.tar
2) Run "cmake -G "Ninja" ." inside extracted dir.
3) Examine produced build.ninja file.
TagsCMake, linux, ninja
Attached Filestar file icon cmake_parens_test.tar [^] (10,240 bytes) 2015-10-15 04:49

 Relationships

  Notes
(0039607)
Pavel Solodovnikov (reporter)
2015-10-15 04:52

I've made a misprint in posted example, it should be
    add_custom_command(TARGET ex POST_BUILD COMMAND cp -f "libex.a" "mydir (abc)")
without VERBATIM option, to reproduce error.
(0039608)
Brad King (manager)
2015-10-15 08:36

The VERBATIM option was added specifically to support more advanced escaping while retaining compatibility with the older implementation. When not using VERBATIM it is your responsibility to add shell escapes.

https://cmake.org/cmake/help/v3.4/command/add_custom_command.html [^]
"Use of VERBATIM is recommended as it enables correct behavior. When VERBATIM is not given the behavior is platform specific because there is no protection of tool-specific special characters."
(0040618)
Robert Maynard (manager)
2016-03-07 09:12

Closing resolved issues that have not been updated in more than 4 months.

 Issue History
Date Modified Username Field Change
2015-10-15 04:49 Pavel Solodovnikov New Issue
2015-10-15 04:49 Pavel Solodovnikov File Added: cmake_parens_test.tar
2015-10-15 04:50 Pavel Solodovnikov Tag Attached: CMake
2015-10-15 04:50 Pavel Solodovnikov Tag Attached: linux
2015-10-15 04:50 Pavel Solodovnikov Tag Attached: ninja
2015-10-15 04:52 Pavel Solodovnikov Note Added: 0039607
2015-10-15 08:33 Brad King Product Version CMake 3.3.2 => CMake 3.4
2015-10-15 08:36 Brad King Note Added: 0039608
2015-10-15 08:36 Brad King Status new => resolved
2015-10-15 08:36 Brad King Resolution open => won't fix
2016-03-07 09:12 Robert Maynard Note Added: 0040618
2016-03-07 09:12 Robert Maynard Status resolved => closed


Copyright © 2000 - 2018 MantisBT Team