Skip to content

Commit

Permalink
Merge pull request #7380 from oltolm/yesno
Browse files Browse the repository at this point in the history
make "yes;no" cmake options boolean instead of string
  • Loading branch information
dgarske authored May 15, 2024
2 parents 287323a + 78b8ea3 commit 1d1800a
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions cmake/functions.cmake
Original file line number Diff line number Diff line change
@@ -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")
Expand All @@ -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)
Expand Down

0 comments on commit 1d1800a

Please sign in to comment.