FeatureSummary.cmake 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. # - Macros for generating a summary of enabled/disabled features
  2. #
  3. # This module provides the macros feature_summary(), set_package_info() and
  4. # add_feature_info().
  5. # For compatiblity it also still provides set_feature_info(),
  6. # print_enabled_features() and print_disabled_features.
  7. #
  8. # These macros can be used to generate a summary of enabled and disabled
  9. # packages and/or feature for a build tree:
  10. #
  11. # -- Enabled features:
  12. # LibXml2 (required version >= 2.4) , XML processing library. , <http://xmlsoft.org>
  13. # PNG , A PNG image library. , <http://www.libpng.org/pub/png/>
  14. # -- Disabled features:
  15. # Lua51 , The Lua scripting language. , <http://www.lua.org>
  16. # Foo , Foo provides cool stuff.
  17. #
  18. #
  19. # FEATURE_SUMMARY( [FILENAME <file>]
  20. # [APPEND]
  21. # [VAR <variable_name>]
  22. # [DESCRIPTION "Found packages:"]
  23. # WHAT (ALL | PACKAGES_FOUND | PACKAGES_NOT_FOUND
  24. # | ENABLED_FEATURES | DISABLED_FEATURES]
  25. # )
  26. #
  27. # The FEATURE_SUMMARY() macro can be used to print information about enabled
  28. # or disabled features or packages of a project.
  29. # By default, only the names of the features/packages will be printed and their
  30. # required version when one was specified. Use SET_FEATURE_INFO() to add more
  31. # useful information, like e.g. a download URL for the respective package.
  32. #
  33. # The WHAT option is the only mandatory option. Here you specify what information
  34. # will be printed:
  35. # ENABLED_FEATURES: the list of all features and packages which are enabled,
  36. # excluding the QUIET packages
  37. # DISABLED_FEATURES: the list of all features and packages which are disabled,
  38. # excluding the QUIET packages
  39. # PACKAGES_FOUND: the list of all packages which have been found
  40. # PACKAGES_NOT_FOUND: the list of all packages which have not been found
  41. # ALL: this will give all packages which have or have not been found
  42. #
  43. # If a FILENAME is given, the information is printed into this file. If APPEND
  44. # is used, it is appended to this file, otherwise the file is overwritten if
  45. # it already existed.
  46. # If the VAR option is used, the information is "printed" into the specified
  47. # variable.
  48. # If FILENAME is not used, the information is printed to the terminal.
  49. # Using the DESCRIPTION option a description or headline can be set which will
  50. # be printed above the actual content.
  51. #
  52. # Example 1, append everything to a file:
  53. # feature_summary(WHAT ALL
  54. # FILENAME ${CMAKE_BINARY_DIR}/all.log APPEND)
  55. #
  56. # Example 2, print the enabled features into the variable enabledFeaturesText:
  57. # feature_summary(WHAT ENABLED_FEATURES
  58. # DESCRIPTION "Enabled Features:"
  59. # VAR enabledFeaturesText)
  60. # message(STATUS "${enabledFeaturesText}")
  61. #
  62. #
  63. # SET_PACKAGE_INFO(<name> <description> [<url> [<comment>] ] )
  64. # Use this macro to set up information about the named package, which can
  65. # then be displayed via FEATURE_SUMMARY().
  66. # This can be done either directly in the Find-module or in the project
  67. # which uses the module after the FIND_PACKAGE() call.
  68. # The features for which information can be set are added automatically by the
  69. # find_package() command.
  70. #
  71. # Example for setting the info for a package:
  72. # find_package(LibXml2)
  73. # set_package_info(LibXml2 "XML processing library." "http://xmlsoft.org/")
  74. #
  75. #
  76. # ADD_FEATURE_INFO(<name> <enabled> <description>)
  77. # Use this macro to add information about a feature with the given <name>.
  78. # <enabled> contains whether this feature is enabled or not, <description>
  79. # is a text descibing the feature.
  80. # The information can be displayed using feature_summary() for ENABLED_FEATURES
  81. # and DISABLED_FEATURES respectively.
  82. #
  83. # Example for setting the info for a feature:
  84. # option(WITH_FOO "Help for foo" ON)
  85. # add_feature_info(Foo WITH_FOO "The Foo feature provides very cool stuff.")
  86. #
  87. #
  88. # The following macros are provided for compatibility with previous CMake versions:
  89. #
  90. # PRINT_ENABLED_FEATURES()
  91. # Does the same as FEATURE_SUMMARY(WHAT ENABLED_FEATURES DESCRIPTION "Enabled features:")
  92. #
  93. # PRINT_DISABLED_FEATURES()
  94. # Does the same as FEATURE_SUMMARY(WHAT DISABLED_FEATURES DESCRIPTION "Disabled features:")
  95. #
  96. # SET_FEATURE_INFO(<name> <description> [<url> [<comment>] ] )
  97. # Does the same as SET_PACKAGE_INFO(<name> <description> <url> <comment> )
  98. #=============================================================================
  99. # Copyright 2007-2009 Kitware, Inc.
  100. #
  101. # Distributed under the OSI-approved BSD License (the "License");
  102. # see accompanying file Copyright.txt for details.
  103. #
  104. # This software is distributed WITHOUT ANY WARRANTY; without even the
  105. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  106. # See the License for more information.
  107. #=============================================================================
  108. # (To distribute this file outside of CMake, substitute the full
  109. # License text for the above reference.)
  110. INCLUDE(CMakeParseArguments)
  111. FUNCTION(ADD_FEATURE_INFO _name _enabled _desc)
  112. IF (${_enabled})
  113. SET_PROPERTY(GLOBAL APPEND PROPERTY ENABLED_FEATURES "${_name}")
  114. ELSE ()
  115. SET_PROPERTY(GLOBAL APPEND PROPERTY DISABLED_FEATURES "${_name}")
  116. ENDIF ()
  117. SET_PROPERTY(GLOBAL PROPERTY _CMAKE_${_name}_DESCRIPTION "${_desc}" )
  118. ENDFUNCTION(ADD_FEATURE_INFO)
  119. FUNCTION(SET_FEATURE_INFO)
  120. SET_PACKAGE_INFO(${ARGN})
  121. ENDFUNCTION(SET_FEATURE_INFO)
  122. FUNCTION(SET_PACKAGE_INFO _name _desc)
  123. SET(_url "${ARGV2}")
  124. SET(_comment "${ARGV3}")
  125. SET_PROPERTY(GLOBAL PROPERTY _CMAKE_${_name}_DESCRIPTION "${_desc}" )
  126. IF(_url MATCHES ".+")
  127. SET_PROPERTY(GLOBAL PROPERTY _CMAKE_${_name}_URL "${_url}" )
  128. ENDIF(_url MATCHES ".+")
  129. IF(_comment MATCHES ".+")
  130. SET_PROPERTY(GLOBAL PROPERTY _CMAKE_${_name}_COMMENT "${_comment}" )
  131. ENDIF(_comment MATCHES ".+")
  132. ENDFUNCTION(SET_PACKAGE_INFO)
  133. FUNCTION(_FS_GET_FEATURE_SUMMARY _property _var)
  134. SET(_currentFeatureText "")
  135. GET_PROPERTY(_EnabledFeatures GLOBAL PROPERTY ${_property})
  136. FOREACH(_currentFeature ${_EnabledFeatures})
  137. SET(_currentFeatureText "${_currentFeatureText}\n${_currentFeature}")
  138. GET_PROPERTY(_info GLOBAL PROPERTY _CMAKE_${_currentFeature}_REQUIRED_VERSION)
  139. IF(_info)
  140. SET(_currentFeatureText "${_currentFeatureText} (required version ${_info})")
  141. ENDIF(_info)
  142. GET_PROPERTY(_info GLOBAL PROPERTY _CMAKE_${_currentFeature}_DESCRIPTION)
  143. IF(_info)
  144. SET(_currentFeatureText "${_currentFeatureText} , ${_info}")
  145. ENDIF(_info)
  146. GET_PROPERTY(_info GLOBAL PROPERTY _CMAKE_${_currentFeature}_URL)
  147. IF(_info)
  148. SET(_currentFeatureText "${_currentFeatureText} , <${_info}>")
  149. ENDIF(_info)
  150. GET_PROPERTY(_info GLOBAL PROPERTY _CMAKE_${_currentFeature}_COMMENT)
  151. IF(_info)
  152. SET(_currentFeatureText "${_currentFeatureText} , ${_info}")
  153. ENDIF(_info)
  154. ENDFOREACH(_currentFeature)
  155. SET(${_var} "${_currentFeatureText}" PARENT_SCOPE)
  156. ENDFUNCTION(_FS_GET_FEATURE_SUMMARY)
  157. FUNCTION(PRINT_ENABLED_FEATURES)
  158. FEATURE_SUMMARY(WHAT ENABLED_FEATURES DESCRIPTION "Enabled features:")
  159. ENDFUNCTION(PRINT_ENABLED_FEATURES)
  160. FUNCTION(PRINT_DISABLED_FEATURES)
  161. FEATURE_SUMMARY(WHAT DISABLED_FEATURES DESCRIPTION "Disabled features:")
  162. ENDFUNCTION(PRINT_DISABLED_FEATURES)
  163. FUNCTION(FEATURE_SUMMARY)
  164. # CMAKE_PARSE_ARGUMENTS(<prefix> <options> <one_value_keywords> <multi_value_keywords> args...)
  165. SET(options APPEND)
  166. SET(oneValueArgs FILENAME VAR DESCRIPTION WHAT)
  167. SET(multiValueArgs ) # none
  168. CMAKE_PARSE_ARGUMENTS(_FS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${_FIRST_ARG} ${ARGN})
  169. IF(_FS_UNPARSED_ARGUMENTS)
  170. MESSAGE(FATAL_ERROR "Unknown keywords given to FEATURE_SUMMARY(): \"${_FS_UNPARSED_ARGUMENTS}\"")
  171. ENDIF(_FS_UNPARSED_ARGUMENTS)
  172. IF(NOT _FS_WHAT)
  173. MESSAGE(FATAL_ERROR "The call to FEATURE_SUMMAY() doesn't set the required WHAT argument.")
  174. ENDIF(NOT _FS_WHAT)
  175. IF( "${_FS_WHAT}" STREQUAL "ENABLED_FEATURES"
  176. OR "${_FS_WHAT}" STREQUAL "DISABLED_FEATURES"
  177. OR "${_FS_WHAT}" STREQUAL "PACKAGES_FOUND"
  178. OR "${_FS_WHAT}" STREQUAL "PACKAGES_NOT_FOUND")
  179. _FS_GET_FEATURE_SUMMARY( ${_FS_WHAT} _featureSummary)
  180. SET(_fullText "${_FS_DESCRIPTION}${_featureSummary}\n")
  181. ELSEIF("${_FS_WHAT}" STREQUAL "ALL")
  182. _FS_GET_FEATURE_SUMMARY( PACKAGES_FOUND _tmp1)
  183. _FS_GET_FEATURE_SUMMARY( PACKAGES_NOT_FOUND _tmp2)
  184. SET(_featureSummary "${_tmp1}${_tmp2}")
  185. IF(_FS_DESCRIPTION)
  186. SET(_fullText "${_FS_DESCRIPTION}${_tmp1}${_tmp2}\n")
  187. ELSE(_FS_DESCRIPTION)
  188. SET(_fullText "-- Found the following packages:${_tmp1}\n-- Did not find the following packages:${_tmp2}\n")
  189. ENDIF(_FS_DESCRIPTION)
  190. ELSE()
  191. MESSAGE(FATAL_ERROR "The WHAT argument of FEATURE_SUMMARY() is set to ${_FS_WHAT}, which is not a valid value.")
  192. ENDIF()
  193. IF(_FS_FILENAME)
  194. IF(_FS_APPEND)
  195. FILE(APPEND "${_FS_FILENAME}" "${_fullText}")
  196. ELSE(_FS_APPEND)
  197. FILE(WRITE "${_FS_FILENAME}" "${_fullText}")
  198. ENDIF(_FS_APPEND)
  199. ELSE(_FS_FILENAME)
  200. IF(NOT _FS_VAR)
  201. MESSAGE(STATUS "${_fullText}")
  202. ENDIF(NOT _FS_VAR)
  203. ENDIF(_FS_FILENAME)
  204. IF(_FS_VAR)
  205. SET(${_FS_VAR} "${_fullText}" PARENT_SCOPE)
  206. ENDIF(_FS_VAR)
  207. ENDFUNCTION(FEATURE_SUMMARY)