-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
238 lines (215 loc) · 9.2 KB
/
Copy pathCMakeLists.txt
File metadata and controls
238 lines (215 loc) · 9.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
#
# Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
# Copyright (c) 2021 Dmitry Arkhipov (grisumbras@gmail.com)
# Copyright (c) 2022 Alan de Freitas (alandefreitas@gmail.com)
# Copyright (c) 2025 Mohammad Nejati
#
# Distributed under the Boost Software License, Version 1.0. (See accompanying
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#
# Official repository: https://github.com/cppalliance/capy
#
#-------------------------------------------------
#
# Project
#
#-------------------------------------------------
cmake_minimum_required(VERSION 3.8...3.20)
set(BOOST_CAPY_VERSION 1)
if (BOOST_SUPERPROJECT_VERSION)
set(BOOST_CAPY_VERSION ${BOOST_SUPERPROJECT_VERSION})
endif ()
project(boost_capy VERSION "${BOOST_CAPY_VERSION}" LANGUAGES CXX)
set(BOOST_CAPY_IS_ROOT OFF)
if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
set(BOOST_CAPY_IS_ROOT ON)
endif ()
set(__ignore__ ${CMAKE_C_COMPILER})
#-------------------------------------------------
#
# Options
#
#-------------------------------------------------
if (BOOST_CAPY_IS_ROOT)
include(CTest)
endif ()
option(BOOST_CAPY_BUILD_TESTS "Build boost::capy tests" ${BUILD_TESTING})
option(BOOST_CAPY_BUILD_EXAMPLES "Build boost::capy examples" ${BOOST_CAPY_IS_ROOT})
option(BOOST_CAPY_MRDOCS_BUILD "Build the target for MrDocs: see mrdocs.yml" OFF)
# Check if environment variable BOOST_SRC_DIR is set
if (NOT DEFINED BOOST_SRC_DIR AND DEFINED ENV{BOOST_SRC_DIR})
set(DEFAULT_BOOST_SRC_DIR "$ENV{BOOST_SRC_DIR}")
else ()
set(DEFAULT_BOOST_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../..")
endif ()
set(BOOST_SRC_DIR ${DEFAULT_BOOST_SRC_DIR} CACHE STRING "Boost source dir to use when running CMake from this directory.")
#-------------------------------------------------
#
# Boost modules
#
#-------------------------------------------------
# The boost super-project requires one explicit dependency per-line.
set(BOOST_CAPY_DEPENDENCIES
Boost::assert
Boost::config
Boost::core
Boost::system
Boost::throw_exception)
foreach (BOOST_CAPY_DEPENDENCY ${BOOST_CAPY_DEPENDENCIES})
if (BOOST_CAPY_DEPENDENCY MATCHES "^[ ]*Boost::([A-Za-z0-9_]+)[ ]*$")
list(APPEND BOOST_CAPY_INCLUDE_LIBRARIES ${CMAKE_MATCH_1})
endif ()
endforeach ()
# Conditional dependencies
if (BOOST_CAPY_BUILD_TESTS)
set(BOOST_CAPY_UNIT_TEST_LIBRARIES asio filesystem url)
endif ()
if (BOOST_CAPY_BUILD_EXAMPLES)
# set(BOOST_CAPY_EXAMPLE_LIBRARIES url)
endif ()
# Complete dependency list
set(BOOST_INCLUDE_LIBRARIES ${BOOST_CAPY_INCLUDE_LIBRARIES} ${BOOST_CAPY_UNIT_TEST_LIBRARIES} ${BOOST_CAPY_EXAMPLE_LIBRARIES})
set(BOOST_EXCLUDE_LIBRARIES capy)
#-------------------------------------------------
#
# Add Boost Subdirectory
#
#-------------------------------------------------
if (BOOST_CAPY_IS_ROOT)
set(CMAKE_FOLDER Dependencies)
# Find absolute BOOST_SRC_DIR
if (NOT IS_ABSOLUTE ${BOOST_SRC_DIR})
set(BOOST_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/${BOOST_SRC_DIR}")
endif ()
# Validate BOOST_SRC_DIR
set(BOOST_SRC_DIR_IS_VALID ON)
foreach (F "CMakeLists.txt" "Jamroot" "boost-build.jam" "bootstrap.sh" "libs")
if (NOT EXISTS "${BOOST_SRC_DIR}/${F}")
message(STATUS "${BOOST_SRC_DIR}/${F} does not exist. Fallback to find_package.")
set(BOOST_SRC_DIR_IS_VALID OFF)
break()
endif ()
endforeach ()
# Create Boost interface targets
if (BOOST_SRC_DIR_IS_VALID)
# From BOOST_SRC_DIR
if (BUILD_SHARED_LIBS)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
endif ()
set(BOOST_EXCLUDE_LIBRARIES ${PROJECT_NAME})
set(PREV_BUILD_TESTING ${BUILD_TESTING})
set(BUILD_TESTING OFF CACHE BOOL "Build the tests." FORCE)
add_subdirectory(${BOOST_SRC_DIR} Dependencies/boost EXCLUDE_FROM_ALL)
set(BUILD_TESTING ${PREV_BUILD_TESTING} CACHE BOOL "Build the tests." FORCE)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${BOOST_SRC_DIR}/tools/cmake/include")
else ()
# From Boost Package
find_package(Boost REQUIRED COMPONENTS url)
foreach (BOOST_INCLUDE_LIBRARY ${BOOST_INCLUDE_LIBRARIES})
if (NOT TARGET Boost::${BOOST_INCLUDE_LIBRARY})
add_library(Boost::${BOOST_INCLUDE_LIBRARY} ALIAS Boost::headers)
endif ()
endforeach ()
endif ()
unset(CMAKE_FOLDER)
endif ()
#-------------------------------------------------
#
# Library
#
#-------------------------------------------------
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
file(GLOB_RECURSE BOOST_CAPY_HEADERS CONFIGURE_DEPENDS include/boost/*.hpp include/boost/*.natvis)
list(FILTER BOOST_CAPY_HEADERS EXCLUDE REGEX ".*/(zlib|brotli).*")
file(GLOB_RECURSE BOOST_CAPY_SOURCES CONFIGURE_DEPENDS src/*.cpp src/*.hpp)
source_group("" FILES "include/boost/capy.hpp" "build/Jamfile")
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR}/include/boost/capy PREFIX "include" FILES ${BOOST_CAPY_HEADERS})
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR}/src PREFIX "src" FILES ${BOOST_CAPY_SOURCES})
function(boost_capy_setup_properties target)
target_compile_features(${target} PUBLIC cxx_std_20)
target_include_directories(${target} PUBLIC "${PROJECT_SOURCE_DIR}/include")
target_include_directories(${target} PRIVATE "${PROJECT_SOURCE_DIR}")
target_link_libraries(${target} PUBLIC ${BOOST_CAPY_DEPENDENCIES})
target_compile_definitions(${target} PUBLIC BOOST_CAPY_NO_LIB)
target_compile_definitions(${target} PRIVATE BOOST_CAPY_SOURCE)
if (BUILD_SHARED_LIBS)
target_compile_definitions(${target} PUBLIC BOOST_CAPY_DYN_LINK)
else ()
target_compile_definitions(${target} PUBLIC BOOST_CAPY_STATIC_LINK)
endif ()
endfunction()
if (BOOST_CAPY_MRDOCS_BUILD)
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/mrdocs.cpp"
"#include <boost/capy.hpp>\n"
"#include <boost/capy/bcrypt.hpp>\n"
"#include <boost/capy/zlib.hpp>\n"
"#include <boost/capy/brotli.hpp>\n")
add_library(boost_capy_mrdocs "${CMAKE_CURRENT_BINARY_DIR}/mrdocs.cpp")
boost_capy_setup_properties(boost_capy_mrdocs)
target_compile_definitions(boost_capy_mrdocs PUBLIC BOOST_CAPY_MRDOCS)
set_target_properties(boost_capy_mrdocs PROPERTIES EXPORT_COMPILE_COMMANDS ON)
return()
endif()
# Complete dependency list
add_library(boost_capy include/boost/capy.hpp build/Jamfile ${BOOST_CAPY_HEADERS} ${BOOST_CAPY_SOURCES})
add_library(Boost::capy ALIAS boost_capy)
boost_capy_setup_properties(boost_capy)
# bcrypt requires platform-specific libraries
if (WIN32)
target_link_libraries(boost_capy PRIVATE bcrypt)
elseif (APPLE)
target_link_libraries(boost_capy PRIVATE "-framework Security")
endif ()
# Zlib
find_package(ZLIB)
if (ZLIB_FOUND)
file(GLOB_RECURSE BOOST_CAPY_ZLIB_HEADERS CONFIGURE_DEPENDS include/boost/capy/zlib/*.hpp)
file(GLOB_RECURSE BOOST_CAPY_ZLIB_SOURCES CONFIGURE_DEPENDS src_zlib/*.cpp src_zlib/*.hpp)
source_group("" FILES "include/boost/capy/zlib.hpp")
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR}/include/boost/capy/zlib PREFIX "include" FILES ${BOOST_CAPY_ZLIB_HEADERS})
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR}/src_zlib PREFIX "src" FILES ${BOOST_CAPY_ZLIB_SOURCES})
add_library(boost_capy_zlib include/boost/capy/zlib.hpp build/Jamfile ${BOOST_CAPY_ZLIB_HEADERS} ${BOOST_CAPY_ZLIB_SOURCES})
add_library(Boost::capy_zlib ALIAS boost_capy_zlib)
target_link_libraries(boost_capy_zlib PUBLIC boost_capy)
target_link_libraries(boost_capy_zlib PRIVATE ZLIB::ZLIB)
target_compile_definitions(boost_capy_zlib PUBLIC BOOST_CAPY_HAS_ZLIB)
target_compile_definitions(boost_capy_zlib PRIVATE BOOST_CAPY_SOURCE)
endif ()
# Brotli
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
find_package(Brotli)
if (Brotli_FOUND)
file(GLOB_RECURSE BOOST_CAPY_BROTLI_HEADERS CONFIGURE_DEPENDS include/boost/capy/brotli/*.hpp)
file(GLOB_RECURSE BOOST_CAPY_BROTLI_SOURCES CONFIGURE_DEPENDS src_brotli/*.cpp src_brotli/*.hpp)
source_group("" FILES "include/boost/capy/brotli.hpp")
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR}/include/boost/capy/brotli PREFIX "include" FILES ${BOOST_CAPY_BROTLI_HEADERS})
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR}/src_brotli PREFIX "src" FILES ${BOOST_CAPY_BROTLI_SOURCES})
add_library(boost_capy_brotli include/boost/capy/brotli.hpp build/Jamfile ${BOOST_CAPY_BROTLI_HEADERS} ${BOOST_CAPY_BROTLI_SOURCES})
add_library(Boost::capy_brotli ALIAS boost_capy_brotli)
target_link_libraries(boost_capy_brotli PUBLIC boost_capy)
target_link_libraries(boost_capy_brotli PRIVATE Brotli::common Brotli::decoder Brotli::encoder)
target_compile_definitions(boost_capy_brotli PUBLIC BOOST_CAPY_HAS_BROTLI)
target_compile_definitions(boost_capy_brotli PRIVATE BOOST_CAPY_SOURCE)
endif ()
#-------------------------------------------------
#
# Benchmarks
#
#-------------------------------------------------
add_subdirectory(bench)
#-------------------------------------------------
#
# Tests
#
#-------------------------------------------------
if (BOOST_CAPY_BUILD_TESTS)
add_subdirectory(test)
endif ()
#-------------------------------------------------
#
# Examples
#
#-------------------------------------------------
if (BOOST_CAPY_BUILD_EXAMPLES)
# add_subdirectory(example)
endif ()