-
Notifications
You must be signed in to change notification settings - Fork 8
/
CMakeLists.txt
439 lines (401 loc) · 19.8 KB
/
CMakeLists.txt
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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
# NOTE: C++20 supported since CMake 3.12.0:
# https://cmake.org/cmake/help/v3.12/prop_tgt/CXX_STANDARD.html
cmake_minimum_required(VERSION 3.12.0)
# Set default build type to "Release".
# NOTE: this should be done before the project command since the latter can set
# CMAKE_BUILD_TYPE itself (it does so for nmake).
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING
"Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
FORCE)
endif()
# NOTE: obake is C++, however we are linking to C
# libraries (e.g., libbacktrace). Moreover, if we don't
# enable C here, on some configurations (e.g., Ubuntu
# + clang) the threading detection/setup seems to break
# down.
project(obake VERSION 0.9.0 LANGUAGES CXX C)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" "${CMAKE_CURRENT_SOURCE_DIR}/cmake/yacma")
message(STATUS "System name: ${CMAKE_SYSTEM_NAME}")
message(STATUS "obake version: ${obake_VERSION}")
# The build options.
option(OBAKE_BUILD_STATIC_LIBRARY "Build obake as a static library, instead of dynamic." OFF)
option(OBAKE_BUILD_TESTS "Build unit tests." OFF)
option(OBAKE_BUILD_BENCHMARKS "Build benchmarks." OFF)
option(OBAKE_WITH_LIBBACKTRACE "Use libbacktrace for improved stack traces." OFF)
# Run the YACMA compiler setup.
include(YACMACompilerLinkerSettings)
# Also the threading setup.
include(YACMAThreadingSetup)
if(YACMA_COMPILER_IS_MSVC AND OBAKE_BUILD_STATIC_LIBRARY)
option(OBAKE_BUILD_STATIC_LIBRARY_WITH_DYNAMIC_MSVC_RUNTIME "Link to the dynamic MSVC runtime when building obake as a static library." OFF)
mark_as_advanced(OBAKE_BUILD_STATIC_LIBRARY_WITH_DYNAMIC_MSVC_RUNTIME)
endif()
# NOTE: on Unix systems, the correct library installation path
# could be something other than just "lib", such as "lib64",
# "lib32", etc., depending on platform/configuration. Apparently,
# CMake provides this information via the GNUInstallDirs module.
# Let's enable this for now on all Unixes except OSX.
# NOTE: potentially, this could be applicable to Cygwin as well.
#
# https://cmake.org/cmake/help/v3.15/module/GNUInstallDirs.html
# https://cmake.org/pipermail/cmake/2013-July/055375.html
if(UNIX AND NOT APPLE)
include(GNUInstallDirs)
set(_OBAKE_INSTALL_LIBDIR_DEFAULT "${CMAKE_INSTALL_LIBDIR}")
else()
set(_OBAKE_INSTALL_LIBDIR_DEFAULT "lib")
endif()
if(NOT OBAKE_INSTALL_LIBDIR)
set(OBAKE_INSTALL_LIBDIR "${_OBAKE_INSTALL_LIBDIR_DEFAULT}" CACHE STRING
"Library installation directory." FORCE)
endif()
mark_as_advanced(OBAKE_INSTALL_LIBDIR)
message(STATUS "Library installation directory: ${OBAKE_INSTALL_LIBDIR}")
# Assemble the flags.
set(OBAKE_CXX_FLAGS_DEBUG ${YACMA_CXX_FLAGS} ${YACMA_CXX_FLAGS_DEBUG})
set(OBAKE_CXX_FLAGS_RELEASE ${YACMA_CXX_FLAGS})
if(YACMA_COMPILER_IS_MSVC)
include(CheckCXXCompilerFlag)
# Disable the idiotic minmax macros on MSVC (both cl and clang-cl).
# Also, enable the bigobj flag and the WIN32_LEAN_AND_MEAN definitions:
# https://stackoverflow.com/questions/11040133/what-does-defining-win32-lean-and-mean-exclude-exactly
list(APPEND OBAKE_CXX_FLAGS_DEBUG "-DNOMINMAX" "/bigobj" "-DWIN32_LEAN_AND_MEAN")
list(APPEND OBAKE_CXX_FLAGS_RELEASE "-DNOMINMAX" "/bigobj" "-DWIN32_LEAN_AND_MEAN")
# Enable strict conformance mode, if supported.
set(CMAKE_REQUIRED_QUIET TRUE)
check_cxx_compiler_flag("/permissive-" _OBAKE_MSVC_SUPPORTS_STRICT_CONFORMANCE)
unset(CMAKE_REQUIRED_QUIET)
if(_OBAKE_MSVC_SUPPORTS_STRICT_CONFORMANCE)
message(STATUS "The '/permissive-' flag is supported, enabling it.")
list(APPEND OBAKE_CXX_FLAGS_DEBUG "/permissive-")
list(APPEND OBAKE_CXX_FLAGS_RELEASE "/permissive-")
endif()
unset(_OBAKE_MSVC_SUPPORTS_STRICT_CONFORMANCE)
if(YACMA_COMPILER_IS_CLANGXX)
# clang-cl emits various warnings from GMP/MPFR, let's just silence them.
# NOTE: at one point in the recent past, MSVC added an options similar to GCC's isystem:
# https://blogs.msdn.microsoft.com/vcblog/2017/12/13/broken-warnings-theory/
# We probably just need to wait for this to be picked up by CMake/clang-cl. Let's
# revisit the issue in the future.
list(APPEND _OBAKE_CLANG_CL_DISABLED_WARNINGS
"-Wno-unused-variable"
"-Wno-inconsistent-dllimport"
"-Wno-unknown-pragmas"
"-Wno-unused-parameter"
"-Wno-sign-compare"
"-Wno-deprecated-declarations"
"-Wno-deprecated-dynamic-exception-spec"
"-Wno-old-style-cast"
"-Wno-sign-conversion"
"-Wno-non-virtual-dtor"
"-Wno-deprecated"
"-Wno-shadow"
"-Wno-shorten-64-to-32"
"-Wno-reserved-id-macro"
"-Wno-undef"
"-Wno-c++98-compat-pedantic"
"-Wno-documentation-unknown-command"
"-Wno-zero-as-null-pointer-constant"
"-Wno-language-extension-token"
"-Wno-gnu-anonymous-struct"
"-Wno-nested-anon-types"
"-Wno-documentation"
"-Wno-comma"
"-Wno-nonportable-system-include-path"
"-Wno-global-constructors"
"-Wno-redundant-parens"
"-Wno-exit-time-destructors"
"-Wno-missing-noreturn"
"-Wno-switch-enum"
"-Wno-covered-switch-default"
"-Wno-float-equal"
"-Wno-double-promotion"
"-Wno-microsoft-enum-value"
"-Wno-missing-prototypes"
"-Wno-implicit-fallthrough"
"-Wno-format-nonliteral"
"-Wno-cast-qual"
"-Wno-disabled-macro-expansion"
"-Wno-unused-private-field"
"-Wno-unused-template"
"-Wno-unused-macros"
"-Wno-extra-semi-stmt"
"-Wno-c++98-compat")
list(APPEND OBAKE_CXX_FLAGS_DEBUG ${_OBAKE_CLANG_CL_DISABLED_WARNINGS})
list(APPEND OBAKE_CXX_FLAGS_RELEASE ${_OBAKE_CLANG_CL_DISABLED_WARNINGS})
unset(_OBAKE_CLANG_CL_DISABLED_WARNINGS)
else()
# Problematic MSVC cl warnings.
list(APPEND OBAKE_CXX_FLAGS_DEBUG "/wd4459")
list(APPEND OBAKE_CXX_FLAGS_RELEASE "/wd4459")
endif()
endif()
if(MINGW)
# In MinGW some tests generate big object files.
message(STATUS "Enabling the '-Wa,-mbig-obj' flag for MinGW.")
list(APPEND OBAKE_CXX_FLAGS_DEBUG "-Wa,-mbig-obj")
list(APPEND OBAKE_CXX_FLAGS_RELEASE "-Wa,-mbig-obj")
endif()
# Find the dependencies.
# mp++.
# NOTE: put the minimum version in a variable
# so that we can re-use it in the config-file package
# machinery below.
set (_OBAKE_MIN_MPPP_VERSION 0.27)
find_package(mp++ REQUIRED)
if(${mp++_VERSION} VERSION_LESS ${_OBAKE_MIN_MPPP_VERSION})
message(FATAL_ERROR "The minimum mp++ version required by obake is ${_OBAKE_MIN_MPPP_VERSION}, but version ${mp++_VERSION} was found instead.")
endif()
# Boost setup.
# NOTE: need 1.81 for unordered_flat_set.
set(_OBAKE_MIN_BOOST_VERSION "1.81")
# NOTE: we look for Boost in CONFIG mode first, as that has become the official supported way
# of locating Boost in recent Boost/CMake versions. If we fail, we try again in
# MODULE mode as last resort.
find_package(Boost ${_OBAKE_MIN_BOOST_VERSION} QUIET COMPONENTS serialization CONFIG)
if(NOT ${Boost_FOUND})
message(STATUS "Boost not found in CONFIG mode, retrying in MODULE mode.")
find_package(Boost ${_OBAKE_MIN_BOOST_VERSION} QUIET MODULE COMPONENTS serialization)
endif()
if(NOT ${Boost_FOUND})
message(FATAL_ERROR "Could not locate Boost in either CONFIG or MODULE mode.")
endif()
message(STATUS "Found Boost version ${Boost_VERSION}.")
# libbacktrace.
if(OBAKE_WITH_LIBBACKTRACE)
set(OBAKE_ENABLE_LIBBACKTRACE "#define OBAKE_WITH_LIBBACKTRACE")
find_package(libbacktrace REQUIRED)
endif()
# TBB. Try to find it first in config mode (supported
# since version 2021 after the oneTBB rename), and, if this
# fails, fall back to our own FindTBB.cmake. This is of course
# not an ideal solution, but it should work until oneTBB
# becomes widely deployed.
find_package(TBB QUIET CONFIG)
if(NOT TBB_FOUND)
message(STATUS "TBB not found using config mode, retrying in module mode.")
find_package(TBB REQUIRED MODULE)
else()
message(STATUS "TBB found using config mode.")
endif()
# Depend on DbgEng on WIN32, for the stack trace support.
if(WIN32)
find_package(DbgEng REQUIRED)
endif()
# fmt.
find_package(fmt REQUIRED)
# Wrap the CMAKE_DL_LIBS variable in an imported target.
include(ObakeFindDl)
# Explanation: on MSVC, when building static libraries, it is good practice to link
# to the static runtime. CMake, however, is hard-coded to link to the dynamic runtime.
# Hence we hackishly replace the /MD flag with /MT. This is the approach suggested
# in the CMake FAQ:
#
# https://gitlab.kitware.com/cmake/community/wikis/FAQ#how-can-i-build-my-msvc-application-with-a-static-runtime
#
# Note that at one point CMake added the possiblity to set this as a target property,
# so in the future we should definitely migrate to that approach:
#
# https://cmake.org/cmake/help/git-master/prop_tgt/MSVC_RUNTIME_LIBRARY.html
#
# NOTE: the OBAKE_BUILD_STATIC_LIBRARY_WITH_DYNAMIC_MSVC_RUNTIME option overrides this choice
# and keeps the dynamic runtime. This can be needed in specific rare situations.
if(YACMA_COMPILER_IS_MSVC AND OBAKE_BUILD_STATIC_LIBRARY AND NOT OBAKE_BUILD_STATIC_LIBRARY_WITH_DYNAMIC_MSVC_RUNTIME)
foreach(flag_var
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
if(${flag_var} MATCHES "/MD")
string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
endif()
endforeach()
endif()
# Initial setup of the obake target.
set(OBAKE_SRC_FILES
"${CMAKE_CURRENT_SOURCE_DIR}/src/cf/cf_stream_insert.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/detail/atomic_flag_array.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/detail/hc.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/detail/to_string.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/detail/fw_utils.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/stack_trace.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/series.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/symbols.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/tex_stream_insert.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/kpack.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/polynomials/packed_monomial.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/polynomials/d_packed_monomial.cpp"
)
if(OBAKE_WITH_LIBBACKTRACE)
set(OBAKE_SRC_FILES "${CMAKE_CURRENT_SOURCE_DIR}/src/libbacktrace_stack_trace.cpp" "${OBAKE_SRC_FILES}")
else()
set(OBAKE_SRC_FILES "${CMAKE_CURRENT_SOURCE_DIR}/src/boost_stack_trace.cpp" "${OBAKE_SRC_FILES}")
endif()
# Make obake header files accessible in Visual Studio IDE.
if(YACMA_COMPILER_IS_MSVC)
set(OBAKE_HEADER_FILES
"${CMAKE_CURRENT_LIST_DIR}/include/obake/byte_size.hpp"
"${CMAKE_CURRENT_LIST_DIR}/include/obake/exceptions.hpp"
"${CMAKE_CURRENT_LIST_DIR}/include/obake/hash.hpp"
"${CMAKE_CURRENT_LIST_DIR}/include/obake/kpack.hpp"
"${CMAKE_CURRENT_LIST_DIR}/include/obake/ranges.hpp"
"${CMAKE_CURRENT_LIST_DIR}/include/obake/s11n.hpp"
"${CMAKE_CURRENT_LIST_DIR}/include/obake/series.hpp"
"${CMAKE_CURRENT_LIST_DIR}/include/obake/stack_trace.hpp"
"${CMAKE_CURRENT_LIST_DIR}/include/obake/symbols.hpp"
"${CMAKE_CURRENT_LIST_DIR}/include/obake/tex_stream_insert.hpp"
"${CMAKE_CURRENT_LIST_DIR}/include/obake/type_name.hpp"
"${CMAKE_CURRENT_LIST_DIR}/include/obake/type_traits.hpp"
"${CMAKE_CURRENT_LIST_DIR}/include/obake/polynomials/d_packed_monomial.hpp"
"${CMAKE_CURRENT_LIST_DIR}/include/obake/polynomials/monomial_diff.hpp"
"${CMAKE_CURRENT_LIST_DIR}/include/obake/polynomials/monomial_homomorphic_hash.hpp"
"${CMAKE_CURRENT_LIST_DIR}/include/obake/polynomials/monomial_integrate.hpp"
"${CMAKE_CURRENT_LIST_DIR}/include/obake/polynomials/monomial_mul.hpp"
"${CMAKE_CURRENT_LIST_DIR}/include/obake/polynomials/monomial_pow.hpp"
"${CMAKE_CURRENT_LIST_DIR}/include/obake/polynomials/monomial_range_overflow_check.hpp"
"${CMAKE_CURRENT_LIST_DIR}/include/obake/polynomials/monomial_subs.hpp"
"${CMAKE_CURRENT_LIST_DIR}/include/obake/polynomials/packed_monomial.hpp"
"${CMAKE_CURRENT_LIST_DIR}/include/obake/polynomials/polynomial.hpp"
"${CMAKE_CURRENT_LIST_DIR}/include/obake/math/degree.hpp"
"${CMAKE_CURRENT_LIST_DIR}/include/obake/math/diff.hpp"
"${CMAKE_CURRENT_LIST_DIR}/include/obake/math/evaluate.hpp"
"${CMAKE_CURRENT_LIST_DIR}/include/obake/math/fma3.hpp"
"${CMAKE_CURRENT_LIST_DIR}/include/obake/math/integrate.hpp"
"${CMAKE_CURRENT_LIST_DIR}/include/obake/math/is_zero.hpp"
"${CMAKE_CURRENT_LIST_DIR}/include/obake/math/negate.hpp"
"${CMAKE_CURRENT_LIST_DIR}/include/obake/math/p_degree.hpp"
"${CMAKE_CURRENT_LIST_DIR}/include/obake/math/pow.hpp"
"${CMAKE_CURRENT_LIST_DIR}/include/obake/math/safe_cast.hpp"
"${CMAKE_CURRENT_LIST_DIR}/include/obake/math/safe_convert.hpp"
"${CMAKE_CURRENT_LIST_DIR}/include/obake/math/subs.hpp"
"${CMAKE_CURRENT_LIST_DIR}/include/obake/math/trim.hpp"
"${CMAKE_CURRENT_LIST_DIR}/include/obake/math/truncate_degree.hpp"
"${CMAKE_CURRENT_LIST_DIR}/include/obake/math/truncate_p_degree.hpp"
"${CMAKE_CURRENT_LIST_DIR}/include/obake/key/key_degree.hpp"
"${CMAKE_CURRENT_LIST_DIR}/include/obake/key/key_evaluate.hpp"
"${CMAKE_CURRENT_LIST_DIR}/include/obake/key/key_is_compatible.hpp"
"${CMAKE_CURRENT_LIST_DIR}/include/obake/key/key_is_one.hpp"
"${CMAKE_CURRENT_LIST_DIR}/include/obake/key/key_is_zero.hpp"
"${CMAKE_CURRENT_LIST_DIR}/include/obake/key/key_merge_symbols.hpp"
"${CMAKE_CURRENT_LIST_DIR}/include/obake/key/key_p_degree.hpp"
"${CMAKE_CURRENT_LIST_DIR}/include/obake/key/key_stream_insert.hpp"
"${CMAKE_CURRENT_LIST_DIR}/include/obake/key/key_tex_stream_insert.hpp"
"${CMAKE_CURRENT_LIST_DIR}/include/obake/key/key_trim.hpp"
"${CMAKE_CURRENT_LIST_DIR}/include/obake/key/key_trim_identify.hpp"
"${CMAKE_CURRENT_LIST_DIR}/include/obake/detail/atomic_flag_array.hpp"
"${CMAKE_CURRENT_LIST_DIR}/include/obake/detail/atomic_lock_guard.hpp"
"${CMAKE_CURRENT_LIST_DIR}/include/obake/detail/fcast.hpp"
"${CMAKE_CURRENT_LIST_DIR}/include/obake/detail/fw_utils.hpp"
"${CMAKE_CURRENT_LIST_DIR}/include/obake/detail/hc.hpp"
"${CMAKE_CURRENT_LIST_DIR}/include/obake/detail/ignore.hpp"
"${CMAKE_CURRENT_LIST_DIR}/include/obake/detail/it_diff_check.hpp"
"${CMAKE_CURRENT_LIST_DIR}/include/obake/detail/limits.hpp"
"${CMAKE_CURRENT_LIST_DIR}/include/obake/detail/mppp_utils.hpp"
"${CMAKE_CURRENT_LIST_DIR}/include/obake/detail/not_implemented.hpp"
"${CMAKE_CURRENT_LIST_DIR}/include/obake/detail/priority_tag.hpp"
"${CMAKE_CURRENT_LIST_DIR}/include/obake/detail/safe_integral_arith.hpp"
"${CMAKE_CURRENT_LIST_DIR}/include/obake/detail/ss_func_forward.hpp"
"${CMAKE_CURRENT_LIST_DIR}/include/obake/detail/to_string.hpp"
"${CMAKE_CURRENT_LIST_DIR}/include/obake/detail/tuple_for_each.hpp"
"${CMAKE_CURRENT_LIST_DIR}/include/obake/detail/type_c.hpp"
"${CMAKE_CURRENT_LIST_DIR}/include/obake/detail/visibility.hpp"
"${CMAKE_CURRENT_LIST_DIR}/include/obake/detail/xoroshiro128_plus.hpp"
"${CMAKE_CURRENT_LIST_DIR}/include/obake/cf/cf_stream_insert.hpp"
"${CMAKE_CURRENT_LIST_DIR}/include/obake/cf/cf_tex_stream_insert.hpp"
)
source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/include/obake" PREFIX "Header Files" FILES ${OBAKE_HEADER_FILES})
set(OBAKE_SRC_FILES ${OBAKE_SRC_FILES} ${OBAKE_HEADER_FILES})
endif()
if(OBAKE_BUILD_STATIC_LIBRARY)
# Setup of the obake static library.
message(STATUS "obake will be built as a static library.")
set(OBAKE_STATIC_BUILD "#define OBAKE_STATIC_BUILD")
add_library(obake STATIC "${OBAKE_SRC_FILES}")
else()
# Setup of the obake shared library.
add_library(obake SHARED "${OBAKE_SRC_FILES}")
set_property(TARGET obake PROPERTY VERSION "9.0")
set_property(TARGET obake PROPERTY SOVERSION 9)
set_target_properties(obake PROPERTIES CXX_VISIBILITY_PRESET hidden)
set_target_properties(obake PROPERTIES VISIBILITY_INLINES_HIDDEN TRUE)
endif()
# Setup common to both the shared and static variants.
target_compile_options(obake PRIVATE
"$<$<CONFIG:Debug>:${OBAKE_CXX_FLAGS_DEBUG}>"
"$<$<CONFIG:Release>:${OBAKE_CXX_FLAGS_RELEASE}>"
"$<$<CONFIG:RelWithDebInfo>:${OBAKE_CXX_FLAGS_RELEASE}>"
"$<$<CONFIG:MinSizeRel>:${OBAKE_CXX_FLAGS_RELEASE}>"
)
# Ensure that C++20 is employed when both compiling and consuming obake.
target_compile_features(obake PUBLIC cxx_std_20)
# Ensure vanilla C++ is being used.
set_property(TARGET obake PROPERTY CXX_EXTENSIONS NO)
if(YACMA_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS "10")
# GCC < 10 still needs the -fconcepts flag, even if C++20 is in use.
message(STATUS "Activating the '-fconcepts' flag for GCC < 10.")
target_compile_options(obake PUBLIC -fconcepts)
endif()
# Add the include dirs to the obake target's interface.
target_include_directories(obake PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
$<INSTALL_INTERFACE:include>)
# Link the deps.
target_link_libraries(obake PUBLIC
Threads::Threads
mp++::mp++
Boost::boost
Boost::serialization
Boost::disable_autolinking
TBB::tbb
fmt::fmt
)
if(OBAKE_WITH_LIBBACKTRACE)
target_link_libraries(obake PRIVATE libbacktrace::libbacktrace)
else()
# NOTE: Boost stacktrace sometimes requires linking to the system
# DL libs.
target_link_libraries(obake PRIVATE obake::dl)
endif()
# Link to DbgEng on Windows.
if(WIN32)
target_link_libraries(obake PRIVATE DbgEng::DbgEng)
endif()
# Configure config.hpp.
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/config.hpp.in" "${CMAKE_CURRENT_BINARY_DIR}/include/obake/config.hpp" @ONLY)
# Configure the sphinx config file.
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/doc/conf.py.in" "${CMAKE_CURRENT_SOURCE_DIR}/doc/conf.py" @ONLY)
# Installation of the header files.
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/obake" DESTINATION include)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/include/obake/config.hpp" DESTINATION include/obake)
# Installation of the library.
install(TARGETS obake
EXPORT obake_export
LIBRARY DESTINATION "${OBAKE_INSTALL_LIBDIR}"
ARCHIVE DESTINATION "${OBAKE_INSTALL_LIBDIR}"
RUNTIME DESTINATION bin
)
# Setup of the optional deps.
set(_OBAKE_CONFIG_OPTIONAL_DEPS)
if(OBAKE_WITH_LIBBACKTRACE)
set(_OBAKE_CONFIG_OPTIONAL_DEPS "${_OBAKE_CONFIG_OPTIONAL_DEPS}find_package(libbacktrace REQUIRED)\n")
endif()
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/obake-config.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/obake-config.cmake" @ONLY)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/obake-config.cmake" DESTINATION "${OBAKE_INSTALL_LIBDIR}/cmake/obake")
install(FILES
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindDbgEng.cmake"
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindTBB.cmake"
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/Findlibbacktrace.cmake"
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/ObakeFindDl.cmake"
DESTINATION "${OBAKE_INSTALL_LIBDIR}/cmake/obake")
install(EXPORT obake_export NAMESPACE obake:: DESTINATION "${OBAKE_INSTALL_LIBDIR}/cmake/obake")
# Take care of versioning.
include(CMakePackageConfigHelpers)
write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/obake-config-version.cmake" COMPATIBILITY SameMinorVersion)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/obake-config-version.cmake" DESTINATION "${OBAKE_INSTALL_LIBDIR}/cmake/obake")
if(OBAKE_BUILD_TESTS)
enable_testing()
add_subdirectory(test)
endif()
if(OBAKE_BUILD_BENCHMARKS)
add_subdirectory(benchmark)
endif()