• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2019, 2020 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
5if(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
9endif()
10
11if(NOT BOOST_ENABLE_CMAKE)
12
13  message(FATAL_ERROR
14    "CMake support in Boost is experimental and part of an ongoing "
15    "development effort. It's not ready for use yet. Please use b2 "
16    "(Boost.Build) to build and install Boost.")
17
18endif()
19
20include(BoostMessage)
21include(BoostInstall)
22
23# --with-<library>
24set(BOOST_INCLUDE_LIBRARIES "" CACHE STRING "List of libraries to build (default: all but excluded and incompatible)")
25
26# --without-<library>
27set(BOOST_EXCLUDE_LIBRARIES "" CACHE STRING "List of libraries to exclude from build")
28
29set(BOOST_INCOMPATIBLE_LIBRARIES beast;callable_traits;compute;gil;hana;hof;safe_numerics;serialization;static_string;stl_interfaces;yap CACHE STRING "List of libraries with incompatible CMakeLists.txt files")
30
31# --layout, --libdir, --cmakedir, --includedir in BoostInstall
32
33# runtime-link=static|shared
34
35set(BOOST_RUNTIME_LINK shared CACHE STRING "Runtime library selection for the MS ABI (shared or static)")
36set_property(CACHE BOOST_RUNTIME_LINK PROPERTY STRINGS shared static)
37
38if(NOT CMAKE_MSVC_RUNTIME_LIBRARY)
39
40  set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
41
42  if(NOT BOOST_RUNTIME_LINK STREQUAL "static")
43    string(APPEND CMAKE_MSVC_RUNTIME_LIBRARY "DLL")
44  endif()
45
46endif()
47
48# Functions
49
50function(__boost_auto_install __boost_lib)
51  if(NOT CMAKE_VERSION VERSION_LESS 3.13)
52
53    string(MAKE_C_IDENTIFIER "${__boost_lib}" __boost_lib_target)
54
55    if(TARGET "Boost::${__boost_lib_target}" AND TARGET "boost_${__boost_lib_target}")
56
57      get_target_property(__boost_lib_incdir "boost_${__boost_lib_target}" INTERFACE_INCLUDE_DIRECTORIES)
58
59      if(__boost_lib_incdir STREQUAL "${BOOST_SUPERPROJECT_SOURCE_DIR}/libs/${__boost_lib}/include")
60
61        boost_message(DEBUG "Enabling installation for '${__boost_lib}'")
62        boost_install(TARGETS "boost_${__boost_lib_target}" VERSION "${BOOST_SUPERPROJECT_VERSION}" HEADER_DIRECTORY "${BOOST_SUPERPROJECT_SOURCE_DIR}/libs/${__boost_lib}/include")
63
64      else()
65        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'")
66      endif()
67
68    else()
69      boost_message(DEBUG "Not enabling installation for '${__boost_lib}'; targets 'Boost::${__boost_lib_target}' and 'boost_${__boost_lib_target}' weren't found")
70    endif()
71
72  endif()
73endfunction()
74
75function(__boost_scan_dependencies lib var)
76
77  file(STRINGS "${BOOST_SUPERPROJECT_SOURCE_DIR}/libs/${lib}/CMakeLists.txt" data)
78
79  set(result "")
80
81  foreach(line IN LISTS data)
82
83    if(line MATCHES "^[ ]*Boost::([A-Za-z0-9_]+)[ ]*$")
84
85      string(REGEX REPLACE "^numeric_" "numeric/" dep ${CMAKE_MATCH_1})
86      list(APPEND result ${dep})
87
88    endif()
89
90  endforeach()
91
92  set(${var} ${result} PARENT_SCOPE)
93
94endfunction()
95
96#
97
98if(CMAKE_SOURCE_DIR STREQUAL Boost_SOURCE_DIR)
99
100  include(CTest)
101  add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure -C $<CONFIG>)
102
103  # link=static|shared
104  option(BUILD_SHARED_LIBS "Build shared libraries")
105
106  # --stagedir
107  set(BOOST_STAGEDIR "${CMAKE_CURRENT_BINARY_DIR}/stage" CACHE STRING "Build output directory")
108
109  if(NOT CMAKE_RUNTIME_OUTPUT_DIRECTORY)
110    set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${BOOST_STAGEDIR}/bin")
111  endif()
112
113  if(NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY)
114    set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${BOOST_STAGEDIR}/lib")
115  endif()
116
117  if(NOT CMAKE_ARCHIVE_OUTPUT_DIRECTORY)
118    set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${BOOST_STAGEDIR}/lib")
119  endif()
120
121endif()
122
123file(GLOB __boost_libraries RELATIVE "${BOOST_SUPERPROJECT_SOURCE_DIR}/libs" "${BOOST_SUPERPROJECT_SOURCE_DIR}/libs/*/CMakeLists.txt" "${BOOST_SUPERPROJECT_SOURCE_DIR}/libs/numeric/*/CMakeLists.txt")
124
125# Check for mistakes in BOOST_INCLUDE_LIBRARIES
126
127foreach(__boost_included_lib IN LISTS BOOST_INCLUDE_LIBRARIES)
128
129  if(NOT "${__boost_included_lib}/CMakeLists.txt" IN_LIST __boost_libraries)
130
131    message(WARNING "Library '${__boost_included_lib}' given in BOOST_INCLUDE_LIBRARIES has not been found.")
132
133  endif()
134
135endforeach()
136
137# Scan for dependencies
138
139set(__boost_include_libraries ${BOOST_INCLUDE_LIBRARIES})
140
141if(__boost_include_libraries)
142  list(REMOVE_DUPLICATES __boost_include_libraries)
143endif()
144
145set(__boost_libs_to_scan ${__boost_include_libraries})
146
147while(__boost_libs_to_scan)
148
149  boost_message(DEBUG "Scanning dependencies: ${__boost_libs_to_scan}")
150
151  set(__boost_dependencies "")
152
153  foreach(__boost_lib IN LISTS __boost_libs_to_scan)
154
155    __boost_scan_dependencies(${__boost_lib} __boost_deps)
156    list(APPEND __boost_dependencies ${__boost_deps})
157
158  endforeach()
159
160  list(REMOVE_DUPLICATES __boost_dependencies)
161
162  set(__boost_libs_to_scan ${__boost_dependencies})
163
164  if(__boost_libs_to_scan)
165    list(REMOVE_ITEM __boost_libs_to_scan ${__boost_include_libraries})
166  endif()
167
168  list(APPEND __boost_include_libraries ${__boost_libs_to_scan})
169
170endwhile()
171
172# Installing targets created in other directories requires CMake 3.13
173if(CMAKE_VERSION VERSION_LESS 3.13)
174
175  boost_message(VERBOSE "Boost installation support is limited on CMake ${CMAKE_VERSION} (need 3.13)")
176
177endif()
178
179foreach(__boost_lib_cml IN LISTS __boost_libraries)
180
181  get_filename_component(__boost_lib "${__boost_lib_cml}" DIRECTORY)
182
183  if(__boost_lib IN_LIST BOOST_INCOMPATIBLE_LIBRARIES)
184
185    boost_message(DEBUG "Skipping incompatible Boost library ${__boost_lib}")
186
187  elseif(__boost_lib IN_LIST BOOST_EXCLUDE_LIBRARIES)
188
189    boost_message(DEBUG "Skipping excluded Boost library ${__boost_lib}")
190
191  elseif(NOT BOOST_INCLUDE_LIBRARIES OR __boost_lib IN_LIST BOOST_INCLUDE_LIBRARIES)
192
193    boost_message(VERBOSE "Adding Boost library ${__boost_lib}")
194    add_subdirectory(libs/${__boost_lib})
195
196    __boost_auto_install(${__boost_lib})
197
198  elseif(__boost_lib IN_LIST __boost_include_libraries)
199
200    set(BUILD_TESTING OFF) # hide cache variable
201
202    boost_message(VERBOSE "Adding dependent Boost library ${__boost_lib}")
203    add_subdirectory(libs/${__boost_lib})
204
205    __boost_auto_install(${__boost_lib})
206
207    unset(BUILD_TESTING)
208
209  else()
210
211    set(BUILD_TESTING OFF) # hide cache variable
212
213    boost_message(DEBUG "Adding Boost library ${__boost_lib} with EXCLUDE_FROM_ALL")
214    add_subdirectory(libs/${__boost_lib} EXCLUDE_FROM_ALL)
215
216    unset(BUILD_TESTING)
217
218  endif()
219
220endforeach()
221