If you want to check the valid values, you need to do it yourself in your file CMakeLists.txt. However, you can provide a list of values for CMake to represent as a combined field for STRING cache variables in the CMake GUI application (as well as the ncurses equivalent in ccmake). You do this by setting the STRINGS property of the cache variable. For instance:
set(trafficLightColors Red Orange Green)
set(trafficLight Green CACHE STRING "Status of something")
set_property(CACHE trafficLight PROPERTY STRINGS ${trafficLightColors})
In this example, the CMake GUI will display the cache variable trafficLightjust like any other string variable, but if the user clicks on it to change it, instead of a common text field you will get a combo field containing items Red, Orangeand Green.
100% , . cmake , , . STRINGS, , . , , . :
list(FIND trafficLightColors ${trafficLight} index)
if(index EQUAL -1)
message(FATAL_ERROR "trafficLight must be one of ${trafficLightColors}")
endif()
, CMake 3.5 :
if(NOT trafficLight IN_LIST trafficLightColors)
message(FATAL_ERROR "trafficLight must be one of ${trafficLightColors}")
endif()