Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding command line options to CMake

People also ask

How do I add options to CMake?

cmake -G %1 -DBUILD_SHARED_LIBS=ON -DBUILD_STATIC_LIBS=ON -DBUILD_TESTS=ON .. You have to enter all your command-line definitions before including the path. @Ébe-isaac If you want to explicitly turn an option OFF just use -DOPTION=OFF .

How do you pass command line arguments in CMake?

If you create the cache variable in the CMakeLists. txt file and then pass the argument via calling cmake, won't the CMakeList. txt file keep overwriting the argument value? No, the cache is populated on the first run with either the default value, or the value supplied on the command line if it is provided.

How do I check my CMake options?

Advanced users may further be interested in the settings of the following options which in most cases are automatically derived from the non-advanced CMake options summarized above. To view these options in the CMake GUI, press the t key in ccmake (Unix) or check the Show Advanced Values box (Windows).


Yeah, you should use the option command. You can set options from the command line this way:

//CMakeLists.txt
option(MyOption "MyOption" OFF)

//Command line
cmake -DMyOption=ON MyProjectFolder

Note that -DMyOption must come before the path.


Just a little correction:

If you have other variables to pass, it is recommended to indicate the type of these:

//CMakeLists.txt
option(MyOption "MyOption" OFF)

//Command line
cmake -DMyOption:BOOL=ON MyProjectFolder -D...