-
-
Notifications
You must be signed in to change notification settings - Fork 26
/
CMakeLists.txt
297 lines (266 loc) · 10.5 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
# =============================================================================
#
# ztd.text
# Copyright © JeanHeyd "ThePhD" Meneide and Shepherd's Oasis, LLC
# Contact: [email protected]
#
# Commercial License Usage
# Licensees holding valid commercial ztd.text 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_SHALLOW ON
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.text
VERSION 0.4.0
DESCRIPTION "A spicy text library."
HOMEPAGE_URL "https://ztdtext.readthedocs.io/en/latest/"
LANGUAGES C CXX)
if(ZTD_TEXT_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_TEXT_IS_TOP_LEVEL_PROJECT YES)
else()
set(ZTD_TEXT_IS_TOP_LEVEL_PROJECT NO)
endif()
# Modify bad flags / change defaults if we are the top level
if(ZTD_TEXT_IS_TOP_LEVEL_PROJECT)
ztd_tools_top_level_project_config()
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_TEXT_BENCHMARKS OR ZTD_TEXT_EXAMPLES OR ZTD_TEXT_TESTS OR ZTD_TEXT_SCRATCH)
# normal flags
check_compiler_flag(disable-permissive MSVC /permissive- GCC -pedantic)
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 LANGUAGES CXX)
check_compiler_flag(extra-constexpr-steps MSVC /constexpr:steps2147483647 GCC -fconstexpr-ops-limit=2147483647 Clang -fconstexpr-steps=2147483647 LANGUAGES CXX)
check_compiler_flag(template-debugging-mode GCC -ftemplate-backtrace-limit=0 LANGUAGES CXX)
# Warning flags
check_compiler_flag(warn-pedantic MSVC /permissive- GCC -pedantic)
check_compiler_flag(warn-all MSVC /W4 GCC -Wall)
check_compiler_flag(warn-none MSVC /W0 GCC -w Clang -w)
check_compiler_flag(warn-errors MSVC /WX GCC -Werror)
check_compiler_flag(warn-extra GCC -Wextra Clang -Wextra)
check_compiler_diagnostic(alignas-extra-padding MSVC 4324 LANGUAGES CXX)
check_compiler_diagnostic(bit-int-extension)
# (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()
# # Options
option(ZTD_TEXT_CI "Whether or not we are in continuous integration mode" OFF)
option(ZTD_TEXT_READTHEDOCS "Whether or not we are building inside of ReadTheDocs" OFF)
option(ZTD_TEXT_TESTS "Enable build of tests" OFF)
option(ZTD_TEXT_DOCUMENTATION "Enable build of documentation" OFF)
option(ZTD_TEXT_DOCUMENTATION_NO_SPHINX "Turn off Sphinx usage (useful for ReadTheDocs builds)" OFF)
option(ZTD_TEXT_GENERATE_SINGLE "Enable generation of a single header and its target" OFF)
option(ZTD_TEXT_BOOST.TEXT "Enable Boost.Text-dependent benchmarking, examples, and similar if benchmarking and/or examples are turned on." OFF)
option(ZTD_TEXT_ICU "Enable ICU-dependent benchmarking, examples, and similar if benchmarking and/or examples are turned on." OFF)
option(ZTD_TEXT_LIBICONV "Enable libiconv-dependent benchmarking, examples, and similar if benchmarking and/or examples are turned on." OFF)
option(ZTD_TEXT_EXAMPLES "Enable build of examples" OFF)
cmake_dependent_option(ZTD_TEXT_EXAMPLES_BOOST.TEXT "Enable usage of Boost.Text in examples" ON "ZTD_TEXT_EXAMPLES;ZTD_TEXT_BOOST.TEXT" OFF)
option(ZTD_TEXT_BENCHMARKS "Enable build of benchmarks" OFF)
cmake_dependent_option(ZTD_TEXT_BENCHMARKS_INTERNALS "Enable benchmarking for basic and internal-specific functionality" ON "ZTD_TEXT_BENCHMARKS" OFF)
cmake_dependent_option(ZTD_TEXT_BENCHMARKS_BOOST.TEXT "Enable benchmarking for Boost.Text" ON "ZTD_TEXT_BENCHMARKS;ZTD_TEXT_BOOST.TEXT" OFF)
cmake_dependent_option(ZTD_TEXT_BENCHMARKS_ICU "Enable benchmarking for ICU" ON "ZTD_TEXT_BENCHMARKS;ZTD_TEXT_ICU" OFF)
cmake_dependent_option(ZTD_TEXT_BENCHMARKS_LIBICONV "Enable benchmarking for libiconv" ON "ZTD_TEXT_BENCHMARKS;ZTD_TEXT_LIBICONV" OFF)
# # Dependencies
# ztd.idk
FetchContent_Declare(ztd.idk
GIT_REPOSITORY https://github.com/soasis/idk.git
GIT_SHALLOW ON
GIT_TAG main)
FetchContent_MakeAvailable(ztd.idk)
# ztd.static_containers
FetchContent_Declare(ztd.static_containers
GIT_REPOSITORY https://github.com/soasis/static_containers.git
GIT_SHALLOW ON
GIT_TAG main)
FetchContent_MakeAvailable(ztd.static_containers)
# ztd.encoding_tables
FetchContent_Declare(ztd.encoding_tables
GIT_REPOSITORY https://github.com/soasis/encoding_tables.git
GIT_SHALLOW ON
GIT_TAG main)
FetchContent_MakeAvailable(ztd.encoding_tables)
# ztd.cuneicode
set(ZTD_CUNEICODE_SIMDUTF_SHARED ${ZTD_TEXT_BENCHMARKS})
FetchContent_Declare(ztd.cuneicode
GIT_REPOSITORY https://github.com/soasis/cuneicode.git
GIT_SHALLOW ON
GIT_TAG main)
FetchContent_MakeAvailable(ztd.cuneicode)
# ztd.platform
FetchContent_Declare(ztd.platform
GIT_REPOSITORY https://github.com/soasis/platform.git
GIT_SHALLOW ON
GIT_TAG main)
FetchContent_MakeAvailable(ztd.platform)
if (ZTD_TEXT_BENCHAMRKS OR ZTD_TEXT_GENERATE_SINGLE OR ZTD_TEXT_DOCUMENTATION)
find_package(Python3 REQUIRED COMPONENTS Interpreter)
endif()
# Main library declarations
file(GLOB_RECURSE ztd.text.includes CONFIGURE_DEPENDS include/*.hpp)
add_library(ztd.text INTERFACE)
add_library(ztd::text ALIAS ztd.text)
target_include_directories(ztd.text
INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
target_sources(ztd.text INTERFACE ${ztd.text.includes})
target_link_libraries(ztd.text
INTERFACE
ztd::idk
ztd::static_containers
ztd::platform
ztd::cuneicode)
install(DIRECTORY include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
# # Config / Version packaging
# Version configurations
configure_package_config_file(
cmake/ztd.text-config.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/cmake/ztd.text/ztd.text-config.cmake"
INSTALL_DESTINATION lib/cmake/ztd.text
NO_CHECK_REQUIRED_COMPONENTS_MACRO)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/cmake/ztd.text/ztd.text-config-version.cmake"
COMPATIBILITY SameMajorVersion)
export(TARGETS ztd.text
FILE
"${CMAKE_CURRENT_BINARY_DIR}/cmake/ztd.text/ztd.text-targets.cmake")
if(ZTD_TEXT_GENERATE_SINGLE)
add_subdirectory(single)
endif()
# # Benchmarks, Tests, Examples and Documentation
# Example and/or benchmark dependencies
if (ZTD_TEXT_EXAMPLES OR ZTD_TEXT_BENCHMARKS)
# # Fetch dependencies for either benchmarks and/or examples
function(simdutf_dependency_jail)
# simdutf
set(SIMDUTF_BENCHMARKS OFF)
set(SIMDUTF_SINGLE_HEADER OFF)
set(SIMDUTF_TESTS OFF)
set(SIMDUTF_TOOLS OFF)
set(BUILD_TESTING OFF)
FetchContent_Declare(
simdutf
GIT_REPOSITORY https://github.com/simdutf/simdutf
GIT_SHALLOW ON
GIT_TAG master
EXCLUDE_FROM_ALL)
FetchContent_MakeAvailable(simdutf)
endfunction()
simdutf_dependency_jail()
function(boost_text_dependency_jail)
# boost.text
set(BOOST_TEXT_PERF OFF)
set(BOOST_TEXT_EXAMPLES OFF)
set(BOOST_TEXT_TESTS OFF)
set(BOOST_TEXT_INSTALL OFF)
set(BUILD_TESTING OFF)
FetchContent_Declare(
boost.text
GIT_REPOSITORY https://github.com/ThePhD/text
GIT_SHALLOW ON
GIT_TAG master
EXCLUDE_FROM_ALL)
FetchContent_MakeAvailable(boost.text)
endfunction()
if (ZTD_TEXT_BOOST.TEXT)
boost_text_dependency_jail()
endif()
endif()
if(ZTD_TEXT_TESTS)
include(CTest)
add_subdirectory(tests)
endif()
if(ZTD_TEXT_DOCUMENTATION)
add_subdirectory(documentation)
endif()
if(ZTD_TEXT_BENCHMARKS)
add_subdirectory(benchmarks)
endif()
if(ZTD_TEXT_EXAMPLES)
add_subdirectory(examples)
endif()
# For quick debugging and development only: don't peek! 🙈
mark_as_advanced(ZTD_TEXT_SCRATCH)
if(ZTD_TEXT_SCRATCH)
add_executable(scratch main.cpp)
target_link_libraries(scratch
PRIVATE
ztd::text
)
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}
)
target_compile_definitions(scratch
PRIVATE
ZTD_ASSERT_CHECKS=1
)
endif()