BoostConfig.cmake 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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. # Since Boost libraries can coexist in many variants - 32/64 bit,
  21. # static/dynamic runtime, debug/release, the following variables can be used
  22. # to control which variant is chosen:
  23. #
  24. # Boost_USE_DEBUG_LIBS: When OFF, disables debug libraries.
  25. # Boost_USE_RELEASE_LIBS: When OFF, disables release libraries.
  26. # Boost_USE_MULTITHREADED: When ON, uses multithreaded Boost libraries.
  27. # When OFF, uses single-threaded libraries.
  28. # The default is to use either.
  29. # Boost_USE_STATIC_LIBS: When ON, uses static Boost libraries; when OFF,
  30. # uses shared Boost libraries; when not set, uses
  31. # static on Windows, shared otherwise.
  32. # Boost_USE_STATIC_RUNTIME: When ON, uses Boost libraries linked against the
  33. # static runtime. The default is shared runtime.
  34. # Boost_USE_DEBUG_RUNTIME: When ON, uses Boost libraries linked against the
  35. # debug runtime. When OFF, against the release
  36. # runtime. The default is to use either.
  37. # Boost_COMPILER: The compiler that has been used to build Boost,
  38. # such as vc141, gcc7, clang37. The default is
  39. # determined from CMAKE_CXX_COMPILER_ID.
  40. # Boost_PYTHON_VERSION: The version of Python against which Boost.Python
  41. # has been built; only required when more than one
  42. # Boost.Python library is present.
  43. #
  44. # The following variables control the verbosity of the output:
  45. #
  46. # Boost_VERBOSE: Enable verbose output
  47. # Boost_DEBUG: Enable debug (even more verbose) output
  48. if(Boost_VERBOSE OR Boost_DEBUG)
  49. message(STATUS "Found Boost ${Boost_VERSION} at ${Boost_DIR}")
  50. # Output requested configuration (f.ex. "REQUIRED COMPONENTS filesystem")
  51. if(Boost_FIND_QUIETLY)
  52. set(_BOOST_CONFIG "${_BOOST_CONFIG} QUIET")
  53. endif()
  54. if(Boost_FIND_REQUIRED)
  55. set(_BOOST_CONFIG "${_BOOST_CONFIG} REQUIRED")
  56. endif()
  57. foreach(__boost_comp IN LISTS Boost_FIND_COMPONENTS)
  58. if(${Boost_FIND_REQUIRED_${__boost_comp}})
  59. list(APPEND _BOOST_COMPONENTS ${__boost_comp})
  60. else()
  61. list(APPEND _BOOST_OPTIONAL_COMPONENTS ${__boost_comp})
  62. endif()
  63. endforeach()
  64. if(_BOOST_COMPONENTS)
  65. set(_BOOST_CONFIG "${_BOOST_CONFIG} COMPONENTS ${_BOOST_COMPONENTS}")
  66. endif()
  67. if(_BOOST_OPTIONAL_COMPONENTS)
  68. set(_BOOST_CONFIG "${_BOOST_CONFIG} OPTIONAL_COMPONENTS ${_BOOST_OPTIONAL_COMPONENTS}")
  69. endif()
  70. if(_BOOST_CONFIG)
  71. message(STATUS " Requested configuration:${_BOOST_CONFIG}")
  72. endif()
  73. unset(_BOOST_CONFIG)
  74. unset(_BOOST_COMPONENTS)
  75. unset(_BOOST_OPTIONAL_COMPONENTS)
  76. endif()
  77. macro(boost_find_component comp req)
  78. set(_BOOST_QUIET)
  79. if(Boost_FIND_QUIETLY)
  80. set(_BOOST_QUIET QUIET)
  81. endif()
  82. set(_BOOST_REQUIRED)
  83. if(${req} AND Boost_FIND_REQUIRED)
  84. set(_BOOST_REQUIRED REQUIRED)
  85. endif()
  86. if("${comp}" MATCHES "^(python|numpy|mpi_python)([1-9])([0-9])$")
  87. # handle pythonXY and numpyXY versioned components for compatibility
  88. set(Boost_PYTHON_VERSION "${CMAKE_MATCH_2}.${CMAKE_MATCH_3}")
  89. set(__boost_comp_nv "${CMAKE_MATCH_1}")
  90. else()
  91. set(__boost_comp_nv "${comp}")
  92. endif()
  93. get_filename_component(_BOOST_CMAKEDIR "${CMAKE_CURRENT_LIST_DIR}/../" ABSOLUTE)
  94. if(Boost_DEBUG)
  95. message(STATUS "BoostConfig: find_package(boost_${__boost_comp_nv} ${Boost_VERSION} EXACT CONFIG ${_BOOST_REQUIRED} ${_BOOST_QUIET} HINTS ${_BOOST_CMAKEDIR})")
  96. endif()
  97. find_package(boost_${__boost_comp_nv} ${Boost_VERSION} EXACT CONFIG ${_BOOST_REQUIRED} ${_BOOST_QUIET} HINTS ${_BOOST_CMAKEDIR})
  98. set(__boost_comp_found ${boost_${__boost_comp_nv}_FOUND})
  99. # FindPackageHandleStandardArgs expects <package>_<component>_FOUND
  100. set(Boost_${comp}_FOUND ${__boost_comp_found})
  101. # FindBoost sets Boost_<COMPONENT>_FOUND
  102. string(TOUPPER ${comp} _BOOST_COMP)
  103. set(Boost_${_BOOST_COMP}_FOUND ${__boost_comp_found})
  104. # FindBoost compatibility variables: Boost_LIBRARIES, Boost_<C>_LIBRARY
  105. if(__boost_comp_found)
  106. list(APPEND Boost_LIBRARIES Boost::${__boost_comp_nv})
  107. set(Boost_${_BOOST_COMP}_LIBRARY Boost::${__boost_comp_nv})
  108. if(NOT "${comp}" STREQUAL "${__boost_comp_nv}" AND NOT TARGET Boost::${comp})
  109. # Versioned target alias (f.ex. Boost::python27) for compatibility
  110. add_library(Boost::${comp} INTERFACE IMPORTED)
  111. set_property(TARGET Boost::${comp} APPEND PROPERTY INTERFACE_LINK_LIBRARIES Boost::${__boost_comp_nv})
  112. endif()
  113. endif()
  114. unset(_BOOST_REQUIRED)
  115. unset(_BOOST_QUIET)
  116. unset(_BOOST_CMAKEDIR)
  117. unset(__boost_comp_nv)
  118. unset(__boost_comp_found)
  119. unset(_BOOST_COMP)
  120. endmacro()
  121. # Find boost_headers
  122. boost_find_component(headers 1)
  123. if(NOT boost_headers_FOUND)
  124. set(Boost_FOUND 0)
  125. set(Boost_NOT_FOUND_MESSAGE "A required dependency, boost_headers, has not been found.")
  126. return()
  127. endif()
  128. # Compatibility variables
  129. set(Boost_MAJOR_VERSION ${Boost_VERSION_MAJOR})
  130. set(Boost_MINOR_VERSION ${Boost_VERSION_MINOR})
  131. set(Boost_SUBMINOR_VERSION ${Boost_VERSION_PATCH})
  132. set(Boost_VERSION_STRING ${Boost_VERSION})
  133. set(Boost_VERSION_MACRO ${Boost_VERSION_MAJOR}0${Boost_VERSION_MINOR}0${Boost_VERSION_PATCH})
  134. get_target_property(Boost_INCLUDE_DIRS Boost::headers INTERFACE_INCLUDE_DIRECTORIES)
  135. set(Boost_LIBRARIES "")
  136. # Find components
  137. foreach(__boost_comp IN LISTS Boost_FIND_COMPONENTS)
  138. boost_find_component(${__boost_comp} ${Boost_FIND_REQUIRED_${__boost_comp}})
  139. endforeach()
  140. # Compatibility targets
  141. if(NOT TARGET Boost::boost)
  142. add_library(Boost::boost INTERFACE IMPORTED)
  143. set_property(TARGET Boost::boost APPEND PROPERTY INTERFACE_LINK_LIBRARIES Boost::headers)
  144. # All Boost:: targets already disable autolink
  145. add_library(Boost::diagnostic_definitions INTERFACE IMPORTED)
  146. add_library(Boost::disable_autolinking INTERFACE IMPORTED)
  147. add_library(Boost::dynamic_linking INTERFACE IMPORTED)
  148. endif()