-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathCMakeLists.txt
308 lines (279 loc) · 10.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
# =============================================================================
#
# ztd.cuneicode
# Copyright © JeanHeyd "ThePhD" Meneide and Shepherd's Oasis, LLC
# Contact: [email protected]
#
# Commercial License Usage
# Licensees holding valid commercial ztd.cuneicode 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"); 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_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.cuneicode
VERSION 0.0.0
DESCRIPTION "A spicy text library for C."
HOMEPAGE_URL "https://ztdcuneicode.readthedocs.io/en/latest/"
LANGUAGES C CXX)
if(ZTD_CUNEICODE_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_CUNEICODE_IS_TOP_LEVEL_PROJECT YES)
else()
set(ZTD_CUNEICODE_IS_TOP_LEVEL_PROJECT NO)
endif()
# Modify bad flags / change defaults if we are the top level
if(ZTD_CUNEICODE_IS_TOP_LEVEL_PROJECT)
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/x86/${CMAKE_BUILD_TYPE}/lib")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/x86/${CMAKE_BUILD_TYPE}/bin")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/x86/${CMAKE_BUILD_TYPE}/bin")
else()
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/x64/${CMAKE_BUILD_TYPE}/lib")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/x64/${CMAKE_BUILD_TYPE}/bin")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/x64/${CMAKE_BUILD_TYPE}/bin")
endif()
if(NOT DEFINED CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 17)
endif()
if(NOT DEFINED CMAKE_C_STANDARD)
set(CMAKE_C_STANDARD 23)
endif()
if(ZTD_CUNEICODE_BENCHMARKS OR ZTD_CUNEICODE_EXAMPLES OR ZTD_CUNEICODE_TESTS OR ZTD_CUNEICODE_SCRATCH)
# normal flags
check_compiler_flag(disable-permissive MSVC /permissive- GCC -pedantic)
check_compiler_flag(updated-cpp-version-flag LANGUAGES CXX MSVC /Zc:__cplusplus Clang -fdoesnotexist GCC -fdoesnotexist)
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(enable-conforming-preprocessor MSVC /Zc:preprocessor Clang -fdoesnotexist GCC -fdoesnotexist)
check_compiler_flag(template-debugging-mode GCC -ftemplate-backtrace-limit=0)
check_compiler_flag(macro-debugging-mode GCC -fmacro-backtrace-limit=0)
# Warning flags
check_compiler_flag(warn-pedantic MSVC /permissive- GCC -pedantic)
check_compiler_flag(no-warn-pedantic MSVC /permissive- GCC -Wno-pedantic)
check_compiler_flag(no-pedantic MSVC /permissive- GCC -no-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)
# (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)
endif()
# Check for statement expression suppression
check_compiler_diagnostic(gnu-auto-type)
check_compiler_diagnostic(gnu-statement-expressions)
check_compiler_diagnostic(gnu-statement-expression-from-macro-expansion)
check_compiler_diagnostic(generic-type-extension)
endif()
endif()
# # Options
option(ZTD_CUNEICODE_CI "Whether or not we are in continuous integration mode" OFF)
option(ZTD_CUNEICODE_TESTS "Enable build of tests" OFF)
option(ZTD_CUNEICODE_DOCUMENTATION "Enable build of documentation" OFF)
option(ZTD_CUNEICODE_DOCUMENTATION_NO_SPHINX "Turn off Sphinx usage (useful for ReadTheDocs builds)" OFF)
option(ZTD_CUNEICODE_EXAMPLES "Enable build of examples" OFF)
option(ZTD_CUNEICODE_BENCHMARKS "Enable build of benchmarks" OFF)
set(ZTD_CUNEICODE_BENCHMARKS_REPETITIONS 50 CACHE STRING "Whole number of repetitions to run for all of ztd.cuneicode's benchmarks")
option(ZTD_CUNEICODE_GENERATE_SINGLE "Enable generation of a single header and its target" OFF)
option(ZTD_CUNEICODE_SIMDUTF_SHARED "Enable the simdutf shared target for cuneicode" OFF)
# # Dependencies
# ztd.idk
FetchContent_Declare(ztd.idk
GIT_REPOSITORY https://github.com/soasis/idk.git
GIT_TAG main)
FetchContent_MakeAvailable(ztd.idk)
# ztd.encoding_tables
FetchContent_Declare(ztd.encoding_tables
GIT_REPOSITORY https://github.com/soasis/encoding_tables.git
GIT_TAG main)
FetchContent_MakeAvailable(ztd.encoding_tables)
# # Main Library
file(GLOB ztd.cuneicode.includes CONFIGURE_DEPENDS include/*.hpp)
file(GLOB_RECURSE ztd.cuneicode.sources
LIST_DIRECTORIES FALSE
CONFIGURE_DEPENDS
source/*.c source/*.cpp)
add_library(ztd.cuneicode ${ztd.cuneicode.sources})
add_library(ztd::cuneicode ALIAS ztd.cuneicode)
target_include_directories(ztd.cuneicode
PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)
target_link_libraries(ztd.cuneicode
PUBLIC
ztd::idk
ztd::encoding_tables)
target_include_directories(ztd.cuneicode
PRIVATE ${PROJECT_SOURCE_DIR}/source/include)
target_compile_definitions(ztd.cuneicode
PRIVATE
_CRT_SECURE_NO_WARNINGS=1
ZTD_CUNEICODE_BUILD=1
PUBLIC
$<$<STREQUAL:$<TARGET_PROPERTY:ztd.cuneicode,TYPE>,SHARED_LIBRARY>:ZTD_CUNEICODE_DLL=1>
)
target_sources(ztd.cuneicode PRIVATE ${ztd.cuneicode.includes})
if(ZTD_CUNEICODE_IS_TOP_LEVEL_PROJECT)
target_compile_options(ztd.cuneicode PRIVATE
${--utf8-literal-encoding}
${--utf8-source-encoding}
${--disable-permissive}
${--updated-cpp-version-flag}
${--warn-pedantic}
${--warn-all}
${--warn-extra}
${--warn-errors}
)
endif()
target_compile_options(ztd.cuneicode PUBLIC
${--enable-conforming-preprocessor}
)
install(DIRECTORY include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
install(TARGETS ztd.cuneicode
PUBLIC_HEADER
RUNTIME
ARCHIVE
LIBRARY
)
# # Config / Version packaging
# Version configurations
configure_package_config_file(
cmake/ztd.cuneicode-config.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/cmake/ztd.cuneicode/ztd.cuneicode-config.cmake"
INSTALL_DESTINATION lib/cmake/ztd.cuneicode
NO_CHECK_REQUIRED_COMPONENTS_MACRO)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/cmake/ztd.cuneicode/ztd.cuneicode-config-version.cmake"
COMPATIBILITY SameMajorVersion)
export(TARGETS ztd.cuneicode
FILE
"${CMAKE_CURRENT_BINARY_DIR}/cmake/ztd.cuneicode/ztd.cuneicode-targets.cmake")
if(ZTD_CUNEICODE_GENERATE_SINGLE)
add_subdirectory(single)
endif()
# # Benchmarks, Tests, Examples
if (ZTD_CUNEICODE_BENCHMARKS)
# Python, for benchmarks
find_package(Python3)
endif()
if (ZTD_CUNEICODE_EXAMPLES OR ZTD_CUNEICODE_SIMDUTF_SHARED)
# # Fetch dependencies for either benchmarks and/or examples
function(simdutf_dependency_jail)
# simdutf
set(SIMDUTF_BENCHMARKS OFF)
set(SIMDUTF_TOOLS OFF)
set(SIMDUTF_SINGLE_HEADER OFF)
set(SIMDUTF_TESTS 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()
add_subdirectory(shared)
add_subdirectory(shared/simdutf)
endif()
if (ZTD_CUNEICODE_TESTS)
include(CTest)
add_subdirectory(tests)
endif()
if(ZTD_CUNEICODE_DOCUMENTATION)
add_subdirectory(documentation)
endif()
if(ZTD_CUNEICODE_BENCHMARKS)
add_subdirectory(benchmarks)
endif()
if(ZTD_CUNEICODE_EXAMPLES)
add_subdirectory(examples)
endif()
# For quick debugging and development only: don't peek! 🙈
mark_as_advanced(ZTD_CUNEICODE_SCRATCH)
if(ZTD_CUNEICODE_SCRATCH)
add_executable(scratch main.cpp)
add_executable(scratch_c main.c)
target_link_libraries(scratch PRIVATE ztd::cuneicode)
target_link_libraries(scratch_c PRIVATE ztd::cuneicode)
target_compile_options(scratch
PRIVATE
${--template-debugging-mode}
${--macro-debugging-mode}
${--updated-cpp-version-flag}
${--warn-pedantic}
${--warn-all}
${--warn-extra}
${--warn-errors}
${--enable-conforming-preprocessor}
${--allow-gnu-auto-type}
${--allow-gnu-statement-expressions}
${--allow-gnu-statement-expression-from-macro-expansion}
)
target_compile_options(scratch_c
PRIVATE
${--template-debugging-mode}
${--macro-debugging-mode}
${--updated-cpp-version-flag}
${--warn-pedantic}
${--warn-all}
${--warn-extra}
${--warn-errors}
${--enable-conforming-preprocessor}
${--allow-gnu-auto-type}
${--allow-gnu-statement-expressions}
${--allow-gnu-statement-expression-from-macro-expansion}
)
endif()