Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cmake : how to append string to the variable via command line?

Tags:

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 
like image 976
kubivan Avatar asked May 22 '14 11:05

kubivan


People also ask

How do I add a variable in CMake?

Options and variables are defined on the CMake command line like this: $ cmake -DVARIABLE=value path/to/source You can set a variable after the initial `CMake` invocation to change its value. You can also undefine a variable: $ cmake -UVARIABLE path/to/source Variables are stored in the `CMake` cache.

What is ${} in CMake?

You access a variable by using ${} , such as ${MY_VARIABLE} . 1. CMake has the concept of scope; you can access the value of the variable after you set it as long as you are in the same scope. If you leave a function or a file in a sub directory, the variable will no longer be defined.

WHAT IS SET command in CMake?

Set a normal, cache, or environment variable to a given value. See the cmake-language(7) variables documentation for the scopes and interaction of normal variables and cache entries. Signatures of this command that specify a <value>... placeholder expect zero or more arguments.


1 Answers

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" 
like image 164
Svalorzen Avatar answered Sep 20 '22 06:09

Svalorzen