[CMake] Clarification for quoting of parameters for "add_executable()"

SF Markus Elfring elfring at users.sourceforge.net
Tue Jan 11 13:56:12 EST 2011


Hello,

My experience with CMake programming is evolving. I try to update some scripts 
which were published with the feature request "Add simple CMake build files".
https://sourceforge.net/apps/trac/cppcheck/ticket/1092#comment:5

A concern that I try to tackle as a next step for this software project is the 
famous issue "parameter quoting" as it is described by an article.
http://cmake.org/Wiki/CMake/Language_Syntax#CMake_splits_arguments_unless_you_use_quotation_marks_or_escapes.

I came along to the build instructions for a program which contained the usual 
function call "add_executable". I added quotation marks for the second parameter 
because I thought that it was appropriate with the advices from the known Wiki 
article in mind. I was suprised by unexpected consequences a moment later. I 
described the corresponding side effects in the bug report/feature request 
'Clarification of message "CMake Error in cli/CMakeLists.txt"'.
http://public.kitware.com/Bug/view.php?id=11677

I assume that David Cole categorises my story as a basic programming error.
But I am not yet convinced about this.

There are still a few details that bother me here if you consider the following 
small script template for example.
cmake_minimum_required(VERSION 2.6)
project(MY_P)
set(MY_SOURCES "A.cxx" ... "Z.cxx")
message(STATUS "file list: ${MY_SOURCES}")
add_executable(MY_P-test "${MY_SOURCES}")

I would expect that a quoted CMake list will be passed from the specified 
variable to this command. How do you think about this when you stumble on a 
message like the following when you know that the "missing" source files are 
available in your directory structure?
...
Configuring done
CMake Error at CMakeLists.txt:5 (add_executable):
   Cannot find source file "Y.cxx". Tried extensions ...
...

I hope that the involved technical details can be better resolved in a wider 
audience.

Regards,
Markus


More information about the CMake mailing list