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