[CMake] How to handle options with more than two possible values?

YuGiOhJCJ Mailing-List yugiohjcj-mailinglist at laposte.net
Thu Oct 13 07:32:45 EDT 2016


Hello,

Regarding the cmake-commands manual [1], 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.

Example:
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 [2], 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.

Example:
if(ENABLE_SOMETHING=AUTO)
	message(STATUS "ENABLE_SOMETHING=AUTO")
endif()
if(ENABLE_SOMETHING=ON)
	message(STATUS "ENABLE_SOMETHING=ON")
endif()
if(ENABLE_SOMETHING=OFF)
	message(STATUS "ENABLE_SOMETHING=OFF")
endif()

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 values?

Thank you.
Best regards.

[1] https://cmake.org/cmake/help/v3.7/command/option.html
[2] https://cmake.org/cmake/help/v3.7/command/if.html


More information about the CMake mailing list