Passing an argument to CMAKE via command prompt

In the CMakeLists.txt file, create a cache variable, as documented here:

SET(MY_VARIABLE "option_value" CACHE STRING "Some user-specified option")

Source: https://cmake.org/cmake/help/latest/command/set.html#set-cache-entry

Then, either use the GUI (ccmake or cmake-gui) to set the cache variable, or specify the value of the variable on the cmake command line with -D:

cmake -DMY_VARIABLE:STRING=option_value2

Modify your cache variable to a boolean if, in fact, your option is boolean.

Leave a Comment