Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMake multiple-option setting

I'm working on a project which is built with CMake, so I'm writing up a CMakeLists.txt for it. In this file I want to have a (cached) CMake variable that can only take one of several options (which I would specify somehow), rather than any arbitrary string. For simplicity, let's take it to be a string which can take "red", "green" or "blue" - but nothing else.

Can I achieve this with a recent CMake version, other than setting an arbitrary string then checking it for validity?

like image 337
einpoklum Avatar asked Dec 02 '17 18:12

einpoklum


1 Answers

The answer is to be found in one of Kitware's Blog Posts named "Constraining Values with ComboBoxes in CMake (cmake-gui)":

So here’s how it works: for each cache entry that you want to constrain to some set of values, define it as usual with a default value as a STRING cache variable, for example:

set(BaseName "binary" CACHE STRING "BaseName chosen by the user at CMake configure time")

Now, after defining the cache entry with its initial default value, define the set of strings to which its value should be constrained:

set_property(CACHE BaseName PROPERTY STRINGS binary octal decimal hexadecimal)

After the set_property call, cmake-gui knows to present a drop-down combo box for editing the “BaseName” cache entry, and it knows that the four valid choices for this entry that it should present are binary, octal, decimal and hexadecimal.

like image 130
Florian Avatar answered Oct 16 '22 17:10

Florian