Spacing in the -D option in cmake
CMake command line parsing is not very consistent or reliable unfortunately.
This problem is probably related to the order in which you pass the arguments.
Internally, CMake iterates through the command line arguments twice. The first time it looks for non-cache arguments and skips the beginning with -D
. Anything that doesn't fit into the list of valid arguments is assumed to be a path to the CMakeLists.txt file (or directory or CMakeCache.txt).
Assuming there will only be one path to go, and does nothing to validate this assumption. This is the problem. If you passed -D Foo=1
, it is -D
treated as a complete argument and is skipped, but Foo=1
treated as a path.
On the second iteration through args, it now grabs the values specified through -D
, but on this run, it correctly handles spaces after -D
. Therefore, he understands what he is -D Foo=1
setting Foo
in 1
.
So, the position of the path on your command line is important here.
cmake -D Foo=1 MyProject/CMakeLists.txt # --> Works
cmake MyProject/CMakeLists.txt -D Foo=1 # --> Fails
To complicate matters, you can wrap the quoted space and parse it with CMake, but the variable name then includes a space and is not applicable in the CMakeLists file.
cmake MyProject/CMakeLists.txt "-D Foo=1" # --> Defines the unusable var ${ Foo}
Another inconsistency is that other command line flags work with or without space (for example -G
), while others require space (for example -E
).
My own advice is to always avoid adding space after the flag unless required. My guess is that always going the last way will help too, although it's not necessary unless you add extra spaces.
source to share
http://cmake.org/cmake/help/v2.8.8/cmake.html#command:add_definitions
The examples provided show that add_definitions should be used without placing spaces within a single definition. Did you install the compiler using add_definitions or during the cmake call?
source to share