Skip to content

Commit

Permalink
Display auto_option hint in all cases (#10762)
Browse files Browse the repository at this point in the history
This takes the HINT added by @dragon512 a step further. The cases
are as follows:
    - feature enabled, option enabled: hints how to disable
    - feature enabled, option disabled: no hint, something broke
    - feature disabled, option enabled (AUTO): hints how to require
    - feature disabled, option disabled: hints how to enable

I made a distinction between enabling and requiring. If the option is
set to AUTO, it is already enabled, in some sense. If the user sets an
option to ON, the user is requiring that the corresponding feature must
be turned on, and should expect an error if a dependency is missing.
  • Loading branch information
JosiahWI authored Nov 15, 2023
1 parent 351605d commit 1966971
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion cmake/AutoOptionHelpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ endmacro()
# Prints a colorized summary of one auto option.
function(PRINT_AUTO_OPTION _NAME)
string(ASCII 27 ESC)
set(HINT "")
set(COLOR_RED "${ESC}[31m")
set(COLOR_GREEN "${ESC}[32m")
set(COLOR_RESET "${ESC}[m")
Expand All @@ -158,15 +157,24 @@ function(PRINT_AUTO_OPTION _NAME)

set(RESET ${COLOR_RESET})
if(FEATURE_VALUE)
# This accounts for both the ON and AUTO cases.
if(OPTION_VALUE)
set(COLOR ${COLOR_GREEN})
set(HINT "(hint: add -D${_NAME}=OFF to disable)")
else()
message(WARNING "${FEATURE} truthy but ${_NAME} isn't!")
set(COLOR ${COLOR_RED})
# There is no sensible hint for this case - things are
# on fire.
set(HINT "")
endif()
else()
# This should account only for the AUTO case.
# If the option is set to ON but dependencies were
# missing, then we should have errored out already.
if(OPTION_VALUE)
set(COLOR ${COLOR_RED})
set(HINT "(hint: add -D${_NAME}=ON to require)")
else()
set(RESET "")
set(HINT "(hint: add -D${_NAME}=ON to enable)")
Expand Down

0 comments on commit 1966971

Please sign in to comment.