FeatureSummary.cmake 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. # - Macros for generating a summary of enabled/disabled features
  2. #
  3. # FEATURE_SUMMARY( [FILENAME <file>]
  4. # [APPEND]
  5. # [VAR <variable_name>]
  6. # [DESCRIPTION "Found packages:"]
  7. # WHAT (ALL | PACKAGES_FOUND | PACKAGES_NOT_FOUND | ENABLED_FEATURES | DISABLED_FEATURES]
  8. # )
  9. #
  10. # The FEATURE_SUMMARY() macro can be used to print information about enabled
  11. # or disabled features or packages of a project.
  12. # By default, only the names of the features/packages will be printed and their
  13. # required version when one was specified. Use SET_FEATURE_INFO() to add more
  14. # useful information, like e.g. a download URL for the respective package.
  15. #
  16. # The WHAT option is the only mandatory option. Here you specify what information
  17. # will be printed:
  18. # ENABLED_FEATURES: the list of all features and packages which have been found, excluding the QUIET ones
  19. # DISABLED_FEATURES: the list of all features and packages which have not been found, excluding the QUIET ones
  20. # PACKAGES_FOUND: the list of all packages which have been found, including the QUIET ones
  21. # PACKAGES_NOT_FOUND: the list of all packages which have not been found, including the QUIET ones
  22. # ALL: this will give all packages which have or have not been found
  23. #
  24. # If a FILENAME is given, the information is printed into this file. If APPEND
  25. # is used, it is appended to this file, otherwise the file is overwritten if
  26. # it already existed.
  27. # If the VAR option is used, the information is "printed" into the specified
  28. # variable.
  29. # If FILENAME is not used, the information is printed to the terminal.
  30. # Using the DESCRIPTION option a description or headline can be set which will
  31. # be printed above the actual content.
  32. #
  33. # Example 1, append everything to a file:
  34. # FEATURE_SUMMARY(WHAT ALL
  35. # FILENAME ${CMAKE_BINARY_DIR}/all.log APPEND)
  36. #
  37. # Example 2, print the enabled features into the variable enabledFeaturesText:
  38. # FEATURE_SUMMARY(WHAT ENABLED_FEATURES
  39. # DESCRIPTION "Enabled Features:"
  40. # VAR enabledFeaturesText)
  41. # MESSAGE(STATUS "${enabledFeaturesText}")
  42. #
  43. #
  44. #
  45. # SET_FEATURE_INFO(NAME DESCRIPTION [URL [COMMENT] ] )
  46. # Use this macro to set up information about the named feature, which can
  47. # then be displayed via FEATURE_SUMMARY() or PRINT_ENABLED/DISABLED_FEATURES().
  48. # This can be done either directly in the Find-module or in the project
  49. # which uses the module after the FIND_PACKAGE() call.
  50. # The features for which information can be set are added automatically by the
  51. # find_package() command. If you want to add additional features, you can add
  52. # them by appending them to the global ENABLED_FEATURES or DISABLED_FEATURES properties.
  53. #
  54. # Example for setting the info for a package:
  55. # FIND_PACKAGE(LibXml2)
  56. # SET_FEATURE_INFO(LibXml2 "XML processing library." "http://xmlsoft.org/")
  57. #
  58. #
  59. # PRINT_ENABLED_FEATURES()
  60. # Does the same as FEATURE_SUMMARY(WHAT ENABLED_FEATURES DESCRIPTION "Enabled features:")
  61. #
  62. #
  63. # PRINT_DISABLED_FEATURES()
  64. # Does the same as FEATURE_SUMMARY(WHAT DISABLED_FEATURES DESCRIPTION "Disabled features:")
  65. #=============================================================================
  66. # Copyright 2007-2009 Kitware, Inc.
  67. #
  68. # Distributed under the OSI-approved BSD License (the "License");
  69. # see accompanying file Copyright.txt for details.
  70. #
  71. # This software is distributed WITHOUT ANY WARRANTY; without even the
  72. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  73. # See the License for more information.
  74. #=============================================================================
  75. # (To distribute this file outside of CMake, substitute the full
  76. # License text for the above reference.)
  77. INCLUDE(CMakeParseArguments)
  78. FUNCTION(SET_FEATURE_INFO _name _desc)
  79. SET(_url "${ARGV2}")
  80. SET(_comment "${ARGV3}")
  81. SET_PROPERTY(GLOBAL PROPERTY _CMAKE_${_name}_DESCRIPTION "${_desc}" )
  82. IF(_url MATCHES ".+")
  83. SET_PROPERTY(GLOBAL PROPERTY _CMAKE_${_name}_URL "${_url}" )
  84. ENDIF(_url MATCHES ".+")
  85. IF(_comment MATCHES ".+")
  86. SET_PROPERTY(GLOBAL PROPERTY _CMAKE_${_name}_COMMENT "${_comment}" )
  87. ENDIF(_comment MATCHES ".+")
  88. ENDFUNCTION(SET_FEATURE_INFO)
  89. FUNCTION(_FS_GET_FEATURE_SUMMARY _property _var)
  90. SET(_currentFeatureText "")
  91. GET_PROPERTY(_EnabledFeatures GLOBAL PROPERTY ${_property})
  92. FOREACH(_currentFeature ${_EnabledFeatures})
  93. SET(_currentFeatureText "${_currentFeatureText}\n${_currentFeature}")
  94. GET_PROPERTY(_info GLOBAL PROPERTY _CMAKE_${_currentFeature}_REQUIRED_VERSION)
  95. IF(_info)
  96. SET(_currentFeatureText "${_currentFeatureText} (required version ${_info})")
  97. ENDIF(_info)
  98. GET_PROPERTY(_info GLOBAL PROPERTY _CMAKE_${_currentFeature}_DESCRIPTION)
  99. IF(_info)
  100. SET(_currentFeatureText "${_currentFeatureText} , ${_info}")
  101. ENDIF(_info)
  102. GET_PROPERTY(_info GLOBAL PROPERTY _CMAKE_${_currentFeature}_URL)
  103. IF(_info)
  104. SET(_currentFeatureText "${_currentFeatureText} , <${_info}>")
  105. ENDIF(_info)
  106. GET_PROPERTY(_info GLOBAL PROPERTY _CMAKE_${_currentFeature}_COMMENT)
  107. IF(_info)
  108. SET(_currentFeatureText "${_currentFeatureText} , ${_info}")
  109. ENDIF(_info)
  110. ENDFOREACH(_currentFeature)
  111. SET(${_var} "${_currentFeatureText}" PARENT_SCOPE)
  112. ENDFUNCTION(_FS_GET_FEATURE_SUMMARY)
  113. FUNCTION(PRINT_ENABLED_FEATURES)
  114. FEATURE_SUMMARY(WHAT ENABLED_FEATURES DESCRIPTION "Enabled features:")
  115. ENDFUNCTION(PRINT_ENABLED_FEATURES)
  116. FUNCTION(PRINT_DISABLED_FEATURES)
  117. FEATURE_SUMMARY(WHAT DISABLED_FEATURES DESCRIPTION "Disabled features:")
  118. ENDFUNCTION(PRINT_DISABLED_FEATURES)
  119. FUNCTION(FEATURE_SUMMARY)
  120. # CMAKE_PARSE_ARGUMENTS(<prefix> <options> <one_value_keywords> <multi_value_keywords> args...)
  121. SET(options APPEND)
  122. SET(oneValueArgs FILENAME VAR DESCRIPTION WHAT)
  123. SET(multiValueArgs ) # none
  124. CMAKE_PARSE_ARGUMENTS(_FS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${_FIRST_ARG} ${ARGN})
  125. IF(_FS_UNPARSED_ARGUMENTS)
  126. MESSAGE(FATAL_ERROR "Unknown keywords given to FEATURE_SUMMARY(): \"${_FS_UNPARSED_ARGUMENTS}\"")
  127. ENDIF(_FS_UNPARSED_ARGUMENTS)
  128. IF(NOT _FS_WHAT)
  129. MESSAGE(FATAL_ERROR "The call to FEATURE_SUMMAY() doesn't set the required WHAT argument.")
  130. ENDIF(NOT _FS_WHAT)
  131. IF( "${_FS_WHAT}" STREQUAL "ENABLED_FEATURES"
  132. OR "${_FS_WHAT}" STREQUAL "DISABLED_FEATURES"
  133. OR "${_FS_WHAT}" STREQUAL "PACKAGES_FOUND"
  134. OR "${_FS_WHAT}" STREQUAL "PACKAGES_NOT_FOUND")
  135. _FS_GET_FEATURE_SUMMARY( ${_FS_WHAT} _featureSummary)
  136. ELSEIF("${_FS_WHAT}" STREQUAL "ALL")
  137. _FS_GET_FEATURE_SUMMARY( PACKAGES_FOUND _tmp1)
  138. _FS_GET_FEATURE_SUMMARY( PACKAGES_NOT_FOUND _tmp2)
  139. SET(_featureSummary "${_tmp1}${_tmp2}")
  140. ELSE()
  141. MESSAGE(FATAL_ERROR "The WHAT argument of FEATURE_SUMMARY() is set to ${_FS_WHAT}, which is not a valid value.")
  142. ENDIF()
  143. SET(_fullText "${_FS_DESCRIPTION}${_featureSummary}\n")
  144. IF(_FS_FILENAME)
  145. IF(_FS_APPEND)
  146. FILE(WRITE "${_FS_FILENAME}" "${_fullText}")
  147. ELSE(_FS_APPEND)
  148. FILE(APPEND "${_FS_FILENAME}" "${_fullText}")
  149. ENDIF(_FS_APPEND)
  150. ELSE(_FS_FILENAME)
  151. IF(NOT _FS_VAR)
  152. MESSAGE(STATUS "${_fullText}")
  153. ENDIF(NOT _FS_VAR)
  154. ENDIF(_FS_FILENAME)
  155. IF(_FS_VAR)
  156. SET(${_FS_VAR} "${_fullText}" PARENT_SCOPE)
  157. ENDIF(_FS_VAR)
  158. ENDFUNCTION(FEATURE_SUMMARY)