mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-17 15:32:10 +08:00
FeatureSummary: Add QUIET_ON_EMPTY option to feature_summary
This option suppresses the output when the list of packages that belong to the selected category is empty.
This commit is contained in:
@@ -119,6 +119,7 @@ endfunction()
|
|||||||
[INCLUDE_QUIET_PACKAGES]
|
[INCLUDE_QUIET_PACKAGES]
|
||||||
[FATAL_ON_MISSING_REQUIRED_PACKAGES]
|
[FATAL_ON_MISSING_REQUIRED_PACKAGES]
|
||||||
[DESCRIPTION "Found packages:"]
|
[DESCRIPTION "Found packages:"]
|
||||||
|
[QUIET_ON_EMPTY]
|
||||||
WHAT (ALL | PACKAGES_FOUND | PACKAGES_NOT_FOUND
|
WHAT (ALL | PACKAGES_FOUND | PACKAGES_NOT_FOUND
|
||||||
| ENABLED_FEATURES | DISABLED_FEATURES)
|
| ENABLED_FEATURES | DISABLED_FEATURES)
|
||||||
)
|
)
|
||||||
@@ -179,6 +180,11 @@ endfunction()
|
|||||||
``FATAL_ON_MISSING_REQUIRED_PACKAGES`` is given, CMake will abort if a
|
``FATAL_ON_MISSING_REQUIRED_PACKAGES`` is given, CMake will abort if a
|
||||||
package which is marked as ``REQUIRED`` has not been found.
|
package which is marked as ``REQUIRED`` has not been found.
|
||||||
|
|
||||||
|
If the ``QUIET_ON_EMPTY`` option is used, if only one type of package was
|
||||||
|
requested, and no packages belonging to that category were found, then no
|
||||||
|
output (including the ``DESCRIPTION``) is printed or added to the ``VAR``
|
||||||
|
variable.
|
||||||
|
|
||||||
Example 1, append everything to a file:
|
Example 1, append everything to a file:
|
||||||
|
|
||||||
.. code-block:: cmake
|
.. code-block:: cmake
|
||||||
@@ -202,7 +208,7 @@ endfunction()
|
|||||||
|
|
||||||
function(FEATURE_SUMMARY)
|
function(FEATURE_SUMMARY)
|
||||||
# CMAKE_PARSE_ARGUMENTS(<prefix> <options> <one_value_keywords> <multi_value_keywords> args...)
|
# CMAKE_PARSE_ARGUMENTS(<prefix> <options> <one_value_keywords> <multi_value_keywords> args...)
|
||||||
set(options APPEND INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES)
|
set(options APPEND INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES QUIET_ON_EMPTY)
|
||||||
set(oneValueArgs FILENAME VAR DESCRIPTION)
|
set(oneValueArgs FILENAME VAR DESCRIPTION)
|
||||||
set(multiValueArgs WHAT)
|
set(multiValueArgs WHAT)
|
||||||
|
|
||||||
@@ -232,7 +238,9 @@ function(FEATURE_SUMMARY)
|
|||||||
list(FIND validWhatParts "${_FS_WHAT}" indexInList)
|
list(FIND validWhatParts "${_FS_WHAT}" indexInList)
|
||||||
if(NOT "${indexInList}" STREQUAL "-1")
|
if(NOT "${indexInList}" STREQUAL "-1")
|
||||||
_FS_GET_FEATURE_SUMMARY( ${_FS_WHAT} _featureSummary ${_FS_INCLUDE_QUIET_PACKAGES} )
|
_FS_GET_FEATURE_SUMMARY( ${_FS_WHAT} _featureSummary ${_FS_INCLUDE_QUIET_PACKAGES} )
|
||||||
set(_fullText "${_FS_DESCRIPTION}${_featureSummary}\n")
|
if(_featureSummary OR NOT _FS_QUIET_ON_EMPTY)
|
||||||
|
set(_fullText "${_FS_DESCRIPTION}${_featureSummary}\n")
|
||||||
|
endif()
|
||||||
if (("${_FS_WHAT}" STREQUAL "REQUIRED_PACKAGES_NOT_FOUND") AND _featureSummary)
|
if (("${_FS_WHAT}" STREQUAL "REQUIRED_PACKAGES_NOT_FOUND") AND _featureSummary)
|
||||||
set(requiredPackagesNotFound TRUE)
|
set(requiredPackagesNotFound TRUE)
|
||||||
endif()
|
endif()
|
||||||
@@ -298,23 +306,25 @@ function(FEATURE_SUMMARY)
|
|||||||
endforeach()
|
endforeach()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(_FS_FILENAME)
|
if(_fullText OR NOT _FS_QUIET_ON_EMPTY)
|
||||||
if(_FS_APPEND)
|
if(_FS_FILENAME)
|
||||||
file(APPEND "${_FS_FILENAME}" "${_fullText}")
|
if(_FS_APPEND)
|
||||||
|
file(APPEND "${_FS_FILENAME}" "${_fullText}")
|
||||||
|
else()
|
||||||
|
file(WRITE "${_FS_FILENAME}" "${_fullText}")
|
||||||
|
endif()
|
||||||
|
|
||||||
else()
|
else()
|
||||||
file(WRITE "${_FS_FILENAME}" "${_fullText}")
|
if(NOT _FS_VAR)
|
||||||
|
message(STATUS "${_fullText}")
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
else()
|
if(_FS_VAR)
|
||||||
if(NOT _FS_VAR)
|
set(${_FS_VAR} "${_fullText}" PARENT_SCOPE)
|
||||||
message(STATUS "${_fullText}")
|
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(_FS_VAR)
|
|
||||||
set(${_FS_VAR} "${_fullText}" PARENT_SCOPE)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(requiredPackagesNotFound AND _FS_FATAL_ON_MISSING_REQUIRED_PACKAGES)
|
if(requiredPackagesNotFound AND _FS_FATAL_ON_MISSING_REQUIRED_PACKAGES)
|
||||||
message(FATAL_ERROR "feature_summary() Error: REQUIRED package(s) are missing, aborting CMake run.")
|
message(FATAL_ERROR "feature_summary() Error: REQUIRED package(s) are missing, aborting CMake run.")
|
||||||
endif()
|
endif()
|
||||||
|
@@ -0,0 +1,5 @@
|
|||||||
|
-- Enabled features:
|
||||||
|
\* Foo, Foo\.
|
||||||
|
\* Bar, Bar\.
|
||||||
|
|
||||||
|
-- Configuring done
|
@@ -0,0 +1,14 @@
|
|||||||
|
include(FeatureSummary)
|
||||||
|
|
||||||
|
set(WITH_FOO 1)
|
||||||
|
set(WITH_BAR 1)
|
||||||
|
|
||||||
|
add_feature_info(Foo WITH_FOO "Foo.")
|
||||||
|
add_feature_info(Bar WITH_BAR "Bar.")
|
||||||
|
|
||||||
|
feature_summary(WHAT ENABLED_FEATURES
|
||||||
|
DESCRIPTION "Enabled features:"
|
||||||
|
QUIET_ON_EMPTY)
|
||||||
|
feature_summary(WHAT DISABLED_FEATURES
|
||||||
|
DESCRIPTION "Disabled features:"
|
||||||
|
QUIET_ON_EMPTY)
|
@@ -12,3 +12,4 @@ run_cmake(FeatureSummaryURLDescription)
|
|||||||
run_cmake(FeatureSummaryTypes)
|
run_cmake(FeatureSummaryTypes)
|
||||||
run_cmake(FeatureSummaryFatalOnMissingRequiredPackages)
|
run_cmake(FeatureSummaryFatalOnMissingRequiredPackages)
|
||||||
run_cmake(FeatureSummaryIncludeQuietPackages)
|
run_cmake(FeatureSummaryIncludeQuietPackages)
|
||||||
|
run_cmake(FeatureSummaryQuietOnEmpty)
|
||||||
|
Reference in New Issue
Block a user