Hello, I'm trying to pass multiple options from outside to a command in add_custom_target() or add_custom_command(). I am new to CMake and I don't know whether the observed behavior is bug or I do it in a wrong way.
I am doing all this with CMake 3.0 on Windows within MSYS environment if it plays some role. A test demonstrating the issue follows (using 'ls' as the command and '-l -h' as the options): # ==== CMakeLists.txt ==== cmake_minimum_required(VERSION 3.0) project(test_project) set(MYTOOL "ls") add_custom_target( x ALL COMMAND ${MYTOOL} ${MYTOOL_FLAGS} COMMENT "test" VERBATIM ) # ==== End of CMakeLists.txt ==== Using the CMakeLists.txt above, I get this: $ mkdir build && cd build $ cmake -G "MSYS Makefiles" -DMYTOOL_FLAGS="-l -h" .. ... (unimportant output censored) $ make VERBOSE=1 ... (unimportant output censored) [100%] test ls "-l -h" ls: invalid option -- Try `ls --help' for more information. make[2]: *** [CMakeFiles/x] Error 2 make[2]: Leaving directory `/prj/pok/build' make[1]: *** [CMakeFiles/x.dir/all] Error 2 make[1]: Leaving directory `/prj/pok/build' make: *** [all] Error 2 As can be seen, CMake propagates the contents of ${MYTOOL_FLAGS} as a single option into 'ls', i.e. generated Makefile attempts to execute ls "-l -h" instead of ls -l -h Any ideas how to do this correctly? Thanks, Martin -- 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