BoostConfig.cmake 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. # Copyright 2019 Peter Dimov
  2. # Distributed under the Boost Software License, Version 1.0.
  3. # (See accompanying file LICENSE_1_0.txt or copy at http://boost.org/LICENSE_1_0.txt)
  4. # This CMake configuration file, installed as part of the Boost build
  5. # and installation procedure done by `b2 install`, provides support
  6. # for find_package(Boost).
  7. #
  8. # It's roughly, but not perfectly, compatible with the behavior
  9. # of find_package(Boost) as provided by FindBoost.cmake.
  10. #
  11. # A typical use might be
  12. #
  13. # find_package(Boost 1.70 REQUIRED COMPONENTS filesystem regex PATHS C:/Boost)
  14. #
  15. # On success, the above invocation would define the targets Boost::headers,
  16. # Boost::filesystem and Boost::regex. Boost::headers represents all
  17. # header-only libraries. An alias, Boost::boost, for Boost::headers is
  18. # provided for compatibility.
  19. #
  20. # Requesting the special component "ALL" will make all installed components
  21. # available, as in the following example:
  22. #
  23. # find_package(Boost 1.73 REQUIRED COMPONENTS ALL)
  24. #
  25. # Since COMPONENTS is optional when REQUIRED is specified, the above can be
  26. # shortened to
  27. #
  28. # find_package(Boost 1.73 REQUIRED ALL)
  29. #
  30. # When ALL is used, a variable Boost_ALL_TARGETS will be set and will contain
  31. # the names of all created targets.
  32. #
  33. # The ALL component cannot be combined with named components.
  34. #
  35. # Since Boost libraries can coexist in many variants - 32/64 bit,
  36. # static/dynamic runtime, debug/release, the following variables can be used
  37. # to control which variant is chosen:
  38. #
  39. # Boost_USE_DEBUG_LIBS: When OFF, disables debug libraries.
  40. # Boost_USE_RELEASE_LIBS: When OFF, disables release libraries.
  41. # Boost_USE_MULTITHREADED: When OFF, uses single-threaded libraries.
  42. # The default is multithreaded.
  43. # Boost_USE_STATIC_LIBS: When ON, uses static Boost libraries; when OFF,
  44. # uses shared Boost libraries; when not set, uses
  45. # static on Windows, shared otherwise.
  46. # Boost_USE_STATIC_RUNTIME: When ON, uses Boost libraries linked against the
  47. # static runtime. The default is shared runtime.
  48. # Boost_USE_DEBUG_RUNTIME: When ON, uses Boost libraries linked against the
  49. # debug runtime. When OFF, against the release
  50. # runtime. The default is to use either.
  51. # Boost_COMPILER: The compiler that has been used to build Boost,
  52. # such as vc141, gcc7, clang37. The default is
  53. # determined from CMAKE_CXX_COMPILER_ID.
  54. # Boost_PYTHON_VERSION: The version of Python against which Boost.Python
  55. # has been built; only required when more than one
  56. # Boost.Python library is present.
  57. #
  58. # The following variables control the verbosity of the output:
  59. #
  60. # Boost_VERBOSE: Enable verbose output
  61. # Boost_DEBUG: Enable debug (even more verbose) output
  62. if(Boost_VERBOSE OR Boost_DEBUG)
  63. message(STATUS "Found Boost ${Boost_VERSION} at ${Boost_DIR}")
  64. # Output requested configuration (f.ex. "REQUIRED COMPONENTS filesystem")
  65. if(Boost_FIND_QUIETLY)
  66. set(_BOOST_CONFIG "${_BOOST_CONFIG} QUIET")
  67. endif()
  68. if(Boost_FIND_REQUIRED)
  69. set(_BOOST_CONFIG "${_BOOST_CONFIG} REQUIRED")
  70. endif()
  71. foreach(__boost_comp IN LISTS Boost_FIND_COMPONENTS)
  72. if(${Boost_FIND_REQUIRED_${__boost_comp}})
  73. list(APPEND _BOOST_COMPONENTS ${__boost_comp})
  74. else()
  75. list(APPEND _BOOST_OPTIONAL_COMPONENTS ${__boost_comp})
  76. endif()
  77. endforeach()
  78. if(_BOOST_COMPONENTS)
  79. set(_BOOST_CONFIG "${_BOOST_CONFIG} COMPONENTS ${_BOOST_COMPONENTS}")
  80. endif()
  81. if(_BOOST_OPTIONAL_COMPONENTS)
  82. set(_BOOST_CONFIG "${_BOOST_CONFIG} OPTIONAL_COMPONENTS ${_BOOST_OPTIONAL_COMPONENTS}")
  83. endif()
  84. if(_BOOST_CONFIG)
  85. message(STATUS " Requested configuration:${_BOOST_CONFIG}")
  86. endif()
  87. unset(_BOOST_CONFIG)
  88. unset(_BOOST_COMPONENTS)
  89. unset(_BOOST_OPTIONAL_COMPONENTS)
  90. endif()
  91. macro(boost_find_component comp required quiet)
  92. set(_BOOST_QUIET)
  93. if(Boost_FIND_QUIETLY OR ${quiet})
  94. set(_BOOST_QUIET QUIET)
  95. endif()
  96. set(_BOOST_REQUIRED)
  97. if(${required} AND Boost_FIND_REQUIRED)
  98. set(_BOOST_REQUIRED REQUIRED)
  99. endif()
  100. if("${comp}" MATCHES "^(python|numpy|mpi_python)([1-9])([0-9])$")
  101. # handle pythonXY and numpyXY versioned components for compatibility
  102. set(Boost_PYTHON_VERSION "${CMAKE_MATCH_2}.${CMAKE_MATCH_3}")
  103. set(__boost_comp_nv "${CMAKE_MATCH_1}")
  104. elseif("${comp}" MATCHES "^(python|numpy|mpi_python)([1-9])$")
  105. # handle python2/python3 for compatibility
  106. set(Boost_PYTHON_VERSION_MAJOR "${CMAKE_MATCH_2}")
  107. set(__boost_comp_nv "${CMAKE_MATCH_1}")
  108. else()
  109. set(__boost_comp_nv "${comp}")
  110. endif()
  111. get_filename_component(_BOOST_CMAKEDIR "${CMAKE_CURRENT_LIST_DIR}/../" ABSOLUTE)
  112. if(Boost_DEBUG)
  113. message(STATUS "BoostConfig: find_package(boost_${__boost_comp_nv} ${Boost_VERSION} EXACT CONFIG ${_BOOST_REQUIRED} ${_BOOST_QUIET} HINTS ${_BOOST_CMAKEDIR})")
  114. endif()
  115. find_package(boost_${__boost_comp_nv} ${Boost_VERSION} EXACT CONFIG ${_BOOST_REQUIRED} ${_BOOST_QUIET} HINTS ${_BOOST_CMAKEDIR})
  116. set(__boost_comp_found ${boost_${__boost_comp_nv}_FOUND})
  117. # FindPackageHandleStandardArgs expects <package>_<component>_FOUND
  118. set(Boost_${comp}_FOUND ${__boost_comp_found})
  119. # FindBoost sets Boost_<COMPONENT>_FOUND
  120. string(TOUPPER ${comp} _BOOST_COMP)
  121. set(Boost_${_BOOST_COMP}_FOUND ${__boost_comp_found})
  122. # FindBoost compatibility variables: Boost_LIBRARIES, Boost_<C>_LIBRARY
  123. if(__boost_comp_found)
  124. list(APPEND Boost_LIBRARIES Boost::${__boost_comp_nv})
  125. set(Boost_${_BOOST_COMP}_LIBRARY Boost::${__boost_comp_nv})
  126. if(NOT "${comp}" STREQUAL "${__boost_comp_nv}" AND NOT TARGET Boost::${comp})
  127. # Versioned target alias (f.ex. Boost::python27) for compatibility
  128. add_library(Boost::${comp} INTERFACE IMPORTED)
  129. set_property(TARGET Boost::${comp} APPEND PROPERTY INTERFACE_LINK_LIBRARIES Boost::${__boost_comp_nv})
  130. endif()
  131. endif()
  132. unset(_BOOST_REQUIRED)
  133. unset(_BOOST_QUIET)
  134. unset(_BOOST_CMAKEDIR)
  135. unset(__boost_comp_nv)
  136. unset(__boost_comp_found)
  137. unset(_BOOST_COMP)
  138. endmacro()
  139. macro(boost_find_all_components)
  140. # Search for all available component-configuration directories...
  141. file(GLOB __boost_all_components
  142. LIST_DIRECTORIES true RELATIVE "${CMAKE_CURRENT_LIST_DIR}/.."
  143. "${CMAKE_CURRENT_LIST_DIR}/../boost_*-${Boost_VERSION}")
  144. # ...and extract component names from it.
  145. string(REGEX REPLACE "boost_([_a-z0-9]+)-${Boost_VERSION}" "\\1"
  146. __boost_all_components "${__boost_all_components}")
  147. if(Boost_DEBUG)
  148. message(STATUS "BoostConfig: discovered components: ${__boost_all_components}")
  149. endif()
  150. list(REMOVE_ITEM __boost_all_components "headers")
  151. # Try to find each component.
  152. foreach(__boost_comp IN LISTS __boost_all_components)
  153. boost_find_component(${__boost_comp} 0 1)
  154. # Append to list of all targets (if found).
  155. if(Boost_${__boost_comp}_FOUND)
  156. list(APPEND Boost_ALL_TARGETS Boost::${__boost_comp})
  157. endif()
  158. endforeach()
  159. unset(__boost_all_components)
  160. if(Boost_DEBUG)
  161. message(STATUS "BoostConfig: Boost_ALL_TARGETS: ${Boost_ALL_TARGETS}")
  162. endif()
  163. endmacro()
  164. # Find boost_headers
  165. boost_find_component(headers 1 0)
  166. if(NOT boost_headers_FOUND)
  167. set(Boost_FOUND 0)
  168. set(Boost_NOT_FOUND_MESSAGE "A required dependency, boost_headers, has not been found.")
  169. return()
  170. endif()
  171. # Compatibility variables
  172. set(Boost_MAJOR_VERSION ${Boost_VERSION_MAJOR})
  173. set(Boost_MINOR_VERSION ${Boost_VERSION_MINOR})
  174. set(Boost_SUBMINOR_VERSION ${Boost_VERSION_PATCH})
  175. set(Boost_VERSION_STRING ${Boost_VERSION})
  176. set(Boost_VERSION_MACRO ${Boost_VERSION_MAJOR}0${Boost_VERSION_MINOR}0${Boost_VERSION_PATCH})
  177. get_target_property(Boost_INCLUDE_DIRS Boost::headers INTERFACE_INCLUDE_DIRECTORIES)
  178. set(Boost_LIBRARIES "")
  179. # Find components
  180. if("ALL" IN_LIST Boost_FIND_COMPONENTS)
  181. # Make sure "ALL" is the only requested component.
  182. list(LENGTH Boost_FIND_COMPONENTS __boost_find_components_count)
  183. if(NOT ${__boost_find_components_count} EQUAL 1)
  184. message(AUTHOR_WARNING "ALL cannot be combined with named components; the named components will be ignored.")
  185. endif()
  186. unset(__boost_find_components_count)
  187. set(Boost_ALL_TARGETS Boost::headers)
  188. boost_find_all_components()
  189. else()
  190. foreach(__boost_comp IN LISTS Boost_FIND_COMPONENTS)
  191. boost_find_component(${__boost_comp} ${Boost_FIND_REQUIRED_${__boost_comp}} 0)
  192. endforeach()
  193. endif()
  194. # Compatibility targets
  195. if(NOT TARGET Boost::boost)
  196. add_library(Boost::boost INTERFACE IMPORTED)
  197. set_property(TARGET Boost::boost APPEND PROPERTY INTERFACE_LINK_LIBRARIES Boost::headers)
  198. # All Boost:: targets already disable autolink
  199. add_library(Boost::diagnostic_definitions INTERFACE IMPORTED)
  200. add_library(Boost::disable_autolinking INTERFACE IMPORTED)
  201. add_library(Boost::dynamic_linking INTERFACE IMPORTED)
  202. endif()
  203. # Compatibility variable when using meta-component "ALL"
  204. if("ALL" IN_LIST Boost_FIND_COMPONENTS)
  205. set(Boost_ALL_FOUND ${boost_headers_FOUND})
  206. endif()