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 .
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.
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...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With