FeatureSummary.cmake 28 KB

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