option() is a handy shortcut for boolean options, but it's little more than
syntactic sugar for a cache variable of type BOOL. To create a tristate
variable, you can do this:
set(ENABLE_SOMETHING AUTO CACHE STRING "Enable SOMETHING support") #
create the variable
set_property(CACHE ENABLE_SOMETHING PROPERTY STRINGS AUTO ON OFF) #
define list of values GUI will offer for the variable
Then, you can test the variable like this:
if(ENABLE_SOMETHING STREQUAL "AUTO")
# AUTO was used
# a true value (such as ON) was used
# a false value (such as OFF) was used
Hope this helps.
On 13 October 2016 at 13:32, YuGiOhJCJ Mailing-List via CMake <
> Regarding the cmake-commands manual , the "option" command seems to
> take as argument a boolean constant that can have the two possible values:
> ON or OFF.
> I would like to use three possible values for an option: AUTO (as default
> value), ON or OFF.
> option(ENABLE_SOMETHING "Enable SOMETHING support" AUTO)
> But of course this example is wrong because "AUTO" is not ON or OFF.
> Regarding the cmake-commands manual , the "if" command seems to return
> TRUE when the boolean constant is 1, ON, YES, TRUE, Y, or a non-zero number.
> It returns FALSE when the boolean constant is 0, OFF, NO, FALSE, N,
> IGNORE, NOTFOUND, the empty string, or ends in the suffix -NOTFOUND.
> I would like to check the value myself.
> message(STATUS "ENABLE_SOMETHING=AUTO")
> message(STATUS "ENABLE_SOMETHING=ON")
> message(STATUS "ENABLE_SOMETHING=OFF")
> But of course this example is wrong because "=" is not accepted for an
> expression in a "if" command.
> So my question is: How to handle options with more than two possible
> Thank you.
> Best regards.
>  https://cmake.org/cmake/help/v3.7/command/option.html
>  https://cmake.org/cmake/help/v3.7/command/if.html
> Powered by www.kitware.com
> Please keep messages on-topic and check the CMake FAQ at:
> Kitware offers various services to support the CMake community. For more
> information on each offering, please visit:
> CMake Support: http://cmake.org/cmake/help/support.html
> CMake Consulting: http://cmake.org/cmake/help/consulting.html
> CMake Training Courses: http://cmake.org/cmake/help/training.html
> Visit other Kitware open-source projects at http://www.kitware.com/
> Follow this link to subscribe/unsubscribe:
Powered by www.kitware.com
Please keep messages on-topic and check the CMake FAQ at:
Kitware offers various services to support the CMake community. For more
information on each offering, please visit:
CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html
Visit other Kitware open-source projects at
Follow this link to subscribe/unsubscribe: