FeatureSummary.cmake 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file Copyright.txt or https://cmake.org/licensing for details.
  3. #[=======================================================================[.rst:
  4. FeatureSummary
  5. --------------
  6. Functions for generating a summary of enabled/disabled features.
  7. These functions can be used to generate a summary of enabled and disabled
  8. packages and/or feature for a build tree such as::
  9. -- The following OPTIONAL packages have been found:
  10. LibXml2 (required version >= 2.4), XML processing lib, <http://xmlsoft.org>
  11. * Enables HTML-import in MyWordProcessor
  12. * Enables odt-export in MyWordProcessor
  13. PNG, A PNG image library., <http://www.libpng.org/pub/png/>
  14. * Enables saving screenshots
  15. -- The following OPTIONAL packages have not been found:
  16. Lua51, The Lua scripting language., <https://www.lua.org>
  17. * Enables macros in MyWordProcessor
  18. Foo, Foo provides cool stuff.
  19. Global Properties
  20. ^^^^^^^^^^^^^^^^^
  21. .. variable:: FeatureSummary_PKG_TYPES
  22. The global property :variable:`FeatureSummary_PKG_TYPES` defines the type of
  23. packages used by `FeatureSummary`.
  24. The order in this list is important, the first package type in the list is the
  25. least important, the last is the most important. the of a package can only be
  26. changed to higher types.
  27. The default package types are , ``RUNTIME``, ``OPTIONAL``, ``RECOMMENDED`` and
  28. ``REQUIRED``, and their importance is
  29. ``RUNTIME < OPTIONAL < RECOMMENDED < REQUIRED``.
  30. .. variable:: FeatureSummary_REQUIRED_PKG_TYPES
  31. The global property :variable:`FeatureSummary_REQUIRED_PKG_TYPES` defines which
  32. package types are required.
  33. If one or more package in this categories has not been found, CMake will abort
  34. when calling :command:`feature_summary` with the
  35. 'FATAL_ON_MISSING_REQUIRED_PACKAGES' option enabled.
  36. The default value for this global property is ``REQUIRED``.
  37. .. variable:: FeatureSummary_DEFAULT_PKG_TYPE
  38. The global property :variable:`FeatureSummary_DEFAULT_PKG_TYPE` defines which
  39. package type is the default one.
  40. When calling :command:`feature_summary`, if the user did not set the package type
  41. explicitly, the package will be assigned to this category.
  42. This value must be one of the types defined in the
  43. :variable:`FeatureSummary_PKG_TYPES` global property unless the package type
  44. is set for all the packages.
  45. The default value for this global property is ``OPTIONAL``.
  46. .. variable:: FeatureSummary_<TYPE>_DESCRIPTION
  47. .. versionadded:: 3.9
  48. The global property :variable:`FeatureSummary_<TYPE>_DESCRIPTION` can be defined
  49. for each type to replace the type name with the specified string whenever the
  50. package type is used in an output string.
  51. If not set, the string "``<TYPE>`` packages" is used.
  52. #]=======================================================================]
  53. get_property(_fsPkgTypeIsSet GLOBAL PROPERTY FeatureSummary_PKG_TYPES SET)
  54. if(NOT _fsPkgTypeIsSet)
  55. set_property(GLOBAL PROPERTY FeatureSummary_PKG_TYPES RUNTIME OPTIONAL RECOMMENDED REQUIRED)
  56. endif()
  57. get_property(_fsReqPkgTypesIsSet GLOBAL PROPERTY FeatureSummary_REQUIRED_PKG_TYPES SET)
  58. if(NOT _fsReqPkgTypesIsSet)
  59. set_property(GLOBAL PROPERTY FeatureSummary_REQUIRED_PKG_TYPES REQUIRED)
  60. endif()
  61. get_property(_fsDefaultPkgTypeIsSet GLOBAL PROPERTY FeatureSummary_DEFAULT_PKG_TYPE SET)
  62. if(NOT _fsDefaultPkgTypeIsSet)
  63. set_property(GLOBAL PROPERTY FeatureSummary_DEFAULT_PKG_TYPE OPTIONAL)
  64. endif()
  65. #[=======================================================================[.rst:
  66. Functions
  67. ^^^^^^^^^
  68. #]=======================================================================]
  69. function(_FS_GET_FEATURE_SUMMARY _property _var _includeQuiet)
  70. get_property(_fsPkgTypes GLOBAL PROPERTY FeatureSummary_PKG_TYPES)
  71. get_property(_fsDefaultPkgType GLOBAL PROPERTY FeatureSummary_DEFAULT_PKG_TYPE)
  72. set(_type "ANY")
  73. foreach(_fsPkgType ${_fsPkgTypes})
  74. if("${_property}" MATCHES "${_fsPkgType}_PACKAGES_(NOT_)?FOUND")
  75. set(_type "${_fsPkgType}")
  76. break()
  77. endif()
  78. endforeach()
  79. if("${_property}" MATCHES "PACKAGES_FOUND")
  80. set(_property "PACKAGES_FOUND")
  81. elseif("${_property}" MATCHES "PACKAGES_NOT_FOUND")
  82. set(_property "PACKAGES_NOT_FOUND")
  83. endif()
  84. set(_currentFeatureText "")
  85. get_property(_EnabledFeatures GLOBAL PROPERTY ${_property})
  86. if(_EnabledFeatures)
  87. list(REMOVE_DUPLICATES _EnabledFeatures)
  88. endif(_EnabledFeatures)
  89. foreach(_currentFeature ${_EnabledFeatures})
  90. # does this package belong to the type we currently want to list ?
  91. get_property(_currentType GLOBAL PROPERTY _CMAKE_${_currentFeature}_TYPE)
  92. if(NOT _currentType)
  93. list(FIND _fsPkgTypes "${_fsDefaultPkgType}" _defaultInPkgTypes)
  94. if("${_defaultInPkgTypes}" STREQUAL "-1")
  95. string(REGEX REPLACE ";([^;]+)$" " and \\1" _fsPkgTypes_msg "${_fsPkgTypes}")
  96. string(REPLACE ";" ", " _fsPkgTypes_msg "${_fsPkgTypes_msg}")
  97. message(FATAL_ERROR "Bad package property type ${_fsDefaultPkgType} used in global property FeatureSummary_DEFAULT_PKG_TYPE. "
  98. "Valid types are ${_fsPkgTypes_msg}. "
  99. "Either update FeatureSummary_DEFAULT_PKG_TYPE or add ${_fsDefaultPkgType} to the FeatureSummary_PKG_TYPES global property.")
  100. endif()
  101. set(_currentType ${_fsDefaultPkgType})
  102. endif()
  103. if("${_type}" STREQUAL ANY OR "${_type}" STREQUAL "${_currentType}")
  104. # check whether the current feature/package should be in the output depending on whether it was QUIET or not
  105. set(includeThisOne TRUE)
  106. set(_required FALSE)
  107. # skip QUIET packages, except if they are REQUIRED or INCLUDE_QUIET_PACKAGES has been set
  108. get_property(_fsReqPkgTypes GLOBAL PROPERTY FeatureSummary_REQUIRED_PKG_TYPES)
  109. foreach(_fsReqPkgType ${_fsReqPkgTypes})
  110. if("${_currentType}" STREQUAL "${_fsReqPkgType}")
  111. set(_required TRUE)
  112. break()
  113. endif()
  114. endforeach()
  115. if(NOT _required AND NOT _includeQuiet)
  116. get_property(_isQuiet GLOBAL PROPERTY _CMAKE_${_currentFeature}_QUIET)
  117. if(_isQuiet)
  118. set(includeThisOne FALSE)
  119. endif()
  120. endif()
  121. get_property(_isTransitiveDepend
  122. GLOBAL PROPERTY _CMAKE_${_currentFeature}_TRANSITIVE_DEPENDENCY
  123. )
  124. if(_isTransitiveDepend)
  125. set(includeThisOne FALSE)
  126. endif()
  127. if(includeThisOne)
  128. string(APPEND _currentFeatureText "\n * ${_currentFeature}")
  129. get_property(_info GLOBAL PROPERTY _CMAKE_${_currentFeature}_REQUIRED_VERSION)
  130. if(_info)
  131. string(APPEND _currentFeatureText " (required version ${_info})")
  132. endif()
  133. get_property(_info GLOBAL PROPERTY _CMAKE_${_currentFeature}_DESCRIPTION)
  134. if(_info)
  135. string(APPEND _currentFeatureText ", ${_info}")
  136. endif()
  137. get_property(_info GLOBAL PROPERTY _CMAKE_${_currentFeature}_URL)
  138. if(_info)
  139. string(APPEND _currentFeatureText ", <${_info}>")
  140. endif()
  141. get_property(_info GLOBAL PROPERTY _CMAKE_${_currentFeature}_PURPOSE)
  142. foreach(_purpose ${_info})
  143. string(APPEND _currentFeatureText "\n ${_purpose}")
  144. endforeach()
  145. endif()
  146. endif()
  147. endforeach()
  148. set(${_var} "${_currentFeatureText}" PARENT_SCOPE)
  149. endfunction()
  150. #[=======================================================================[.rst:
  151. .. command:: feature_summary
  152. ::
  153. feature_summary( [FILENAME <file>]
  154. [APPEND]
  155. [VAR <variable_name>]
  156. [INCLUDE_QUIET_PACKAGES]
  157. [FATAL_ON_MISSING_REQUIRED_PACKAGES]
  158. [DESCRIPTION "<description>" | DEFAULT_DESCRIPTION]
  159. [QUIET_ON_EMPTY]
  160. WHAT (ALL
  161. | PACKAGES_FOUND | PACKAGES_NOT_FOUND
  162. | <TYPE>_PACKAGES_FOUND | <TYPE>_PACKAGES_NOT_FOUND
  163. | ENABLED_FEATURES | DISABLED_FEATURES)
  164. )
  165. The ``feature_summary()`` macro can be used to print information about
  166. enabled or disabled packages or features of a project. By default,
  167. only the names of the features/packages will be printed and their
  168. required version when one was specified. Use ``set_package_properties()``
  169. to add more useful information, like e.g. a download URL for the
  170. respective package or their purpose in the project.
  171. The ``WHAT`` option is the only mandatory option. Here you specify what
  172. information will be printed:
  173. ``ALL``
  174. print everything
  175. ``ENABLED_FEATURES``
  176. the list of all features which are enabled
  177. ``DISABLED_FEATURES``
  178. the list of all features which are disabled
  179. ``PACKAGES_FOUND``
  180. the list of all packages which have been found
  181. ``PACKAGES_NOT_FOUND``
  182. the list of all packages which have not been found
  183. For each package type ``<TYPE>`` defined by the
  184. :variable:`FeatureSummary_PKG_TYPES` global property, the following
  185. information can also be used:
  186. ``<TYPE>_PACKAGES_FOUND``
  187. only those packages which have been found which have the type <TYPE>
  188. ``<TYPE>_PACKAGES_NOT_FOUND``
  189. only those packages which have not been found which have the type <TYPE>
  190. .. versionchanged:: 3.1
  191. With the exception of the ``ALL`` value, these values can be combined
  192. in order to customize the output. For example:
  193. .. code-block:: cmake
  194. feature_summary(WHAT ENABLED_FEATURES DISABLED_FEATURES)
  195. If a ``FILENAME`` is given, the information is printed into this file. If
  196. ``APPEND`` is used, it is appended to this file, otherwise the file is
  197. overwritten if it already existed. If the VAR option is used, the
  198. information is "printed" into the specified variable. If ``FILENAME`` is
  199. not used, the information is printed to the terminal. Using the
  200. ``DESCRIPTION`` option a description or headline can be set which will be
  201. printed above the actual content. If only one type of
  202. package was requested, no title is printed, unless it is explicitly set using
  203. either ``DESCRIPTION`` to use a custom string, or ``DEFAULT_DESCRIPTION`` to
  204. use a default title for the requested type.
  205. If ``INCLUDE_QUIET_PACKAGES`` is given, packages which have been searched with
  206. ``find_package(... QUIET)`` will also be listed. By default they are skipped.
  207. If ``FATAL_ON_MISSING_REQUIRED_PACKAGES`` is given, CMake will abort if a
  208. package which is marked as one of the package types listed in the
  209. :variable:`FeatureSummary_REQUIRED_PKG_TYPES` global property has not been
  210. found.
  211. The default value for the :variable:`FeatureSummary_REQUIRED_PKG_TYPES` global
  212. property is ``REQUIRED``.
  213. .. versionadded:: 3.9
  214. The ``DEFAULT_DESCRIPTION`` option.
  215. The :variable:`FeatureSummary_DEFAULT_PKG_TYPE` global property can be
  216. modified to change the default package type assigned when not explicitly
  217. assigned by the user.
  218. .. versionadded:: 3.8
  219. If the ``QUIET_ON_EMPTY`` option is used, if only one type of package was
  220. requested, and no packages belonging to that category were found, then no
  221. output (including the ``DESCRIPTION``) is printed or added to the ``VAR``
  222. variable.
  223. Example 1, append everything to a file:
  224. .. code-block:: cmake
  225. include(FeatureSummary)
  226. feature_summary(WHAT ALL
  227. FILENAME ${CMAKE_BINARY_DIR}/all.log APPEND)
  228. Example 2, print the enabled features into the variable
  229. enabledFeaturesText, including QUIET packages:
  230. .. code-block:: cmake
  231. include(FeatureSummary)
  232. feature_summary(WHAT ENABLED_FEATURES
  233. INCLUDE_QUIET_PACKAGES
  234. DESCRIPTION "Enabled Features:"
  235. VAR enabledFeaturesText)
  236. message(STATUS "${enabledFeaturesText}")
  237. Example 3, change default package types and print only the categories that
  238. are not empty:
  239. .. code-block:: cmake
  240. include(FeatureSummary)
  241. set_property(GLOBAL APPEND PROPERTY FeatureSummary_PKG_TYPES BUILD)
  242. find_package(FOO)
  243. set_package_properties(FOO PROPERTIES TYPE BUILD)
  244. feature_summary(WHAT BUILD_PACKAGES_FOUND
  245. Description "Build tools found:"
  246. QUIET_ON_EMPTY)
  247. feature_summary(WHAT BUILD_PACKAGES_NOT_FOUND
  248. Description "Build tools not found:"
  249. QUIET_ON_EMPTY)
  250. #]=======================================================================]
  251. function(FEATURE_SUMMARY)
  252. # CMAKE_PARSE_ARGUMENTS(<prefix> <options> <one_value_keywords> <multi_value_keywords> args...)
  253. set(options APPEND
  254. INCLUDE_QUIET_PACKAGES
  255. FATAL_ON_MISSING_REQUIRED_PACKAGES
  256. QUIET_ON_EMPTY
  257. DEFAULT_DESCRIPTION)
  258. set(oneValueArgs FILENAME
  259. VAR
  260. DESCRIPTION)
  261. set(multiValueArgs WHAT)
  262. CMAKE_PARSE_ARGUMENTS(_FS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${_FIRST_ARG} ${ARGN})
  263. if(_FS_UNPARSED_ARGUMENTS)
  264. message(FATAL_ERROR "Unknown keywords given to FEATURE_SUMMARY(): \"${_FS_UNPARSED_ARGUMENTS}\"")
  265. endif()
  266. if(NOT _FS_WHAT)
  267. message(FATAL_ERROR "The call to FEATURE_SUMMARY() doesn't set the required WHAT argument.")
  268. endif()
  269. if(_FS_DEFAULT_DESCRIPTION AND DEFINED _FS_DESCRIPTION)
  270. message(WARNING "DEFAULT_DESCRIPTION option discarded since DESCRIPTION is set.")
  271. set(_FS_DEFAULT_DESCRIPTION 0)
  272. endif()
  273. set(validWhatParts "ENABLED_FEATURES"
  274. "DISABLED_FEATURES"
  275. "PACKAGES_FOUND"
  276. "PACKAGES_NOT_FOUND")
  277. get_property(_fsPkgTypes GLOBAL PROPERTY FeatureSummary_PKG_TYPES)
  278. get_property(_fsReqPkgTypes GLOBAL PROPERTY FeatureSummary_REQUIRED_PKG_TYPES)
  279. foreach(_fsPkgType ${_fsPkgTypes})
  280. list(APPEND validWhatParts "${_fsPkgType}_PACKAGES_FOUND"
  281. "${_fsPkgType}_PACKAGES_NOT_FOUND")
  282. endforeach()
  283. set(title_ENABLED_FEATURES "The following features have been enabled:")
  284. set(title_DISABLED_FEATURES "The following features have been disabled:")
  285. set(title_PACKAGES_FOUND "The following packages have been found:")
  286. set(title_PACKAGES_NOT_FOUND "The following packages have not been found:")
  287. foreach(_fsPkgType ${_fsPkgTypes})
  288. set(_fsPkgTypeDescription "${_fsPkgType} packages")
  289. get_property(_fsPkgTypeDescriptionIsSet GLOBAL PROPERTY FeatureSummary_${_fsPkgType}_DESCRIPTION SET)
  290. if(_fsPkgTypeDescriptionIsSet)
  291. get_property(_fsPkgTypeDescription GLOBAL PROPERTY FeatureSummary_${_fsPkgType}_DESCRIPTION )
  292. endif()
  293. set(title_${_fsPkgType}_PACKAGES_FOUND "The following ${_fsPkgTypeDescription} have been found:")
  294. set(title_${_fsPkgType}_PACKAGES_NOT_FOUND "The following ${_fsPkgTypeDescription} have not been found:")
  295. endforeach()
  296. list(FIND validWhatParts "${_FS_WHAT}" indexInList)
  297. if(NOT "${indexInList}" STREQUAL "-1")
  298. _FS_GET_FEATURE_SUMMARY( ${_FS_WHAT} _featureSummary ${_FS_INCLUDE_QUIET_PACKAGES} )
  299. if(_featureSummary OR NOT _FS_QUIET_ON_EMPTY)
  300. if(_FS_DEFAULT_DESCRIPTION)
  301. set(_fullText "${title_${_FS_WHAT}}\n${_featureSummary}\n")
  302. else()
  303. set(_fullText "${_FS_DESCRIPTION}${_featureSummary}\n")
  304. endif()
  305. endif()
  306. if(_featureSummary)
  307. foreach(_fsReqPkgType ${_fsReqPkgTypes})
  308. if("${_FS_WHAT}" STREQUAL "${_fsReqPkgType}_PACKAGES_NOT_FOUND")
  309. set(requiredPackagesNotFound TRUE)
  310. break()
  311. endif()
  312. endforeach()
  313. endif()
  314. else()
  315. if("${_FS_WHAT}" STREQUAL "ALL")
  316. set(allWhatParts "ENABLED_FEATURES")
  317. foreach(_fsPkgType ${_fsPkgTypes})
  318. list(APPEND allWhatParts "${_fsPkgType}_PACKAGES_FOUND")
  319. endforeach()
  320. list(APPEND allWhatParts "DISABLED_FEATURES")
  321. foreach(_fsPkgType ${_fsPkgTypes})
  322. list(APPEND allWhatParts "${_fsPkgType}_PACKAGES_NOT_FOUND")
  323. endforeach()
  324. else()
  325. set(allWhatParts)
  326. foreach(part ${_FS_WHAT})
  327. list(FIND validWhatParts "${part}" indexInList)
  328. if(NOT "${indexInList}" STREQUAL "-1")
  329. list(APPEND allWhatParts "${part}")
  330. else()
  331. if("${part}" STREQUAL "ALL")
  332. message(FATAL_ERROR "The WHAT argument of FEATURE_SUMMARY() contains ALL, which cannot be combined with other values.")
  333. else()
  334. message(FATAL_ERROR "The WHAT argument of FEATURE_SUMMARY() contains ${part}, which is not a valid value.")
  335. endif()
  336. endif()
  337. endforeach()
  338. endif()
  339. set(_fullText "${_FS_DESCRIPTION}")
  340. foreach(part ${allWhatParts})
  341. set(_tmp)
  342. _FS_GET_FEATURE_SUMMARY( ${part} _tmp ${_FS_INCLUDE_QUIET_PACKAGES})
  343. if(_tmp)
  344. if(_fullText)
  345. string(APPEND _fullText "\n-- ")
  346. endif()
  347. string(APPEND _fullText "${title_${part}}\n${_tmp}\n")
  348. foreach(_fsReqPkgType ${_fsReqPkgTypes})
  349. if("${part}" STREQUAL "${_fsReqPkgType}_PACKAGES_NOT_FOUND")
  350. set(requiredPackagesNotFound TRUE)
  351. break()
  352. endif()
  353. endforeach()
  354. endif()
  355. endforeach()
  356. endif()
  357. if(_fullText OR NOT _FS_QUIET_ON_EMPTY)
  358. if(_FS_FILENAME)
  359. if(_FS_APPEND)
  360. file(APPEND "${_FS_FILENAME}" "${_fullText}")
  361. else()
  362. file(WRITE "${_FS_FILENAME}" "${_fullText}")
  363. endif()
  364. else()
  365. if(NOT _FS_VAR)
  366. message(STATUS "${_fullText}")
  367. endif()
  368. endif()
  369. if(_FS_VAR)
  370. set(${_FS_VAR} "${_fullText}" PARENT_SCOPE)
  371. endif()
  372. endif()
  373. if(requiredPackagesNotFound AND _FS_FATAL_ON_MISSING_REQUIRED_PACKAGES)
  374. message(FATAL_ERROR "feature_summary() Error: REQUIRED package(s) are missing, aborting CMake run.")
  375. endif()
  376. endfunction()
  377. #[=======================================================================[.rst:
  378. .. command:: set_package_properties
  379. ::
  380. set_package_properties(<name> PROPERTIES
  381. [ URL <url> ]
  382. [ DESCRIPTION <description> ]
  383. [ TYPE (RUNTIME|OPTIONAL|RECOMMENDED|REQUIRED) ]
  384. [ PURPOSE <purpose> ]
  385. )
  386. Use this macro to set up information about the named package, which
  387. can then be displayed via FEATURE_SUMMARY(). This can be done either
  388. directly in the Find-module or in the project which uses the module
  389. after the find_package() call. The features for which information can
  390. be set are added automatically by the find_package() command.
  391. ``URL <url>``
  392. This should be the homepage of the package, or something similar.
  393. Ideally this is set already directly in the Find-module.
  394. ``DESCRIPTION <description>``
  395. A short description what that package is, at most one sentence.
  396. Ideally this is set already directly in the Find-module.
  397. ``TYPE <type>``
  398. What type of dependency has the using project on that package.
  399. Default is ``OPTIONAL``. In this case it is a package which can be used
  400. by the project when available at buildtime, but it also work without.
  401. ``RECOMMENDED`` is similar to ``OPTIONAL``, i.e. the project will build if
  402. the package is not present, but the functionality of the resulting
  403. binaries will be severely limited. If a ``REQUIRED`` package is not
  404. available at buildtime, the project may not even build. This can be
  405. combined with the ``FATAL_ON_MISSING_REQUIRED_PACKAGES`` argument for
  406. ``feature_summary()``. Last, a ``RUNTIME`` package is a package which is
  407. actually not used at all during the build, but which is required for
  408. actually running the resulting binaries. So if such a package is
  409. missing, the project can still be built, but it may not work later on.
  410. If ``set_package_properties()`` is called multiple times for the same
  411. package with different TYPEs, the ``TYPE`` is only changed to higher
  412. TYPEs (``RUNTIME < OPTIONAL < RECOMMENDED < REQUIRED``), lower TYPEs are
  413. ignored. The ``TYPE`` property is project-specific, so it cannot be set
  414. by the Find-module, but must be set in the project.
  415. Type accepted can be changed by setting the
  416. :variable:`FeatureSummary_PKG_TYPES` global property.
  417. ``PURPOSE <purpose>``
  418. This describes which features this package enables in the
  419. project, i.e. it tells the user what functionality he gets in the
  420. resulting binaries. If set_package_properties() is called multiple
  421. times for a package, all PURPOSE properties are appended to a list of
  422. purposes of the package in the project. As the TYPE property, also
  423. the PURPOSE property is project-specific, so it cannot be set by the
  424. Find-module, but must be set in the project.
  425. Example for setting the info for a package:
  426. .. code-block:: cmake
  427. find_package(LibXml2)
  428. set_package_properties(LibXml2 PROPERTIES
  429. DESCRIPTION "A XML processing library."
  430. URL "http://xmlsoft.org/")
  431. # or
  432. set_package_properties(LibXml2 PROPERTIES
  433. TYPE RECOMMENDED
  434. PURPOSE "Enables HTML-import in MyWordProcessor")
  435. # or
  436. set_package_properties(LibXml2 PROPERTIES
  437. TYPE OPTIONAL
  438. PURPOSE "Enables odt-export in MyWordProcessor")
  439. find_package(DBUS)
  440. set_package_properties(DBUS PROPERTIES
  441. TYPE RUNTIME
  442. PURPOSE "Necessary to disable the screensaver during a presentation")
  443. #]=======================================================================]
  444. function(SET_PACKAGE_PROPERTIES _name _props)
  445. if(NOT "${_props}" STREQUAL "PROPERTIES")
  446. message(FATAL_ERROR "PROPERTIES keyword is missing in SET_PACKAGE_PROPERTIES() call.")
  447. endif()
  448. set(options ) # none
  449. set(oneValueArgs DESCRIPTION URL TYPE PURPOSE )
  450. set(multiValueArgs ) # none
  451. CMAKE_PARSE_ARGUMENTS(_SPP "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
  452. if(_SPP_UNPARSED_ARGUMENTS)
  453. message(FATAL_ERROR "Unknown keywords given to SET_PACKAGE_PROPERTIES(): \"${_SPP_UNPARSED_ARGUMENTS}\"")
  454. endif()
  455. if(_SPP_DESCRIPTION)
  456. get_property(_info GLOBAL PROPERTY _CMAKE_${_name}_DESCRIPTION)
  457. if(_info AND NOT "${_info}" STREQUAL "${_SPP_DESCRIPTION}")
  458. message(STATUS "Warning: Property DESCRIPTION for package ${_name} already set to \"${_info}\", overriding it with \"${_SPP_DESCRIPTION}\"")
  459. endif()
  460. set_property(GLOBAL PROPERTY _CMAKE_${_name}_DESCRIPTION "${_SPP_DESCRIPTION}" )
  461. endif()
  462. if(_SPP_URL)
  463. get_property(_info GLOBAL PROPERTY _CMAKE_${_name}_URL)
  464. if(_info AND NOT "${_info}" STREQUAL "${_SPP_URL}")
  465. message(STATUS "Warning: Property URL already set to \"${_info}\", overriding it with \"${_SPP_URL}\"")
  466. endif()
  467. set_property(GLOBAL PROPERTY _CMAKE_${_name}_URL "${_SPP_URL}" )
  468. endif()
  469. # handle the PURPOSE: use APPEND, since there can be multiple purposes for one package inside a project
  470. if(_SPP_PURPOSE)
  471. set_property(GLOBAL APPEND PROPERTY _CMAKE_${_name}_PURPOSE "${_SPP_PURPOSE}" )
  472. endif()
  473. get_property(_fsPkgTypes GLOBAL PROPERTY FeatureSummary_PKG_TYPES)
  474. get_property(_fsDefaultPkgType GLOBAL PROPERTY FeatureSummary_DEFAULT_PKG_TYPE)
  475. # handle the TYPE
  476. if(DEFINED _SPP_TYPE)
  477. # Supported types are listed in FeatureSummary_PKG_TYPES according to their priority
  478. get_property(_fsPkgTypes GLOBAL PROPERTY FeatureSummary_PKG_TYPES)
  479. list(FIND _fsPkgTypes ${_SPP_TYPE} _typeIndexInList)
  480. if("${_typeIndexInList}" STREQUAL "-1" )
  481. string(REGEX REPLACE ";([^;]+)$" " and \\1" _fsPkgTypes_msg "${_fsPkgTypes}")
  482. string(REPLACE ";" ", " _fsPkgTypes_msg "${_fsPkgTypes_msg}")
  483. message(FATAL_ERROR "Bad package property type ${_SPP_TYPE} used in SET_PACKAGE_PROPERTIES(). "
  484. "Valid types are ${_fsPkgTypes_msg}." )
  485. endif()
  486. get_property(_previousType GLOBAL PROPERTY _CMAKE_${_name}_TYPE)
  487. list(FIND _fsPkgTypes "${_previousType}" _prevTypeIndexInList)
  488. # make sure a previously set TYPE is not overridden with a lower new TYPE:
  489. if("${_typeIndexInList}" GREATER "${_prevTypeIndexInList}")
  490. set_property(GLOBAL PROPERTY _CMAKE_${_name}_TYPE "${_SPP_TYPE}" )
  491. endif()
  492. endif()
  493. endfunction()
  494. #[=======================================================================[.rst:
  495. .. command:: add_feature_info
  496. ::
  497. add_feature_info(<name> <enabled> <description>)
  498. Use this macro to add information about a feature with the given ``<name>``.
  499. ``<enabled>`` contains whether this feature is enabled or not. It can be a
  500. variable or a list of conditions.
  501. ``<description>`` is a text describing the feature. The information can
  502. be displayed using ``feature_summary()`` for ``ENABLED_FEATURES`` and
  503. ``DISABLED_FEATURES`` respectively.
  504. .. versionchanged:: 3.8
  505. ``<enabled>`` can be a list of conditions.
  506. .. versionchanged:: 3.32
  507. Full :ref:`Condition Syntax` is now supported for ``<enabled>``.
  508. See policy :policy:`CMP0183`.
  509. Example for setting the info for a feature:
  510. .. code-block:: cmake
  511. option(WITH_FOO "Help for foo" ON)
  512. add_feature_info(Foo WITH_FOO "The Foo feature provides very cool stuff.")
  513. #]=======================================================================]
  514. function(ADD_FEATURE_INFO _name _depends _desc)
  515. cmake_policy(GET CMP0183 _CDO_CMP0183
  516. PARENT_SCOPE # undocumented, do not use outside of CMake
  517. )
  518. set(_enabled 1)
  519. if("x${_CDO_CMP0183}x" STREQUAL "xNEWx")
  520. foreach(_d ${_depends})
  521. cmake_language(EVAL CODE "
  522. if(${_d})
  523. else()
  524. set(_enabled 0)
  525. endif()"
  526. )
  527. endforeach()
  528. else()
  529. foreach(_d ${_depends})
  530. string(REGEX REPLACE " +" ";" _d "${_d}")
  531. if(${_d})
  532. else()
  533. set(_enabled 0)
  534. break()
  535. endif()
  536. endforeach()
  537. endif()
  538. if (${_enabled})
  539. set_property(GLOBAL APPEND PROPERTY ENABLED_FEATURES "${_name}")
  540. else ()
  541. set_property(GLOBAL APPEND PROPERTY DISABLED_FEATURES "${_name}")
  542. endif ()
  543. set_property(GLOBAL PROPERTY _CMAKE_${_name}_DESCRIPTION "${_desc}" )
  544. if("x${_CDO_CMP0183}x" STREQUAL "xx" AND "x${_depends}x" MATCHES "[^A-Za-z0-9_.; ]")
  545. cmake_policy(GET_WARNING CMP0183 _CDO_CMP0183_WARNING)
  546. message(AUTHOR_WARNING "${_CDO_CMP0183_WARNING}")
  547. endif()
  548. unset(_CDO_CMP0183)
  549. endfunction()
  550. # The stuff below is only kept for compatibility
  551. #[=======================================================================[.rst:
  552. Legacy Macros
  553. ^^^^^^^^^^^^^
  554. The following macros are provided for compatibility with previous
  555. CMake versions:
  556. .. command:: set_package_info
  557. ::
  558. set_package_info(<name> <description> [ <url> [<purpose>] ])
  559. Use this macro to set up information about the named package, which
  560. can then be displayed via ``feature_summary()``. This can be done either
  561. directly in the Find-module or in the project which uses the module
  562. after the :command:`find_package` call. The features for which information
  563. can be set are added automatically by the ``find_package()`` command.
  564. #]=======================================================================]
  565. function(SET_PACKAGE_INFO _name _desc)
  566. message(DEPRECATION "SET_PACKAGE_INFO is deprecated. Use SET_PACKAGE_PROPERTIES instead.")
  567. unset(_url)
  568. unset(_purpose)
  569. if(ARGC GREATER 2)
  570. set(_url "${ARGV2}")
  571. endif()
  572. if(ARGC GREATER 3)
  573. set(_purpose "${ARGV3}")
  574. endif()
  575. set_property(GLOBAL PROPERTY _CMAKE_${_name}_DESCRIPTION "${_desc}" )
  576. if(NOT _url STREQUAL "")
  577. set_property(GLOBAL PROPERTY _CMAKE_${_name}_URL "${_url}" )
  578. endif()
  579. if(NOT _purpose STREQUAL "")
  580. set_property(GLOBAL APPEND PROPERTY _CMAKE_${_name}_PURPOSE "${_purpose}" )
  581. endif()
  582. endfunction()
  583. #[=======================================================================[.rst:
  584. .. command:: set_feature_info
  585. ::
  586. set_feature_info(<name> <description> [<url>])
  587. Does the same as::
  588. set_package_info(<name> <description> <url>)
  589. #]=======================================================================]
  590. function(SET_FEATURE_INFO)
  591. message(DEPRECATION "SET_FEATURE_INFO is deprecated. Use ADD_FEATURE_INFO instead.")
  592. SET_PACKAGE_INFO(${ARGN})
  593. endfunction()
  594. #[=======================================================================[.rst:
  595. .. command:: print_enabled_features
  596. ::
  597. print_enabled_features()
  598. Does the same as
  599. .. code-block:: cmake
  600. feature_summary(WHAT ENABLED_FEATURES DESCRIPTION "Enabled features:")
  601. #]=======================================================================]
  602. function(PRINT_ENABLED_FEATURES)
  603. message(DEPRECATION "PRINT_ENABLED_FEATURES is deprecated. Use
  604. feature_summary(WHAT ENABLED_FEATURES DESCRIPTION \"Enabled features:\")")
  605. FEATURE_SUMMARY(WHAT ENABLED_FEATURES DESCRIPTION "Enabled features:")
  606. endfunction()
  607. #[=======================================================================[.rst:
  608. .. command:: print_disabled_features
  609. ::
  610. print_disabled_features()
  611. Does the same as
  612. .. code-block:: cmake
  613. feature_summary(WHAT DISABLED_FEATURES DESCRIPTION "Disabled features:")
  614. #]=======================================================================]
  615. function(PRINT_DISABLED_FEATURES)
  616. message(DEPRECATION "PRINT_DISABLED_FEATURES is deprecated. Use
  617. feature_summary(WHAT DISABLED_FEATURES DESCRIPTION \"Disabled features:\")")
  618. FEATURE_SUMMARY(WHAT DISABLED_FEATURES DESCRIPTION "Disabled features:")
  619. endfunction()