-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
216 lines (172 loc) · 6.4 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
# Written in 2017, 2019, 2022-2023 by Henrik Steffen Gaßmann <[email protected]>
#
# To the extent possible under law, the author(s) have dedicated all
# copyright and related and neighboring rights to this software to the
# public domain worldwide. This software is distributed without any warranty.
#
# You should have received a copy of the CC0 Public Domain Dedication
# along with this software. If not, see
#
# http://creativecommons.org/publicdomain/zero/1.0/
#
########################################################################
cmake_minimum_required(VERSION 3.22)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/tools/cmake/")
if (POLICY CMP0127)
cmake_policy(SET CMP0127 NEW)
endif()
########################################################################
# configure vcpkg from environment vars if possible
include(VcpkgDefaults)
if (BUILD_TESTING OR NOT DEFINED BUILD_TESTING)
list(APPEND VCPKG_MANIFEST_FEATURES "tests")
endif()
########################################################################
project(deeppack
VERSION 0.1.0.12
LANGUAGES CXX
)
include(EnforceOutOfSourceBuilds)
include(CMakeDependentOption)
include(CMakePackageConfigHelpers)
include(FeatureSummary)
include(GNUInstallDirs)
include(SourceHelpers)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
if (BUILD_TESTING)
enable_testing()
endif()
########################################################################
# options
option(DPLX_DP_DISABLE_WORKAROUNDS "Disable all workarounds" OFF)
option(DPLX_DP_FLAG_OUTDATED_WORKAROUNDS "Emit compiler errors for workarounds which are active, but haven't been validated for this version" OFF)
option(DPLX_DP_USE_BRANCHING_INTEGER_ENCODER "Use the branching store_var_uint implementation" OFF)
mark_as_advanced(DPLX_DP_USE_BRANCHING_INTEGER_ENCODER)
option(DPLX_DP_DISABLE_WORKAROUNDS "Disable all workarounds" OFF)
option(DPLX_DP_FLAG_OUTDATED_WORKAROUNDS "Emit compiler errors for workarounds which are active, but haven't been validated for this version" OFF)
########################################################################
# dependencies
set(Boost_NO_WARN_NEW_VERSIONS ON)
find_package(concrete 0.0 CONFIG REQUIRED)
find_package(fmt 9 CONFIG REQUIRED)
find_package(status-code CONFIG REQUIRED)
find_package(outcome CONFIG REQUIRED)
find_package(Boost 1.81 REQUIRED)
find_package(yaml-cpp CONFIG)
set_package_properties(yaml-cpp PROPERTIES
TYPE OPTIONAL
PURPOSE "Allows to build the test suite"
)
find_package(Catch2 CONFIG)
set_package_properties(Catch2 PROPERTIES
TYPE OPTIONAL
PURPOSE "Allows to build the test suite"
)
cmake_dependent_option(BUILD_TESTING "Build the test suite" ON "Catch2_FOUND;yaml-cpp_FOUND" OFF)
find_package(Sphinx)
set_package_properties(Sphinx PROPERTIES
TYPE OPTIONAL
PURPOSE "Allows to build the documentation"
)
cmake_dependent_option(BUILD_DOCS "Build the documentation using sphinx" ON Sphinx_FOUND OFF)
########################################################################
# warning configuration
include(CompilerWarnings)
########################################################################
# additional compiler options
set(CMAKE_CXX_EXTENSIONS OFF CACHE STRING "" FORCE)
add_library(compiler_settings INTERFACE)
add_library(Deeplex::deeppack_compiler_settings ALIAS compiler_settings)
set_target_properties(compiler_settings PROPERTIES
EXPORT_NAME deeppack_compiler_settings
)
target_compile_features(compiler_settings INTERFACE cxx_std_20)
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
target_compile_options(compiler_settings INTERFACE
/utf-8 # all sources are utf-8 encoded
/Zc:__cplusplus # correctly define the __cplusplus macro
)
endif()
if (WIN32)
target_compile_definitions(compiler_settings INTERFACE
-D_ENABLE_EXTENDED_ALIGNED_STORAGE=1
)
endif()
########################################################################
# library
add_library(deeppack)
add_library(Deeplex::deeppack ALIAS deeppack)
target_link_libraries(deeppack PUBLIC
Deeplex::deeppack_compiler_settings
Boost::boost
Deeplex::concrete
fmt::fmt
outcome::hl
status-code::hl
)
target_include_directories(deeppack PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/generated/src>
$<INSTALL_INTERFACE:include>
)
########################################################################
# library test project
if (BUILD_TESTING)
add_executable(deeppack-tests)
target_link_libraries(deeppack-tests PRIVATE
Deeplex::deeppack
Catch2::Catch2 Catch2::Catch2WithMain
yaml-cpp::yaml-cpp
)
target_include_directories(deeppack-tests PRIVATE
src/dp_tests
)
add_test(NAME deeppack-tests COMMAND deeppack-tests
WORKING_DIRECTORY $<TARGET_FILE_DIR:deeppack-tests>
)
endif()
########################################################################
# source files
include(sources.cmake)
source_group(vcpkg REGULAR_EXPRESSION .*/vcpkg_installed/.*)
########################################################################
# docs
if (BUILD_DOCS)
add_subdirectory(docs)
endif()
########################################################################
# cmake install
install(DIRECTORY src/dplx
TYPE INCLUDE
FILES_MATCHING
REGEX ".*\\.h(pp)?"
)
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/generated/src/dplx
TYPE INCLUDE
FILES_MATCHING
REGEX ".*\\.h(pp)?"
)
install(TARGETS deeppack compiler_settings EXPORT deeppack-targets)
install(EXPORT deeppack-targets
NAMESPACE Deeplex::
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/deeppack"
)
export(EXPORT deeppack-targets NAMESPACE Deeplex::)
# note that you need to configure with -DCMAKE_EXPORT_PACKAGE_REGISTRY=ON
# for this to have any effect at all
export(PACKAGE deeppack)
configure_package_config_file(tools/deeppack-config.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/deeppack-config.cmake"
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/deeppack"
)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/deeppack-config-version.cmake"
COMPATIBILITY SameMinorVersion
)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/deeppack-config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/deeppack-config-version.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/deeppack"
)
########################################################################
feature_summary(WHAT PACKAGES_FOUND PACKAGES_NOT_FOUND)