Merge pull request #7380 from oltolm/yesno

make "yes;no" cmake options boolean instead of string
pull/7542/head
David Garske 2024-05-15 15:18:42 -07:00 committed by GitHub
commit 1d1800a3bd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 10 additions and 5 deletions

View File

@ -1,7 +1,7 @@
function(override_cache VAR VAL)
get_property(VAR_STRINGS CACHE ${VAR} PROPERTY STRINGS)
LIST(FIND VAR_STRINGS ${VAL} CK)
if(-1 EQUAL ${CK})
if(-1 EQUAL ${CK} AND DEFINED VAR_STRINGS)
message(SEND_ERROR
"\"${VAL}\" is not valid override value for \"${VAR}\"."
" Please select value from \"${VAR_STRINGS}\"\n")
@ -10,10 +10,15 @@ function(override_cache VAR VAL)
endfunction()
function(add_option NAME HELP_STRING DEFAULT VALUES)
# Set the default value for the option.
set(${NAME} ${DEFAULT} CACHE STRING ${HELP_STRING})
# Set the list of allowed values for the option.
set_property(CACHE ${NAME} PROPERTY STRINGS ${VALUES})
if(VALUES STREQUAL "yes;no")
# Set the default value for the option.
set(${NAME} ${DEFAULT} CACHE BOOL ${HELP_STRING})
else()
# Set the default value for the option.
set(${NAME} ${DEFAULT} CACHE STRING ${HELP_STRING})
# Set the list of allowed values for the option.
set_property(CACHE ${NAME} PROPERTY STRINGS ${VALUES})
endif()
if(DEFINED ${NAME})
list(FIND VALUES ${${NAME}} IDX)