Reputation: 393
In my CMakeList.txt i can do the following thing:
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -new -flags -here")
Is it possible to to the same thing via command line? Like:
cmake.exe -DCMAKE_CXXFLAGS+= -new -flags
Upvotes: 26
Views: 47355
Reputation: 2825
First of all, keep your hands off CMAKE_CXX_FLAGS
! Use target_compile_options
:
target_compile_options(<YOUR_TARGET> PRIVATE ${MY_FLAGS})
To expand other lists use list
:
list(APPEND <YOUR_LIST> <ITEM_TO_ADD>)
Upvotes: 15
Reputation: 3132
If you don't like the command-line syntax specified by @Svalorzen, you could write a script that interprets its command-line arguments the way you like and converts them to something you can put on the cmake.exe command line. If portability is a concern, you could write the script in a language such as Perl (generally available on Unix-like platforms and can be installed on Windows).
If all this is going to buy you is an alternative solution to the problem you described, however, I would recommend just using the answer from @Svalorzen.
Upvotes: 0
Reputation: 5617
I'm not sure whether you can directly add options from the command line, but you can use an additional variable to store them and merge it at the end. Like the following:
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MY_FLAGS}")
And then call cmake as following:
cmake -DMY_FLAGS="-new -flags"
Upvotes: 22