theadnangondal
theadnangondal

Reputation: 1664

Create a new cmake input variable

is it possible to create a new cmake variable ? when I run cmake through gui

ccmake .

a set of variables appear on the screen . I want an extra variable which could have three string values and depending on those strings I can modify my build options

Upvotes: 4

Views: 2061

Answers (1)

The input variables shown in all CMake UIs are cache variables. You can create your own using set( ... CACHE) calls.

To create a "select one of three values" type of variable, you could do this:

set(MY_SELECTION "Option A" CACHE STRING "Help message for this variable")
set_property(
  CACHE MY_SELECTION
  PROPERTY STRINGS
  "Option A" "Option B" "Option C"
)

This will create a variable named MY_SELECTION visible in CMake UI, whose values can be chosen from between Option A, Option B, and Option C. Its initial value will be Option A and its help string will be Help message for this variable.

Note that set(... CACHE ...) calls only affect the variable's value if that variable does not yet exist. If the user already entered their own value, it will not be overridden (which is typically what you want in such case).

Upvotes: 7

Related Questions