From d348cd1bc50b74786d3e350a3b29aa92eeca1339 Mon Sep 17 00:00:00 2001 From: "Daniele E. Domenichelli" Date: Fri, 28 Feb 2014 17:36:38 +0100 Subject: [PATCH] FeatureSummary: Allow to combine and reorder values for the "WHAT" option For example it is now possible to do: feature_summary(WHAT ENABLED_FEATURES DISABLED_FEATURES) That produces an output like: -- -- The following features have been enabled: * Feature1 * Feature2 -- The following features have been disabled: * Feature2 Skipping the lists that are empty. Without this patch this would require to do: message(STATUS "") feature_summary(WHAT ENABLED_FEATURES DESCRIPTION "The following features have been enabled:") feature_summary(WHAT DISABLED_FEATURES DESCRIPTION "The following features have been disabled:") And empty lists would not be skipped. The behaviour when WHAT has a single argument (ALL or any option) is unchanged. --- Modules/FeatureSummary.cmake | 54 +++++++++++++++++++++++++----------- 1 file changed, 38 insertions(+), 16 deletions(-) diff --git a/Modules/FeatureSummary.cmake b/Modules/FeatureSummary.cmake index c0e63d531..66965158b 100644 --- a/Modules/FeatureSummary.cmake +++ b/Modules/FeatureSummary.cmake @@ -71,6 +71,13 @@ # RUNTIME_PACKAGES_FOUND: only those packages which have been found which have the type RUNTIME # RUNTIME_PACKAGES_NOT_FOUND: only those packages which have not been found which have the type RUNTIME # +# With the exception of the ``ALL`` value, these values can be combined +# in order to customize the output. For example: +# +# :: +# +# feature_summary(WHAT ENABLED_FEATURES DISABLED_FEATURES) +# # # # If a FILENAME is given, the information is printed into this file. If @@ -417,8 +424,8 @@ endfunction() function(FEATURE_SUMMARY) # CMAKE_PARSE_ARGUMENTS( args...) set(options APPEND INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES) - set(oneValueArgs FILENAME VAR DESCRIPTION WHAT) - set(multiValueArgs ) # none + set(oneValueArgs FILENAME VAR DESCRIPTION) + set(multiValueArgs WHAT) CMAKE_PARSE_ARGUMENTS(_FS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${_FIRST_ARG} ${ARGN}) @@ -451,20 +458,37 @@ function(FEATURE_SUMMARY) set(requiredPackagesNotFound TRUE) endif() - elseif("${_FS_WHAT}" STREQUAL "ALL") + else() + if("${_FS_WHAT}" STREQUAL "ALL") - set(allWhatParts "ENABLED_FEATURES" - "RUNTIME_PACKAGES_FOUND" - "OPTIONAL_PACKAGES_FOUND" - "RECOMMENDED_PACKAGES_FOUND" - "REQUIRED_PACKAGES_FOUND" + set(allWhatParts "ENABLED_FEATURES" + "RUNTIME_PACKAGES_FOUND" + "OPTIONAL_PACKAGES_FOUND" + "RECOMMENDED_PACKAGES_FOUND" + "REQUIRED_PACKAGES_FOUND" - "DISABLED_FEATURES" - "RUNTIME_PACKAGES_NOT_FOUND" - "OPTIONAL_PACKAGES_NOT_FOUND" - "RECOMMENDED_PACKAGES_NOT_FOUND" - "REQUIRED_PACKAGES_NOT_FOUND" - ) + "DISABLED_FEATURES" + "RUNTIME_PACKAGES_NOT_FOUND" + "OPTIONAL_PACKAGES_NOT_FOUND" + "RECOMMENDED_PACKAGES_NOT_FOUND" + "REQUIRED_PACKAGES_NOT_FOUND" + ) + + else() + set(allWhatParts) + foreach(part ${_FS_WHAT}) + list(FIND validWhatParts "${part}" indexInList) + if(NOT "${indexInList}" STREQUAL "-1") + list(APPEND allWhatParts "${part}") + else() + if("${part}" STREQUAL "ALL") + message(FATAL_ERROR "The WHAT argument of FEATURE_SUMMARY() contains ALL, which cannot be combined with other values.") + else() + message(FATAL_ERROR "The WHAT argument of FEATURE_SUMMARY() contains ${part}, which is not a valid value.") + endif() + endif() + endforeach() + endif() set(title_ENABLED_FEATURES "The following features have been enabled:") set(title_DISABLED_FEATURES "The following features have been disabled:") @@ -488,8 +512,6 @@ function(FEATURE_SUMMARY) endif() endif() endforeach() - else() - message(FATAL_ERROR "The WHAT argument of FEATURE_SUMMARY() is set to ${_FS_WHAT}, which is not a valid value.") endif() if(_FS_FILENAME)