FeatureSummary.cmake 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741
  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., <http://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. The global property :variable:`FeatureSummary_<TYPE>_DESCRIPTION` can be defined
  48. for each type to replace the type name with the specified string whenever the
  49. package type is used in an output string.
  50. If not set, the string "``<TYPE>`` packages" is used.
  51. #]=======================================================================]
  52. get_property(_fsPkgTypeIsSet GLOBAL PROPERTY FeatureSummary_PKG_TYPES SET)
  53. if(NOT _fsPkgTypeIsSet)
  54. set_property(GLOBAL PROPERTY FeatureSummary_PKG_TYPES RUNTIME OPTIONAL RECOMMENDED REQUIRED)
  55. endif()
  56. get_property(_fsReqPkgTypesIsSet GLOBAL PROPERTY FeatureSummary_REQUIRED_PKG_TYPES SET)
  57. if(NOT _fsReqPkgTypesIsSet)
  58. set_property(GLOBAL PROPERTY FeatureSummary_REQUIRED_PKG_TYPES REQUIRED)
  59. endif()
  60. get_property(_fsDefaultPkgTypeIsSet GLOBAL PROPERTY FeatureSummary_DEFAULT_PKG_TYPE SET)
  61. if(NOT _fsDefaultPkgTypeIsSet)
  62. set_property(GLOBAL PROPERTY FeatureSummary_DEFAULT_PKG_TYPE OPTIONAL)
  63. endif()
  64. #[=======================================================================[.rst:
  65. Functions
  66. ^^^^^^^^^
  67. #]=======================================================================]
  68. include(CMakeParseArguments)
  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. With the exception of the ``ALL`` value, these values can be combined
  191. in order to customize the output. For example:
  192. .. code-block:: cmake
  193. feature_summary(WHAT ENABLED_FEATURES DISABLED_FEATURES)
  194. If a ``FILENAME`` is given, the information is printed into this file. If
  195. ``APPEND`` is used, it is appended to this file, otherwise the file is
  196. overwritten if it already existed. If the VAR option is used, the
  197. information is "printed" into the specified variable. If ``FILENAME`` is
  198. not used, the information is printed to the terminal. Using the
  199. ``DESCRIPTION`` option a description or headline can be set which will be
  200. printed above the actual content. If only one type of
  201. package was requested, no title is printed, unless it is explicitly set using
  202. either ``DESCRIPTION`` to use a custom string, or ``DEFAULT_DESCRIPTION`` to
  203. use a default title for the requested type.
  204. If ``INCLUDE_QUIET_PACKAGES`` is given, packages which have been searched with
  205. ``find_package(... QUIET)`` will also be listed. By default they are skipped.
  206. If ``FATAL_ON_MISSING_REQUIRED_PACKAGES`` is given, CMake will abort if a
  207. package which is marked as one of the package types listed in the
  208. :variable:`FeatureSummary_REQUIRED_PKG_TYPES` global property has not been
  209. found.
  210. The default value for the :variable:`FeatureSummary_REQUIRED_PKG_TYPES` global
  211. property is ``REQUIRED``.
  212. The :variable:`FeatureSummary_DEFAULT_PKG_TYPE` global property can be
  213. modified to change the default package type assigned when not explicitly
  214. assigned by the user.
  215. If the ``QUIET_ON_EMPTY`` option is used, if only one type of package was
  216. requested, and no packages belonging to that category were found, then no
  217. output (including the ``DESCRIPTION``) is printed or added to the ``VAR``
  218. variable.
  219. Example 1, append everything to a file:
  220. .. code-block:: cmake
  221. include(FeatureSummary)
  222. feature_summary(WHAT ALL
  223. FILENAME ${CMAKE_BINARY_DIR}/all.log APPEND)
  224. Example 2, print the enabled features into the variable
  225. enabledFeaturesText, including QUIET packages:
  226. .. code-block:: cmake
  227. include(FeatureSummary)
  228. feature_summary(WHAT ENABLED_FEATURES
  229. INCLUDE_QUIET_PACKAGES
  230. DESCRIPTION "Enabled Features:"
  231. VAR enabledFeaturesText)
  232. message(STATUS "${enabledFeaturesText}")
  233. Example 3, change default package types and print only the categories that
  234. are not empty:
  235. .. code-block:: cmake
  236. include(FeatureSummary)
  237. set_property(GLOBAL APPEND PROPERTY FeatureSummary_PKG_TYPES BUILD)
  238. find_package(FOO)
  239. set_package_properties(FOO PROPERTIES TYPE BUILD)
  240. feature_summary(WHAT BUILD_PACKAGES_FOUND
  241. Description "Build tools found:"
  242. QUIET_ON_EMPTY)
  243. feature_summary(WHAT BUILD_PACKAGES_NOT_FOUND
  244. Description "Build tools not found:"
  245. QUIET_ON_EMPTY)
  246. #]=======================================================================]
  247. function(FEATURE_SUMMARY)
  248. # CMAKE_PARSE_ARGUMENTS(<prefix> <options> <one_value_keywords> <multi_value_keywords> args...)
  249. set(options APPEND
  250. INCLUDE_QUIET_PACKAGES
  251. FATAL_ON_MISSING_REQUIRED_PACKAGES
  252. QUIET_ON_EMPTY
  253. DEFAULT_DESCRIPTION)
  254. set(oneValueArgs FILENAME
  255. VAR
  256. DESCRIPTION)
  257. set(multiValueArgs WHAT)
  258. CMAKE_PARSE_ARGUMENTS(_FS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${_FIRST_ARG} ${ARGN})
  259. if(_FS_UNPARSED_ARGUMENTS)
  260. message(FATAL_ERROR "Unknown keywords given to FEATURE_SUMMARY(): \"${_FS_UNPARSED_ARGUMENTS}\"")
  261. endif()
  262. if(NOT _FS_WHAT)
  263. message(FATAL_ERROR "The call to FEATURE_SUMMARY() doesn't set the required WHAT argument.")
  264. endif()
  265. if(_FS_DEFAULT_DESCRIPTION AND DEFINED _FS_DESCRIPTION)
  266. message(WARNING "DEFAULT_DESCRIPTION option discarded since DESCRIPTION is set.")
  267. set(_FS_DEFAULT_DESCRIPTION 0)
  268. endif()
  269. set(validWhatParts "ENABLED_FEATURES"
  270. "DISABLED_FEATURES"
  271. "PACKAGES_FOUND"
  272. "PACKAGES_NOT_FOUND")
  273. get_property(_fsPkgTypes GLOBAL PROPERTY FeatureSummary_PKG_TYPES)
  274. get_property(_fsReqPkgTypes GLOBAL PROPERTY FeatureSummary_REQUIRED_PKG_TYPES)
  275. foreach(_fsPkgType ${_fsPkgTypes})
  276. list(APPEND validWhatParts "${_fsPkgType}_PACKAGES_FOUND"
  277. "${_fsPkgType}_PACKAGES_NOT_FOUND")
  278. endforeach()
  279. set(title_ENABLED_FEATURES "The following features have been enabled:")
  280. set(title_DISABLED_FEATURES "The following features have been disabled:")
  281. set(title_PACKAGES_FOUND "The following packages have been found:")
  282. set(title_PACKAGES_NOT_FOUND "The following packages have not been found:")
  283. foreach(_fsPkgType ${_fsPkgTypes})
  284. set(_fsPkgTypeDescription "${_fsPkgType} packages")
  285. get_property(_fsPkgTypeDescriptionIsSet GLOBAL PROPERTY FeatureSummary_${_fsPkgType}_DESCRIPTION SET)
  286. if(_fsPkgTypeDescriptionIsSet)
  287. get_property(_fsPkgTypeDescription GLOBAL PROPERTY FeatureSummary_${_fsPkgType}_DESCRIPTION )
  288. endif()
  289. set(title_${_fsPkgType}_PACKAGES_FOUND "The following ${_fsPkgTypeDescription} have been found:")
  290. set(title_${_fsPkgType}_PACKAGES_NOT_FOUND "The following ${_fsPkgTypeDescription} have not been found:")
  291. endforeach()
  292. list(FIND validWhatParts "${_FS_WHAT}" indexInList)
  293. if(NOT "${indexInList}" STREQUAL "-1")
  294. _FS_GET_FEATURE_SUMMARY( ${_FS_WHAT} _featureSummary ${_FS_INCLUDE_QUIET_PACKAGES} )
  295. if(_featureSummary OR NOT _FS_QUIET_ON_EMPTY)
  296. if(_FS_DEFAULT_DESCRIPTION)
  297. set(_fullText "${title_${_FS_WHAT}}\n${_featureSummary}\n")
  298. else()
  299. set(_fullText "${_FS_DESCRIPTION}${_featureSummary}\n")
  300. endif()
  301. endif()
  302. if(_featureSummary)
  303. foreach(_fsReqPkgType ${_fsReqPkgTypes})
  304. if("${_FS_WHAT}" STREQUAL "${_fsReqPkgType}_PACKAGES_NOT_FOUND")
  305. set(requiredPackagesNotFound TRUE)
  306. break()
  307. endif()
  308. endforeach()
  309. endif()
  310. else()
  311. if("${_FS_WHAT}" STREQUAL "ALL")
  312. set(allWhatParts "ENABLED_FEATURES")
  313. foreach(_fsPkgType ${_fsPkgTypes})
  314. list(APPEND allWhatParts "${_fsPkgType}_PACKAGES_FOUND")
  315. endforeach()
  316. list(APPEND allWhatParts "DISABLED_FEATURES")
  317. foreach(_fsPkgType ${_fsPkgTypes})
  318. list(APPEND allWhatParts "${_fsPkgType}_PACKAGES_NOT_FOUND")
  319. endforeach()
  320. else()
  321. set(allWhatParts)
  322. foreach(part ${_FS_WHAT})
  323. list(FIND validWhatParts "${part}" indexInList)
  324. if(NOT "${indexInList}" STREQUAL "-1")
  325. list(APPEND allWhatParts "${part}")
  326. else()
  327. if("${part}" STREQUAL "ALL")
  328. message(FATAL_ERROR "The WHAT argument of FEATURE_SUMMARY() contains ALL, which cannot be combined with other values.")
  329. else()
  330. message(FATAL_ERROR "The WHAT argument of FEATURE_SUMMARY() contains ${part}, which is not a valid value.")
  331. endif()
  332. endif()
  333. endforeach()
  334. endif()
  335. set(_fullText "${_FS_DESCRIPTION}")
  336. foreach(part ${allWhatParts})
  337. set(_tmp)
  338. _FS_GET_FEATURE_SUMMARY( ${part} _tmp ${_FS_INCLUDE_QUIET_PACKAGES})
  339. if(_tmp)
  340. if(_fullText)
  341. string(APPEND _fullText "\n-- ")
  342. endif()
  343. string(APPEND _fullText "${title_${part}}\n${_tmp}\n")
  344. foreach(_fsReqPkgType ${_fsReqPkgTypes})
  345. if("${part}" STREQUAL "${_fsReqPkgType}_PACKAGES_NOT_FOUND")
  346. set(requiredPackagesNotFound TRUE)
  347. break()
  348. endif()
  349. endforeach()
  350. endif()
  351. endforeach()
  352. endif()
  353. if(_fullText OR NOT _FS_QUIET_ON_EMPTY)
  354. if(_FS_FILENAME)
  355. if(_FS_APPEND)
  356. file(APPEND "${_FS_FILENAME}" "${_fullText}")
  357. else()
  358. file(WRITE "${_FS_FILENAME}" "${_fullText}")
  359. endif()
  360. else()
  361. if(NOT _FS_VAR)
  362. message(STATUS "${_fullText}")
  363. endif()
  364. endif()
  365. if(_FS_VAR)
  366. set(${_FS_VAR} "${_fullText}" PARENT_SCOPE)
  367. endif()
  368. endif()
  369. if(requiredPackagesNotFound AND _FS_FATAL_ON_MISSING_REQUIRED_PACKAGES)
  370. message(FATAL_ERROR "feature_summary() Error: REQUIRED package(s) are missing, aborting CMake run.")
  371. endif()
  372. endfunction()
  373. #[=======================================================================[.rst:
  374. .. command:: set_package_properties
  375. ::
  376. set_package_properties(<name> PROPERTIES
  377. [ URL <url> ]
  378. [ DESCRIPTION <description> ]
  379. [ TYPE (RUNTIME|OPTIONAL|RECOMMENDED|REQUIRED) ]
  380. [ PURPOSE <purpose> ]
  381. )
  382. Use this macro to set up information about the named package, which
  383. can then be displayed via FEATURE_SUMMARY(). This can be done either
  384. directly in the Find-module or in the project which uses the module
  385. after the find_package() call. The features for which information can
  386. be set are added automatically by the find_package() command.
  387. ``URL <url>``
  388. This should be the homepage of the package, or something similar.
  389. Ideally this is set already directly in the Find-module.
  390. ``DESCRIPTION <description>``
  391. A short description what that package is, at most one sentence.
  392. Ideally this is set already directly in the Find-module.
  393. ``TYPE <type>``
  394. What type of dependency has the using project on that package.
  395. Default is ``OPTIONAL``. In this case it is a package which can be used
  396. by the project when available at buildtime, but it also work without.
  397. ``RECOMMENDED`` is similar to ``OPTIONAL``, i.e. the project will build if
  398. the package is not present, but the functionality of the resulting
  399. binaries will be severely limited. If a ``REQUIRED`` package is not
  400. available at buildtime, the project may not even build. This can be
  401. combined with the ``FATAL_ON_MISSING_REQUIRED_PACKAGES`` argument for
  402. ``feature_summary()``. Last, a ``RUNTIME`` package is a package which is
  403. actually not used at all during the build, but which is required for
  404. actually running the resulting binaries. So if such a package is
  405. missing, the project can still be built, but it may not work later on.
  406. If ``set_package_properties()`` is called multiple times for the same
  407. package with different TYPEs, the ``TYPE`` is only changed to higher
  408. TYPEs (``RUNTIME < OPTIONAL < RECOMMENDED < REQUIRED``), lower TYPEs are
  409. ignored. The ``TYPE`` property is project-specific, so it cannot be set
  410. by the Find-module, but must be set in the project.
  411. Type accepted can be changed by setting the
  412. :variable:`FeatureSummary_PKG_TYPES` global property.
  413. ``PURPOSE <purpose>``
  414. This describes which features this package enables in the
  415. project, i.e. it tells the user what functionality he gets in the
  416. resulting binaries. If set_package_properties() is called multiple
  417. times for a package, all PURPOSE properties are appended to a list of
  418. purposes of the package in the project. As the TYPE property, also
  419. the PURPOSE property is project-specific, so it cannot be set by the
  420. Find-module, but must be set in the project.
  421. Example for setting the info for a package:
  422. .. code-block:: cmake
  423. find_package(LibXml2)
  424. set_package_properties(LibXml2 PROPERTIES
  425. DESCRIPTION "A XML processing library."
  426. URL "http://xmlsoft.org/")
  427. # or
  428. set_package_properties(LibXml2 PROPERTIES
  429. TYPE RECOMMENDED
  430. PURPOSE "Enables HTML-import in MyWordProcessor")
  431. # or
  432. set_package_properties(LibXml2 PROPERTIES
  433. TYPE OPTIONAL
  434. PURPOSE "Enables odt-export in MyWordProcessor")
  435. find_package(DBUS)
  436. set_package_properties(DBUS PROPERTIES
  437. TYPE RUNTIME
  438. PURPOSE "Necessary to disable the screensaver during a presentation")
  439. #]=======================================================================]
  440. function(SET_PACKAGE_PROPERTIES _name _props)
  441. if(NOT "${_props}" STREQUAL "PROPERTIES")
  442. message(FATAL_ERROR "PROPERTIES keyword is missing in SET_PACKAGE_PROPERTIES() call.")
  443. endif()
  444. set(options ) # none
  445. set(oneValueArgs DESCRIPTION URL TYPE PURPOSE )
  446. set(multiValueArgs ) # none
  447. CMAKE_PARSE_ARGUMENTS(_SPP "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
  448. if(_SPP_UNPARSED_ARGUMENTS)
  449. message(FATAL_ERROR "Unknown keywords given to SET_PACKAGE_PROPERTIES(): \"${_SPP_UNPARSED_ARGUMENTS}\"")
  450. endif()
  451. if(_SPP_DESCRIPTION)
  452. get_property(_info GLOBAL PROPERTY _CMAKE_${_name}_DESCRIPTION)
  453. if(_info AND NOT "${_info}" STREQUAL "${_SPP_DESCRIPTION}")
  454. message(STATUS "Warning: Property DESCRIPTION for package ${_name} already set to \"${_info}\", overriding it with \"${_SPP_DESCRIPTION}\"")
  455. endif()
  456. set_property(GLOBAL PROPERTY _CMAKE_${_name}_DESCRIPTION "${_SPP_DESCRIPTION}" )
  457. endif()
  458. if(_SPP_URL)
  459. get_property(_info GLOBAL PROPERTY _CMAKE_${_name}_URL)
  460. if(_info AND NOT "${_info}" STREQUAL "${_SPP_URL}")
  461. message(STATUS "Warning: Property URL already set to \"${_info}\", overriding it with \"${_SPP_URL}\"")
  462. endif()
  463. set_property(GLOBAL PROPERTY _CMAKE_${_name}_URL "${_SPP_URL}" )
  464. endif()
  465. # handle the PURPOSE: use APPEND, since there can be multiple purposes for one package inside a project
  466. if(_SPP_PURPOSE)
  467. set_property(GLOBAL APPEND PROPERTY _CMAKE_${_name}_PURPOSE "${_SPP_PURPOSE}" )
  468. endif()
  469. get_property(_fsPkgTypes GLOBAL PROPERTY FeatureSummary_PKG_TYPES)
  470. get_property(_fsDefaultPkgType GLOBAL PROPERTY FeatureSummary_DEFAULT_PKG_TYPE)
  471. # handle the TYPE
  472. if(DEFINED _SPP_TYPE)
  473. # Supported types are listed in FeatureSummary_PKG_TYPES according to their priority
  474. get_property(_fsPkgTypes GLOBAL PROPERTY FeatureSummary_PKG_TYPES)
  475. list(FIND _fsPkgTypes ${_SPP_TYPE} _typeIndexInList)
  476. if("${_typeIndexInList}" STREQUAL "-1" )
  477. string(REGEX REPLACE ";([^;]+)$" " and \\1" _fsPkgTypes_msg "${_fsPkgTypes}")
  478. string(REPLACE ";" ", " _fsPkgTypes_msg "${_fsPkgTypes_msg}")
  479. message(FATAL_ERROR "Bad package property type ${_SPP_TYPE} used in SET_PACKAGE_PROPERTIES(). "
  480. "Valid types are ${_fsPkgTypes_msg}." )
  481. endif()
  482. get_property(_previousType GLOBAL PROPERTY _CMAKE_${_name}_TYPE)
  483. list(FIND _fsPkgTypes "${_previousType}" _prevTypeIndexInList)
  484. # make sure a previously set TYPE is not overridden with a lower new TYPE:
  485. if("${_typeIndexInList}" GREATER "${_prevTypeIndexInList}")
  486. set_property(GLOBAL PROPERTY _CMAKE_${_name}_TYPE "${_SPP_TYPE}" )
  487. endif()
  488. endif()
  489. endfunction()
  490. #[=======================================================================[.rst:
  491. .. command:: add_feature_info
  492. ::
  493. add_feature_info(<name> <enabled> <description>)
  494. Use this macro to add information about a feature with the given ``<name>``.
  495. ``<enabled>`` contains whether this feature is enabled or not. It can be a
  496. variable or a list of conditions.
  497. ``<description>`` is a text describing the feature. The information can
  498. be displayed using ``feature_summary()`` for ``ENABLED_FEATURES`` and
  499. ``DISABLED_FEATURES`` respectively.
  500. Example for setting the info for a feature:
  501. .. code-block:: cmake
  502. option(WITH_FOO "Help for foo" ON)
  503. add_feature_info(Foo WITH_FOO "The Foo feature provides very cool stuff.")
  504. #]=======================================================================]
  505. function(ADD_FEATURE_INFO _name _depends _desc)
  506. set(_enabled 1)
  507. foreach(_d ${_depends})
  508. string(REGEX REPLACE " +" ";" _d "${_d}")
  509. if(${_d})
  510. else()
  511. set(_enabled 0)
  512. break()
  513. endif()
  514. endforeach()
  515. if (${_enabled})
  516. set_property(GLOBAL APPEND PROPERTY ENABLED_FEATURES "${_name}")
  517. else ()
  518. set_property(GLOBAL APPEND PROPERTY DISABLED_FEATURES "${_name}")
  519. endif ()
  520. set_property(GLOBAL PROPERTY _CMAKE_${_name}_DESCRIPTION "${_desc}" )
  521. endfunction()
  522. # The stuff below is only kept for compatibility
  523. #[=======================================================================[.rst:
  524. Legacy Macros
  525. ^^^^^^^^^^^^^
  526. The following macros are provided for compatibility with previous
  527. CMake versions:
  528. .. command:: set_package_info
  529. ::
  530. set_package_info(<name> <description> [ <url> [<purpose>] ])
  531. Use this macro to set up information about the named package, which
  532. can then be displayed via ``feature_summary()``. This can be done either
  533. directly in the Find-module or in the project which uses the module
  534. after the :command:`find_package` call. The features for which information
  535. can be set are added automatically by the ``find_package()`` command.
  536. #]=======================================================================]
  537. function(SET_PACKAGE_INFO _name _desc)
  538. message(DEPRECATION "SET_PACKAGE_INFO is deprecated. Use SET_PACKAGE_PROPERTIES instead.")
  539. unset(_url)
  540. unset(_purpose)
  541. if(ARGC GREATER 2)
  542. set(_url "${ARGV2}")
  543. endif()
  544. if(ARGC GREATER 3)
  545. set(_purpose "${ARGV3}")
  546. endif()
  547. set_property(GLOBAL PROPERTY _CMAKE_${_name}_DESCRIPTION "${_desc}" )
  548. if(NOT _url STREQUAL "")
  549. set_property(GLOBAL PROPERTY _CMAKE_${_name}_URL "${_url}" )
  550. endif()
  551. if(NOT _purpose STREQUAL "")
  552. set_property(GLOBAL APPEND PROPERTY _CMAKE_${_name}_PURPOSE "${_purpose}" )
  553. endif()
  554. endfunction()
  555. #[=======================================================================[.rst:
  556. .. command:: set_feature_info
  557. ::
  558. set_feature_info(<name> <description> [<url>])
  559. Does the same as::
  560. set_package_info(<name> <description> <url>)
  561. #]=======================================================================]
  562. function(SET_FEATURE_INFO)
  563. message(DEPRECATION "SET_FEATURE_INFO is deprecated. Use ADD_FEATURE_INFO instead.")
  564. SET_PACKAGE_INFO(${ARGN})
  565. endfunction()
  566. #[=======================================================================[.rst:
  567. .. command:: print_enabled_features
  568. ::
  569. print_enabled_features()
  570. Does the same as
  571. .. code-block:: cmake
  572. feature_summary(WHAT ENABLED_FEATURES DESCRIPTION "Enabled features:")
  573. #]=======================================================================]
  574. function(PRINT_ENABLED_FEATURES)
  575. message(DEPRECATION "PRINT_ENABLED_FEATURES is deprecated. Use
  576. feature_summary(WHAT ENABLED_FEATURES DESCRIPTION \"Enabled features:\")")
  577. FEATURE_SUMMARY(WHAT ENABLED_FEATURES DESCRIPTION "Enabled features:")
  578. endfunction()
  579. #[=======================================================================[.rst:
  580. .. command:: print_disabled_features
  581. ::
  582. print_disabled_features()
  583. Does the same as
  584. .. code-block:: cmake
  585. feature_summary(WHAT DISABLED_FEATURES DESCRIPTION "Disabled features:")
  586. #]=======================================================================]
  587. function(PRINT_DISABLED_FEATURES)
  588. message(DEPRECATION "PRINT_DISABLED_FEATURES is deprecated. Use
  589. feature_summary(WHAT DISABLED_FEATURES DESCRIPTION \"Disabled features:\")")
  590. FEATURE_SUMMARY(WHAT DISABLED_FEATURES DESCRIPTION "Disabled features:")
  591. endfunction()