The following issue has been SUBMITTED. ====================================================================== https://public.kitware.com/Bug/view.php?id=15792 ====================================================================== Reported By: Pavel Solodovnikov Assigned To: ====================================================================== Project: CMake Issue ID: 15792 Category: CMake Reproducibility: always Severity: major Priority: normal Status: new ====================================================================== Date Submitted: 2015-10-15 04:49 EDT Last Modified: 2015-10-15 04:49 EDT ====================================================================== Summary: Bad escaping of parentheses in POST_BUILD events if Ninja generator used Description: CMake 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 Reproduce: 1) Extract attached example.tar 2) Run "cmake -G "Ninja" ." inside extracted dir. 3) Examine produced build.ninja file. ====================================================================== Issue History Date Modified Username Field Change ====================================================================== 2015-10-15 04:49 Pavel SolodovnikovNew Issue 2015-10-15 04:49 Pavel SolodovnikovFile Added: cmake_parens_test.tar ====================================================================== -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: http://public.kitware.com/mailman/listinfo/cmake-developers