-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathCMakeLists.txt
305 lines (276 loc) · 10.1 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
# =============================================================================
#
# ztd.idk
# Copyright © JeanHeyd "ThePhD" Meneide and Shepherd's Oasis, LLC
# Contact: [email protected]
#
# Commercial License Usage
# Licensees holding valid commercial ztd.idk licenses may use this file in
# accordance with the commercial license agreement provided with the
# Software or, alternatively, in accordance with the terms contained in
# a written agreement between you and Shepherd's Oasis, LLC.
# For licensing terms and conditions see your agreement. For
# further information contact [email protected].
#
# Apache License Version 2 Usage
# Alternatively, this file may be used under the terms of Apache License
# Version 2.0 (the "License") for non-commercial use; you may not use this
# file except in compliance with the License. You may obtain a copy of the
# License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# ============================================================================>
cmake_minimum_required(VERSION 3.28.0)
# # Project kickstart
# Includes a bunch of basic flags and utilities shared across projects
# See more at the github repository link below
include(FetchContent)
FetchContent_Declare(ztd.cmake
GIT_REPOSITORY https://github.com/soasis/cmake.git
GIT_TAG main)
FetchContent_MakeAvailable(ztd.cmake)
set(CMAKE_PROJECT_INCLUDE ${ZTD_CMAKE_PROJECT_PRELUDE})
# # Project declaration
# informs about the project, gives a description, version and MOST IMPORTANTLY
# the languages the project is going to use. Required.
project(ztd.idk
VERSION 0.0.0
DESCRIPTION "The IDK (Industrial Development Kit) Library, for useful tools that get the job done!"
HOMEPAGE_URL "https://ztdidk.rtfd.io/"
LANGUAGES CXX C)
if(ZTD_IDK_READTHEDOCS)
# ReadTheDocs seems unable to handle the include at the project level: something must be going wrong?
include(CheckCXXCompilerFlag)
include(CheckCCompilerFlag)
include(CheckIPOSupported)
include(CMakePackageConfigHelpers)
include(CMakeDependentOption)
include(CMakePrintHelpers)
include(GNUInstallDirs)
include(FeatureSummary)
include(FetchContent)
include(CTest)
endif()
# # # Top-Level Directories
# Check if this is the top-level project or not
if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
set(ZTD_IDK_IS_TOP_LEVEL_PROJECT YES)
else()
set(ZTD_IDK_IS_TOP_LEVEL_PROJECT NO)
endif()
# # Options
option(ZTD_IDK_CI "Whether or not we are in continuous integration mode" OFF)
option(ZTD_IDK_READTHEDOCS "Whether or not we are building inside of ReadTheDocs" OFF)
option(ZTD_IDK_TESTS "Enable build of tests" OFF)
option(ZTD_IDK_DOCUMENTATION "Enable build of documentation" OFF)
option(ZTD_IDK_DOCUMENTATION_NO_SPHINX "Turn off Sphinx usage (useful for ReadTheDocs builds)" OFF)
option(ZTD_IDK_EXAMPLES "Enable build of examples" OFF)
option(ZTD_IDK_BENCHMARKS "Enable build of benchmarks" OFF)
option(ZTD_IDK_GENERATE_SINGLE "Enable generation of a single header and its target" OFF)
set(ZTD_IDK_BENCHMARKS_REPETITIONS 50 CACHE STRING "Number of repetitions to perform. Each repetition has a number of iterations: higher means a lot more time is spent benchmarking.")
# Modify bad flags / change defaults if we are the top level
if(ZTD_IDK_IS_TOP_LEVEL_PROJECT)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/lib")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin")
if(NOT DEFINED CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 17)
endif()
if(NOT DEFINED CMAKE_C_STANDARD)
set(CMAKE_C_STANDARD 11)
endif()
if(ZTD_IDK_BENCHMARKS OR ZTD_IDK_EXAMPLES OR ZTD_IDK_TESTS OR ZTD_IDK_SCRATCH)
# normal flags
check_compiler_flag(disable-permissive MSVC /permissive- GCC -pedantic)
check_compiler_flag(disable-aliasing GCC -fno-strict-aliasing)
# Warning flags
check_compiler_flag(warn-pedantic MSVC /permissive- GCC -pedantic)
check_compiler_flag(warn-all MSVC /W4 GCC -Wall)
check_compiler_flag(warn-errors MSVC /WX GCC -Werror)
check_compiler_flag(warn-extra GCC -Wextra Clang -Wextra)
check_compiler_flag(utf8-literal-encoding MSVC /execution-charset:utf-8 GCC -fexec-charset=utf-8)
check_compiler_flag(utf8-source-encoding MSVC /source-charset:utf-8 GCC -finput-charset=utf-8)
check_compiler_flag(extra-constexpr-depth MSVC /constexpr:depth2147483647 GCC -fconstexpr-depth=2147483647 Clang -fconstexpr-depth=2147483647)
check_compiler_flag(extra-constexpr-steps MSVC /constexpr:steps2147483647 GCC -fconstexpr-ops-limit=2147483647 Clang -fconstexpr-steps=2147483647)
check_compiler_flag(template-debugging-mode GCC -ftemplate-backtrace-limit=0)
check_compiler_diagnostic(microsoft-enum-value)
check_compiler_diagnostic(gnu-zero-variadic-macro-arguments)
check_compiler_diagnostic(type-limits)
# (Wstringop-overflow) - [meta-bug] bogus/missing -Wstringop-overflow warnings
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88443
# Bogus -Wstringop-overflow warning
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100395
# [10 Regression] spurious -Wstringop-overflow writing to a trailing array plus offset
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95353
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.0)
check_compiler_diagnostic(stringop-overflow)
check_compiler_diagnostic(stringop-overread)
check_compiler_diagnostic(array-bounds)
endif()
endif()
endif()
# # Main library declarations
# ztd.version
add_library(ztd.version INTERFACE)
add_library(ztd::version ALIAS ztd.version)
target_include_directories(ztd.version
INTERFACE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
install(DIRECTORY include/
DESTINATION
${CMAKE_INSTALL_INCLUDEDIR}
)
configure_package_config_file(
cmake/ztd.version-config.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/cmake/ztd.version/ztd.version-config.cmake"
INSTALL_DESTINATION lib/cmake/ztd.version
NO_CHECK_REQUIRED_COMPONENTS_MACRO
)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/cmake/ztd.version/ztd.version-config-version.cmake"
COMPATIBILITY SameMajorVersion
)
export(TARGETS ztd.version
FILE
"${CMAKE_CURRENT_BINARY_DIR}/cmake/ztd.version/ztd.version-targets.cmake"
)
# ztd.tag_invoke
file(GLOB_RECURSE ztd.tag_invoke.includes
CONFIGURE_DEPENDS
include/tag_invoke**.hpp
include/tag_invoke**.h
)
add_library(ztd.tag_invoke INTERFACE)
add_library(ztd::tag_invoke ALIAS ztd.tag_invoke)
target_include_directories(ztd.tag_invoke
INTERFACE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
target_link_libraries(ztd.tag_invoke
INTERFACE
ztd::version
)
install(DIRECTORY include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
configure_package_config_file(
cmake/ztd.tag_invoke-config.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/cmake/ztd.tag_invoke/ztd.tag_invoke-config.cmake"
INSTALL_DESTINATION lib/cmake/ztd.tag_invoke
NO_CHECK_REQUIRED_COMPONENTS_MACRO
)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/cmake/ztd.tag_invoke/ztd.tag_invoke-config-version.cmake"
COMPATIBILITY SameMajorVersion
)
export(TARGETS ztd.tag_invoke
FILE
"${CMAKE_CURRENT_BINARY_DIR}/cmake/ztd.tag_invoke/ztd.tag_invoke-targets.cmake"
)
# ztd.idk
file(GLOB_RECURSE ztd.idk.includes
CONFIGURE_DEPENDS
include/ztd/idk**.hpp
include/ztd/idk**.h
)
file(GLOB_RECURSE ztd.idk.sources
CONFIGURE_DEPENDS
source/ztd/idk/**.cpp
source/ztd/idk/**.c
)
add_library(ztd.idk ${ztd.idk.sources})
add_library(ztd::idk ALIAS ztd.idk)
target_include_directories(ztd.idk
PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
PRIVATE
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/source/include>
)
target_link_libraries(ztd.idk
PUBLIC
ztd::version
ztd::tag_invoke
)
target_compile_definitions(ztd.idk
PRIVATE
ZTD_IDK_BUILD=1
PUBLIC
$<$<STREQUAL:$<TARGET_PROPERTY:ztd.idk,TYPE>,SHARED_LIBRARY>:ZTD_IDK_DLL=1>
${CMAKE_DL_LIBS}
)
if(ZTD_IDK_IS_TOP_LEVEL_PROJECT)
target_compile_options(ztd.idk
PRIVATE
${--utf8-literal-encoding}
${--utf8-source-encoding}
${--disable-permissive}
${--warn-pedantic}
${--warn-default}
${--warn-extra}
${--warn-errors}
)
endif()
install(TARGETS ztd.idk)
install(DIRECTORY include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
configure_package_config_file(
cmake/ztd.idk-config.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/cmake/ztd.idk/ztd.idk-config.cmake"
INSTALL_DESTINATION lib/cmake/ztd.idk
NO_CHECK_REQUIRED_COMPONENTS_MACRO
)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/cmake/ztd.idk/ztd.idk-config-version.cmake"
COMPATIBILITY SameMajorVersion
)
export(TARGETS ztd.idk
FILE
"${CMAKE_CURRENT_BINARY_DIR}/cmake/ztd.idk/ztd.idk-targets.cmake"
)
install(
DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/cmake"
TYPE DATA
)
if(ZTD_IDK_GENERATE_SINGLE)
add_subdirectory(single)
endif()
# # Benchmarks, Tests, Examples and Documentation
if(ZTD_IDK_TESTS)
include(CTest)
add_subdirectory(tests)
endif()
if(ZTD_IDK_DOCUMENTATION)
add_subdirectory(documentation)
endif()
if(ZTD_IDK_BENCHMARKS)
add_subdirectory(benchmarks)
endif()
if(ZTD_IDK_EXAMPLES)
add_subdirectory(examples)
endif()
# For quick debugging and development only: don't peek! 🙈
mark_as_advanced(ZTD_IDK_SCRATCH)
if(ZTD_IDK_SCRATCH)
add_executable(scratch main.cpp)
target_link_libraries(scratch PRIVATE ztd::idk)
target_include_directories(scratch PRIVATE tests/shared/include)
target_compile_options(scratch
PRIVATE
${--template-debugging-mode}
${--disable-permissive}
${--warn-pedantic}
${--warn-all}
${--warn-extra}
${--warn-errors})
endif()