]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/tools/cmake/include/BoostRoot.cmake
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / tools / cmake / include / BoostRoot.cmake
1 # Copyright 2019-2021 Peter Dimov
2 # Distributed under the Boost Software License, Version 1.0.
3 # See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt
4
5 if(CMAKE_SOURCE_DIR STREQUAL Boost_SOURCE_DIR AND WIN32 AND CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
6
7 set(CMAKE_INSTALL_PREFIX "C:/Boost" CACHE PATH "Installation path prefix, prepended to installation directories" FORCE)
8
9 endif()
10
11 include(BoostMessage)
12 include(BoostInstall)
13
14 #
15
16 set(__boost_incompatible_libraries
17 gil
18 )
19
20 # Define cache variables if root project
21
22 if(CMAKE_SOURCE_DIR STREQUAL Boost_SOURCE_DIR)
23
24 # --with-<library>
25 set(BOOST_INCLUDE_LIBRARIES "" CACHE STRING
26 "List of libraries to build (default: all but excluded and incompatible)")
27
28 # --without-<library>
29 set(BOOST_EXCLUDE_LIBRARIES "" CACHE STRING
30 "List of libraries to exclude from build")
31
32 set(BOOST_INCOMPATIBLE_LIBRARIES
33 "${__boost_incompatible_libraries}"
34 CACHE STRING
35 "List of libraries with incompatible CMakeLists.txt files")
36
37 option(BOOST_ENABLE_MPI
38 "Build and enable installation of Boost.MPI and its dependents (requires MPI, CMake 3.9)")
39
40 option(BOOST_ENABLE_PYTHON
41 "Build and enable installation of Boost.Python and its dependents (requires Python, CMake 3.14)")
42
43 # --layout, --libdir, --cmakedir, --includedir in BoostInstall
44
45 # runtime-link=static|shared
46
47 set(BOOST_RUNTIME_LINK shared CACHE STRING "Runtime library selection for the MS ABI (shared or static)")
48 set_property(CACHE BOOST_RUNTIME_LINK PROPERTY STRINGS shared static)
49
50 option(BUILD_TESTING "Build the tests." OFF)
51 include(CTest)
52 add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure -C $<CONFIG>)
53
54 # link=static|shared
55 option(BUILD_SHARED_LIBS "Build shared libraries")
56
57 # --stagedir
58 set(BOOST_STAGEDIR "${CMAKE_CURRENT_BINARY_DIR}/stage" CACHE STRING "Build output directory")
59
60 if(NOT CMAKE_RUNTIME_OUTPUT_DIRECTORY)
61 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${BOOST_STAGEDIR}/bin")
62 endif()
63
64 if(NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY)
65 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${BOOST_STAGEDIR}/lib")
66 endif()
67
68 if(NOT CMAKE_ARCHIVE_OUTPUT_DIRECTORY)
69 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${BOOST_STAGEDIR}/lib")
70 endif()
71
72 else()
73
74 # add_subdirectory use
75
76 if(NOT DEFINED BOOST_INCOMPATIBLE_LIBRARIES)
77 set(BOOST_INCOMPATIBLE_LIBRARIES ${__boost_incompatible_libraries})
78 endif()
79
80 if(NOT DEFINED BOOST_ENABLE_MPI)
81 set(BOOST_ENABLE_MPI OFF)
82 endif()
83
84 if(NOT DEFINED BOOST_ENABLE_PYTHON)
85 set(BOOST_ENABLE_PYTHON OFF)
86 endif()
87
88 set(BUILD_TESTING OFF)
89 set(CMAKE_SKIP_INSTALL_RULES ON)
90
91 endif()
92
93 if(NOT CMAKE_MSVC_RUNTIME_LIBRARY)
94
95 set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
96
97 if(NOT BOOST_RUNTIME_LINK STREQUAL "static")
98 string(APPEND CMAKE_MSVC_RUNTIME_LIBRARY "DLL")
99 endif()
100
101 endif()
102
103 # Output configuration status lines
104
105 set(_msg "")
106
107 if(NOT CMAKE_CONFIGURATION_TYPES AND CMAKE_BUILD_TYPE)
108 string(APPEND _msg "${CMAKE_BUILD_TYPE} build, ")
109 endif()
110
111 if(BUILD_SHARED_LIBS)
112 string(APPEND _msg "shared libraries, ")
113 else()
114 string(APPEND _msg "static libraries, ")
115 endif()
116
117 if(MSVC)
118 if(CMAKE_MSVC_RUNTIME_LIBRARY STREQUAL "MultiThreaded$<$<CONFIG:Debug>:Debug>")
119 string(APPEND _msg "static runtime, ")
120 elseif(CMAKE_MSVC_RUNTIME_LIBRARY STREQUAL "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
121 string(APPEND _msg "shared runtime, ")
122 endif()
123 endif()
124
125 string(APPEND _msg "MPI ${BOOST_ENABLE_MPI}, Python ${BOOST_ENABLE_PYTHON}, testing ${BUILD_TESTING}")
126
127 message(STATUS "Boost: ${_msg}")
128
129 unset(_msg)
130
131 if(BOOST_INCLUDE_LIBRARIES)
132 message(STATUS "Boost: libraries included: ${BOOST_INCLUDE_LIBRARIES}")
133 endif()
134
135 if(BOOST_EXCLUDE_LIBRARIES)
136 message(STATUS "Boost: libraries excluded: ${BOOST_EXCLUDE_LIBRARIES}")
137 endif()
138
139 # Define functions
140
141 function(__boost_auto_install __boost_lib)
142 if(NOT CMAKE_VERSION VERSION_LESS 3.13)
143
144 string(MAKE_C_IDENTIFIER "${__boost_lib}" __boost_lib_target)
145
146 if(TARGET "Boost::${__boost_lib_target}" AND TARGET "boost_${__boost_lib_target}")
147
148 get_target_property(__boost_lib_incdir "boost_${__boost_lib_target}" INTERFACE_INCLUDE_DIRECTORIES)
149
150 if(__boost_lib_incdir STREQUAL "${BOOST_SUPERPROJECT_SOURCE_DIR}/libs/${__boost_lib}/include")
151
152 boost_message(DEBUG "Enabling installation for '${__boost_lib}'")
153 boost_install(TARGETS "boost_${__boost_lib_target}" VERSION "${BOOST_SUPERPROJECT_VERSION}" HEADER_DIRECTORY "${BOOST_SUPERPROJECT_SOURCE_DIR}/libs/${__boost_lib}/include")
154
155 else()
156 boost_message(DEBUG "Not enabling installation for '${__boost_lib}'; interface include directory '${__boost_lib_incdir}' does not equal '${BOOST_SUPERPROJECT_SOURCE_DIR}/libs/${__boost_lib}/include'")
157 endif()
158
159 else()
160 boost_message(DEBUG "Not enabling installation for '${__boost_lib}'; targets 'Boost::${__boost_lib_target}' and 'boost_${__boost_lib_target}' weren't found")
161 endif()
162
163 endif()
164 endfunction()
165
166 function(__boost_scan_dependencies lib var)
167
168 set(result "")
169
170 if(EXISTS "${BOOST_SUPERPROJECT_SOURCE_DIR}/libs/${lib}/CMakeLists.txt")
171
172 file(STRINGS "${BOOST_SUPERPROJECT_SOURCE_DIR}/libs/${lib}/CMakeLists.txt" data)
173
174 foreach(line IN LISTS data)
175
176 if(line MATCHES "^[ ]*Boost::([A-Za-z0-9_]+)[ ]*$")
177
178 string(REGEX REPLACE "^numeric_" "numeric/" dep ${CMAKE_MATCH_1})
179 list(APPEND result ${dep})
180
181 endif()
182
183 endforeach()
184
185 endif()
186
187 set(${var} ${result} PARENT_SCOPE)
188
189 endfunction()
190
191 #
192
193 file(GLOB __boost_libraries RELATIVE "${BOOST_SUPERPROJECT_SOURCE_DIR}/libs" "${BOOST_SUPERPROJECT_SOURCE_DIR}/libs/*/CMakeLists.txt" "${BOOST_SUPERPROJECT_SOURCE_DIR}/libs/numeric/*/CMakeLists.txt")
194
195 # Check for mistakes in BOOST_INCLUDE_LIBRARIES
196
197 foreach(__boost_included_lib IN LISTS BOOST_INCLUDE_LIBRARIES)
198
199 if(NOT "${__boost_included_lib}/CMakeLists.txt" IN_LIST __boost_libraries)
200
201 message(WARNING "Library '${__boost_included_lib}' given in BOOST_INCLUDE_LIBRARIES has not been found.")
202
203 endif()
204
205 endforeach()
206
207 # Scan for dependencies
208
209 set(__boost_include_libraries ${BOOST_INCLUDE_LIBRARIES})
210
211 if(__boost_include_libraries)
212 list(REMOVE_DUPLICATES __boost_include_libraries)
213 endif()
214
215 set(__boost_libs_to_scan ${__boost_include_libraries})
216
217 while(__boost_libs_to_scan)
218
219 boost_message(DEBUG "Scanning dependencies: ${__boost_libs_to_scan}")
220
221 set(__boost_dependencies "")
222
223 foreach(__boost_lib IN LISTS __boost_libs_to_scan)
224
225 __boost_scan_dependencies(${__boost_lib} __boost_deps)
226 list(APPEND __boost_dependencies ${__boost_deps})
227
228 endforeach()
229
230 list(REMOVE_DUPLICATES __boost_dependencies)
231
232 set(__boost_libs_to_scan ${__boost_dependencies})
233
234 if(__boost_libs_to_scan)
235 list(REMOVE_ITEM __boost_libs_to_scan ${__boost_include_libraries})
236 endif()
237
238 list(APPEND __boost_include_libraries ${__boost_libs_to_scan})
239
240 endwhile()
241
242 # Installing targets created in other directories requires CMake 3.13
243 if(CMAKE_VERSION VERSION_LESS 3.13)
244
245 boost_message(STATUS "Boost installation support requires CMake 3.13 (have ${CMAKE_VERSION})")
246
247 endif()
248
249 set(__boost_mpi_libs mpi graph_parallel property_map_parallel)
250 set(__boost_python_libs python parameter_python)
251
252 foreach(__boost_lib_cml IN LISTS __boost_libraries)
253
254 get_filename_component(__boost_lib "${__boost_lib_cml}" DIRECTORY)
255
256 if(__boost_lib IN_LIST BOOST_INCOMPATIBLE_LIBRARIES)
257
258 boost_message(DEBUG "Skipping incompatible Boost library ${__boost_lib}")
259
260 elseif(__boost_lib IN_LIST BOOST_EXCLUDE_LIBRARIES)
261
262 boost_message(DEBUG "Skipping excluded Boost library ${__boost_lib}")
263
264 elseif(NOT BOOST_ENABLE_MPI AND __boost_lib IN_LIST __boost_mpi_libs)
265
266 boost_message(DEBUG "Skipping Boost library ${__boost_lib}, BOOST_ENABLE_MPI is OFF")
267
268 elseif(NOT BOOST_ENABLE_PYTHON AND __boost_lib IN_LIST __boost_python_libs)
269
270 boost_message(DEBUG "Skipping Boost library ${__boost_lib}, BOOST_ENABLE_PYTHON is OFF")
271
272 elseif(NOT BOOST_INCLUDE_LIBRARIES OR __boost_lib IN_LIST BOOST_INCLUDE_LIBRARIES)
273
274 boost_message(VERBOSE "Adding Boost library ${__boost_lib}")
275 add_subdirectory(libs/${__boost_lib})
276
277 __boost_auto_install(${__boost_lib})
278
279 elseif(__boost_lib IN_LIST __boost_include_libraries)
280
281 # Disable tests for dependencies
282
283 set(__boost_build_testing ${BUILD_TESTING})
284 set(BUILD_TESTING OFF) # hide cache variable
285
286 boost_message(VERBOSE "Adding Boost dependency ${__boost_lib}")
287 add_subdirectory(libs/${__boost_lib})
288
289 __boost_auto_install(${__boost_lib})
290
291 set(BUILD_TESTING ${__boost_build_testing})
292
293 elseif(BUILD_TESTING)
294
295 # Disable tests and installation for libraries neither included nor dependencies
296
297 set(__boost_build_testing ${BUILD_TESTING})
298 set(BUILD_TESTING OFF) # hide cache variable
299
300 set(__boost_skip_install ${CMAKE_SKIP_INSTALL_RULES})
301 set(CMAKE_SKIP_INSTALL_RULES ON)
302
303 boost_message(DEBUG "Adding Boost library ${__boost_lib} with EXCLUDE_FROM_ALL")
304 add_subdirectory(libs/${__boost_lib} EXCLUDE_FROM_ALL)
305
306 set(BUILD_TESTING ${__boost_build_testing})
307 set(CMAKE_SKIP_INSTALL_RULES ${__boost_skip_install})
308
309 endif()
310
311 endforeach()