[cmake-developers] [PATCH] Do not output transitive dependencies in feature_summary()
Alex Merry
kde at randomguy3.me.uk
Mon Feb 3 12:00:26 EST 2014
Currently, feature_summary() prints out all the transitive dependencies
of a package (those found with find_dependency() in a Config.cmake file)
in addition to the explicit dependencies looked for in a CMakeLists.txt.
This makes feature_summary() much less useful, because it is difficult
to see what is going on with such a long list, and the transitive
dependencies will not have information about the type and purpose set.
This adds a new package property, TRANSITIVE_DEPENDENCY, which is set by
find_dependency(). feature_summary() then omits any packages with that
set. If a CMakeLists.txt also finds the package directly and sets
information about it using set_package_properties(), the
TRANSITIVE_DEPENDENCY property is discarded.
---
Modules/CMakeFindDependencyMacro.cmake | 7 ++++++-
Modules/FeatureSummary.cmake | 25 +++++++++++++++++++++++--
2 files changed, 29 insertions(+), 3 deletions(-)
diff --git a/Modules/CMakeFindDependencyMacro.cmake b/Modules/CMakeFindDependencyMacro.cmake
index 596c6fc..55a7ffa 100644
--- a/Modules/CMakeFindDependencyMacro.cmake
+++ b/Modules/CMakeFindDependencyMacro.cmake
@@ -11,7 +11,9 @@
# dependency. It is designed to be used in a <package>Config.cmake file, and it
# forwards the correct parameters for EXACT, QUIET and REQUIRED which were
# passed to the original :command:`find_package` call. It also sets an
-# informative diagnostic message if the dependency could not be found.
+# informative diagnostic message if the dependency could not be found, and
+# marks the package as a TRANSITIVE_DEPENDENCY for
+# :command:`feature_summary`.
#
#=============================================================================
@@ -27,6 +29,8 @@
# (To distribute this file outside of CMake, substitute the full
# License text for the above reference.)
+include(FeatureSummary)
+
macro(find_dependency dep)
if (NOT ${dep}_FOUND)
if (${ARGV1})
@@ -46,6 +50,7 @@ macro(find_dependency dep)
endif()
find_package(${dep} ${version} ${exact_arg} ${quiet_arg} ${required_arg})
+ set_package_properties(${dep} PROPERTIES TRANSITIVE_DEPENDENCY)
if (NOT ${dep}_FOUND)
set(${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE "${CMAKE_FIND_PACKAGE_NAME} could not be found because dependency ${dep} could not be found.")
set(${CMAKE_FIND_PACKAGE_NAME}_FOUND False)
diff --git a/Modules/FeatureSummary.cmake b/Modules/FeatureSummary.cmake
index b0f8e16..1d561b3 100644
--- a/Modules/FeatureSummary.cmake
+++ b/Modules/FeatureSummary.cmake
@@ -115,6 +115,7 @@
# [ DESCRIPTION <description> ]
# [ TYPE (RUNTIME|OPTIONAL|RECOMMENDED|REQUIRED) ]
# [ PURPOSE <purpose> ]
+# [ TRANSITIVE_DEPENDENCY ]
# )
#
#
@@ -157,6 +158,12 @@
# the PURPOSE property is project-specific, so it cannot be set by the
# Find-module, but must be set in the project.
#
+# TRANSITIVE_DEPENDENCY: This indicates that the package has only been
+# found as a dependency of another package; it only makes sense to use
+# this option from a *Config.cmake file. A package will only be
+# labelled as a transitive dependency if every SET_PACKAGE_PROPERTIES
+# call for this package includes the TRANSITIVE_DEPENDENCY flag.
+#
#
#
# Example for setting the info for a package:
@@ -243,6 +250,7 @@
#=============================================================================
# Copyright 2007-2009 Kitware, Inc.
+# Copyright 2014 Alex Merry <dev at randomguy3.me.uk>
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
@@ -274,7 +282,7 @@ function(SET_PACKAGE_PROPERTIES _name _props)
message(FATAL_ERROR "PROPERTIES keyword is missing in SET_PACKAGE_PROPERTIES() call.")
endif()
- set(options ) # none
+ set(options TRANSITIVE_DEPENDENCY)
set(oneValueArgs DESCRIPTION URL TYPE PURPOSE )
set(multiValueArgs ) # none
@@ -330,6 +338,12 @@ function(SET_PACKAGE_PROPERTIES _name _props)
set_property(GLOBAL PROPERTY _CMAKE_${_name}_TYPE "${_SPP_TYPE}" )
endif()
+ if(_SPP_TRANSITIVE_DEPENDENCY)
+ set_property(GLOBAL PROPERTY _CMAKE_${_name}_TRANSITIVE_DEPENDENCY TRUE)
+ else()
+ set_property(GLOBAL PROPERTY _CMAKE_${_name}_TRANSITIVE_DEPENDENCY FALSE)
+ endif()
+
endfunction()
@@ -367,8 +381,9 @@ function(_FS_GET_FEATURE_SUMMARY _property _var _includeQuiet)
if("${_type}" STREQUAL ANY OR "${_type}" STREQUAL "${_currentType}")
- # check whether the current feature/package should be in the output depending on whether it was QUIET or not
+ # check whether the current feature/package should be in the output
set(includeThisOne TRUE)
+
# skip QUIET packages, except if they are REQUIRED or INCLUDE_QUIET_PACKAGES has been set
if((NOT "${_currentType}" STREQUAL "REQUIRED") AND NOT _includeQuiet)
get_property(_isQuiet GLOBAL PROPERTY _CMAKE_${_currentFeature}_QUIET)
@@ -377,6 +392,12 @@ function(_FS_GET_FEATURE_SUMMARY _property _var _includeQuiet)
endif()
endif()
+ # skip TRANSITIVE_DEPENDENCY packages
+ get_property(_isTransDep GLOBAL PROPERTY _CMAKE_${_currentFeature}_TRANSITIVE_DEPENDENCY)
+ if(_isTransDep)
+ set(includeThisOne FALSE)
+ endif()
+
if(includeThisOne)
set(_currentFeatureText "${_currentFeatureText}\n * ${_currentFeature}")
--
1.8.5.3
More information about the cmake-developers
mailing list