FeatureSummary.cmake 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  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. # SET_PACKAGE_PROPERTIES(<name> PROPERTIES <description> [<url> [<purpose> [<type>] ] ] )
  76. #
  77. # URL: homepage of the package
  78. # DESCRIPTION: short description of the package itself
  79. # PURPOSE: what is the purpopse of using the package in the current project, always appended
  80. # TYPE: OPTIONAL (default), RECOMMENDED, REQUIRED, RUNTIME
  81. #
  82. # ADD_FEATURE_INFO(<name> <enabled> <description>)
  83. # Use this macro to add information about a feature with the given <name>.
  84. # <enabled> contains whether this feature is enabled or not, <description>
  85. # is a text descibing the feature.
  86. # The information can be displayed using feature_summary() for ENABLED_FEATURES
  87. # and DISABLED_FEATURES respectively.
  88. #
  89. # Example for setting the info for a feature:
  90. # option(WITH_FOO "Help for foo" ON)
  91. # add_feature_info(Foo WITH_FOO "The Foo feature provides very cool stuff.")
  92. #
  93. #
  94. # The following macros are provided for compatibility with previous CMake versions:
  95. #
  96. # PRINT_ENABLED_FEATURES()
  97. # Does the same as FEATURE_SUMMARY(WHAT ENABLED_FEATURES DESCRIPTION "Enabled features:")
  98. #
  99. # PRINT_DISABLED_FEATURES()
  100. # Does the same as FEATURE_SUMMARY(WHAT DISABLED_FEATURES DESCRIPTION "Disabled features:")
  101. #
  102. # SET_FEATURE_INFO(<name> <description> [<url> [<comment>] ] )
  103. # Does the same as SET_PACKAGE_INFO(<name> <description> <url> <comment> )
  104. #=============================================================================
  105. # Copyright 2007-2009 Kitware, Inc.
  106. #
  107. # Distributed under the OSI-approved BSD License (the "License");
  108. # see accompanying file Copyright.txt for details.
  109. #
  110. # This software is distributed WITHOUT ANY WARRANTY; without even the
  111. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  112. # See the License for more information.
  113. #=============================================================================
  114. # (To distribute this file outside of CMake, substitute the full
  115. # License text for the above reference.)
  116. INCLUDE(CMakeParseArguments)
  117. FUNCTION(ADD_FEATURE_INFO _name _enabled _desc)
  118. IF (${_enabled})
  119. SET_PROPERTY(GLOBAL APPEND PROPERTY ENABLED_FEATURES "${_name}")
  120. ELSE ()
  121. SET_PROPERTY(GLOBAL APPEND PROPERTY DISABLED_FEATURES "${_name}")
  122. ENDIF ()
  123. SET_PROPERTY(GLOBAL PROPERTY _CMAKE_${_name}_DESCRIPTION "${_desc}" )
  124. ENDFUNCTION(ADD_FEATURE_INFO)
  125. FUNCTION(SET_FEATURE_INFO)
  126. SET_PACKAGE_INFO(${ARGN})
  127. ENDFUNCTION(SET_FEATURE_INFO)
  128. FUNCTION(SET_PACKAGE_INFO _name _desc)
  129. SET(_url "${ARGV2}")
  130. SET(_comment "${ARGV3}")
  131. SET_PROPERTY(GLOBAL PROPERTY _CMAKE_${_name}_DESCRIPTION "${_desc}" )
  132. IF(_url MATCHES ".+")
  133. SET_PROPERTY(GLOBAL PROPERTY _CMAKE_${_name}_URL "${_url}" )
  134. ENDIF(_url MATCHES ".+")
  135. IF(_comment MATCHES ".+")
  136. SET_PROPERTY(GLOBAL PROPERTY _CMAKE_${_name}_COMMENT "${_comment}" )
  137. ENDIF(_comment MATCHES ".+")
  138. ENDFUNCTION(SET_PACKAGE_INFO)
  139. FUNCTION(SET_PACKAGE_PROPERTIES _name _props)
  140. IF(NOT "${_props}" STREQUAL "PROPERTIES")
  141. MESSAGE(FATAL_ERROR "PROPERTIES keyword is missing in SET_PACKAGE_PROPERTIES() call.")
  142. ENDIF()
  143. SET(options ) # none
  144. SET(oneValueArgs DESCRIPTION URL TYPE PURPOSE )
  145. SET(multiValueArgs ) # none
  146. CMAKE_PARSE_ARGUMENTS(_SPP "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
  147. IF(_SPP_UNPARSED_ARGUMENTS)
  148. MESSAGE(FATAL_ERROR "Unknown keywords given to SET_PACKAGE_PROPERTIES(): \"${_SPP_UNPARSED_ARGUMENTS}\"")
  149. ENDIF()
  150. IF(_SPP_DESCRIPTION)
  151. GET_PROPERTY(_info GLOBAL PROPERTY _CMAKE_${_name}_DESCRIPTION)
  152. IF(_info)
  153. MESSAGE(STATUS "Warning: Property DESCRIPTION for package ${_name} already set to \"${_info}\", overriding it with \"${_SPP_DESCRIPTION}\"")
  154. ENDIF()
  155. SET_PROPERTY(GLOBAL PROPERTY _CMAKE_${_name}_DESCRIPTION "${_SPP_DESCRIPTION}" )
  156. ENDIF()
  157. IF(_SPP_URL)
  158. GET_PROPERTY(_info GLOBAL PROPERTY _CMAKE_${_name}_URL)
  159. IF(_info)
  160. MESSAGE(STATUS "Warning: Property URL already set to \"${_info}\", overriding it with \"${_SPP_URL}\"")
  161. ENDIF()
  162. SET_PROPERTY(GLOBAL PROPERTY _CMAKE_${_name}_URL "${_SPP_URL}" )
  163. ENDIF()
  164. # handle the PURPOSE: use APPEND, since there can be multiple purposes for one package inside a project
  165. IF(_SPP_PURPOSE)
  166. SET_PROPERTY(GLOBAL APPEND PROPERTY _CMAKE_${_name}_PURPOSE "${_SPP_PURPOSE}" )
  167. ENDIF()
  168. # handle the TYPE
  169. IF(NOT _SPP_TYPE)
  170. SET(_SPP_TYPE OPTIONAL)
  171. ENDIF()
  172. SET(validTypes OPTIONAL RECOMMENDED REQUIRED RUNTIME )
  173. LIST(FIND validTypes ${_SPP_TYPE} _typeIndexInList)
  174. IF("${_typeIndexInList}" STREQUAL "-1" )
  175. MESSAGE(FATAL_ERROR "Bad package property type ${_SPP_TYPE} used in SET_PACKAGE_PROPERTIES(). "
  176. "Valid types are OPTIONAL, RECOMMENDED, REQUIRED and RUNTIME." )
  177. ENDIF()
  178. SET_PROPERTY(GLOBAL PROPERTY _CMAKE_${_name}_TYPE "${_SPP_TYPE}" )
  179. ENDFUNCTION(SET_PACKAGE_PROPERTIES)
  180. FUNCTION(_FS_GET_FEATURE_SUMMARY _property _var)
  181. SET(_type "ANY")
  182. IF("${_property}" MATCHES "REQUIRED_")
  183. SET(_type "REQUIRED")
  184. ELSEIF("${_property}" MATCHES "RECOMMENDED_")
  185. SET(_type "RECOMMENDED")
  186. ELSEIF("${_property}" MATCHES "RUNTIME_")
  187. SET(_type "RUNTIME")
  188. ELSEIF("${_property}" MATCHES "OPTIONAL_")
  189. SET(_type "OPTIONAL")
  190. ENDIF()
  191. IF("${_property}" MATCHES "PACKAGES_FOUND")
  192. SET(_property "PACKAGES_FOUND")
  193. ELSEIF("${_property}" MATCHES "PACKAGES_NOT_FOUND")
  194. SET(_property "PACKAGES_NOT_FOUND")
  195. ENDIF()
  196. SET(_currentFeatureText "")
  197. GET_PROPERTY(_EnabledFeatures GLOBAL PROPERTY ${_property})
  198. FOREACH(_currentFeature ${_EnabledFeatures})
  199. # does this package belong to the type we currently want to list ?
  200. GET_PROPERTY(_currentType GLOBAL PROPERTY _CMAKE_${_currentFeature}_TYPE)
  201. IF(NOT _currentType)
  202. SET(_currentType OPTIONAL)
  203. ENDIF()
  204. IF("${_type}" STREQUAL ANY OR "${_type}" STREQUAL "${_currentType}")
  205. SET(_currentFeatureText "${_currentFeatureText}\n${_currentFeature}")
  206. GET_PROPERTY(_info GLOBAL PROPERTY _CMAKE_${_currentFeature}_REQUIRED_VERSION)
  207. IF(_info)
  208. SET(_currentFeatureText "${_currentFeatureText} (required version ${_info})")
  209. ENDIF(_info)
  210. GET_PROPERTY(_info GLOBAL PROPERTY _CMAKE_${_currentFeature}_DESCRIPTION)
  211. IF(_info)
  212. SET(_currentFeatureText "${_currentFeatureText} , ${_info}")
  213. ENDIF(_info)
  214. GET_PROPERTY(_info GLOBAL PROPERTY _CMAKE_${_currentFeature}_URL)
  215. IF(_info)
  216. SET(_currentFeatureText "${_currentFeatureText} , <${_info}>")
  217. ENDIF(_info)
  218. GET_PROPERTY(_info GLOBAL PROPERTY _CMAKE_${_currentFeature}_COMMENT)
  219. IF(_info)
  220. SET(_currentFeatureText "${_currentFeatureText} , ${_info}")
  221. ENDIF(_info)
  222. GET_PROPERTY(_info GLOBAL PROPERTY _CMAKE_${_currentFeature}_PURPOSE)
  223. FOREACH(_purpose ${_info})
  224. SET(_currentFeatureText "${_currentFeatureText}\n * ${_purpose}")
  225. ENDFOREACH()
  226. ENDIF("${_type}" STREQUAL ANY OR "${_type}" STREQUAL "${_currentType}")
  227. ENDFOREACH(_currentFeature)
  228. SET(${_var} "${_currentFeatureText}" PARENT_SCOPE)
  229. ENDFUNCTION(_FS_GET_FEATURE_SUMMARY)
  230. FUNCTION(PRINT_ENABLED_FEATURES)
  231. FEATURE_SUMMARY(WHAT ENABLED_FEATURES DESCRIPTION "Enabled features:")
  232. ENDFUNCTION(PRINT_ENABLED_FEATURES)
  233. FUNCTION(PRINT_DISABLED_FEATURES)
  234. FEATURE_SUMMARY(WHAT DISABLED_FEATURES DESCRIPTION "Disabled features:")
  235. ENDFUNCTION(PRINT_DISABLED_FEATURES)
  236. FUNCTION(FEATURE_SUMMARY)
  237. # CMAKE_PARSE_ARGUMENTS(<prefix> <options> <one_value_keywords> <multi_value_keywords> args...)
  238. SET(options APPEND)
  239. SET(oneValueArgs FILENAME VAR DESCRIPTION WHAT)
  240. SET(multiValueArgs ) # none
  241. CMAKE_PARSE_ARGUMENTS(_FS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${_FIRST_ARG} ${ARGN})
  242. IF(_FS_UNPARSED_ARGUMENTS)
  243. MESSAGE(FATAL_ERROR "Unknown keywords given to FEATURE_SUMMARY(): \"${_FS_UNPARSED_ARGUMENTS}\"")
  244. ENDIF(_FS_UNPARSED_ARGUMENTS)
  245. IF(NOT _FS_WHAT)
  246. MESSAGE(FATAL_ERROR "The call to FEATURE_SUMMAY() doesn't set the required WHAT argument.")
  247. ENDIF(NOT _FS_WHAT)
  248. SET(validWhatParts "ENABLED_FEATURES"
  249. "DISABLED_FEATURES"
  250. "PACKAGES_FOUND"
  251. "PACKAGES_NOT_FOUND"
  252. "OPTIONAL_PACKAGES_FOUND"
  253. "OPTIONAL_PACKAGES_NOT_FOUND"
  254. "RECOMMENDED_PACKAGES_FOUND"
  255. "RECOMMENDED_PACKAGES_NOT_FOUND"
  256. "REQUIRED_PACKAGES_FOUND"
  257. "REQUIRED_PACKAGES_NOT_FOUND"
  258. "RUNTIME_PACKAGES_FOUND"
  259. "RUNTIME_PACKAGES_NOT_FOUND")
  260. LIST(FIND validWhatParts "${_FS_WHAT}" indexInList)
  261. IF(NOT "${indexInList}" STREQUAL "-1")
  262. _FS_GET_FEATURE_SUMMARY( ${_FS_WHAT} _featureSummary)
  263. SET(_fullText "${_FS_DESCRIPTION}${_featureSummary}\n")
  264. ELSEIF("${_FS_WHAT}" STREQUAL "ALL")
  265. SET(allWhatParts "ENABLED_FEATURES"
  266. "RUNTIME_PACKAGES_FOUND"
  267. "OPTIONAL_PACKAGES_FOUND"
  268. "RECOMMENDED_PACKAGES_FOUND"
  269. "REQUIRED_PACKAGES_FOUND"
  270. "DISABLED_FEATURES"
  271. "RUNTIME_PACKAGES_NOT_FOUND"
  272. "OPTIONAL_PACKAGES_NOT_FOUND"
  273. "RECOMMENDED_PACKAGES_NOT_FOUND"
  274. "REQUIRED_PACKAGES_NOT_FOUND"
  275. )
  276. SET(title_ENABLED_FEATURES "The following features have been enabled:")
  277. SET(title_DISABLED_FEATURES "The following features have been disabled:")
  278. SET(title_OPTIONAL_PACKAGES_FOUND "The following OPTIONAL packages have been found:")
  279. SET(title_OPTIONAL_PACKAGES_NOT_FOUND "The following OPTIONAL packages have not been found:")
  280. SET(title_RECOMMENDED_PACKAGES_FOUND "The following RECOMMENDED packages have been found:")
  281. SET(title_RECOMMENDED_PACKAGES_NOT_FOUND "The following RECOMMENDED packages have not been found:")
  282. SET(title_REQUIRED_PACKAGES_FOUND "The following REQUIRED packages have been found:")
  283. SET(title_REQUIRED_PACKAGES_NOT_FOUND "The following REQUIRED packages have not been found:")
  284. SET(title_RUNTIME_PACKAGES_FOUND "The following RUNTIME packages have been found:")
  285. SET(title_RUNTIME_PACKAGES_NOT_FOUND "The following RUNTIME packages have not been found:")
  286. SET(_fullText "${_FS_DESCRIPTION}\n")
  287. FOREACH(part ${allWhatParts})
  288. SET(_tmp)
  289. _FS_GET_FEATURE_SUMMARY( ${part} _tmp)
  290. IF(_tmp)
  291. SET(_fullText "${_fullText}\n${title_${part}}\n${_tmp}")
  292. ENDIF()
  293. ENDFOREACH()
  294. ELSE()
  295. MESSAGE(FATAL_ERROR "The WHAT argument of FEATURE_SUMMARY() is set to ${_FS_WHAT}, which is not a valid value.")
  296. ENDIF()
  297. IF(_FS_FILENAME)
  298. IF(_FS_APPEND)
  299. FILE(APPEND "${_FS_FILENAME}" "${_fullText}")
  300. ELSE(_FS_APPEND)
  301. FILE(WRITE "${_FS_FILENAME}" "${_fullText}")
  302. ENDIF(_FS_APPEND)
  303. ELSE(_FS_FILENAME)
  304. IF(NOT _FS_VAR)
  305. MESSAGE(STATUS "${_fullText}")
  306. ENDIF(NOT _FS_VAR)
  307. ENDIF(_FS_FILENAME)
  308. IF(_FS_VAR)
  309. SET(${_FS_VAR} "${_fullText}" PARENT_SCOPE)
  310. ENDIF(_FS_VAR)
  311. ENDFUNCTION(FEATURE_SUMMARY)