-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
319 lines (209 loc) · 7.86 KB
/
Copy pathCMakeLists.txt
File metadata and controls
319 lines (209 loc) · 7.86 KB
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
# ######################################################################## #
# File: /CMakeLists.txt
#
# Purpose: Top-level CMake lists file for b64
#
# Created: 6th February 2024
# Updated: 30th July 2026
#
# ######################################################################## #
# ##########################################################
# CMake
cmake_minimum_required(VERSION 3.20 FATAL_ERROR)
# require out-of-source builds
file(TO_CMAKE_PATH "${CMAKE_CURRENT_BINARY_DIR}/CMakeLists.txt" LOC_PATH)
if(EXISTS "${LOC_PATH}")
message(FATAL_ERROR "You cannot build in a source directory (or any directory with a CMakeLists.txt file). Please make a build subdirectory. Feel free to remove CMakeCache.txt and CMakeFiles.")
endif()
# directory for CMake specific extensions and source files.
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
# ##########################################################
# project
project(b64
DESCRIPTION "b64 is a small, standalone library, that provides extensible C-style string instances and extensible arrays of such."
HOMEPAGE_URL "https://github.com/synesissoftware/b64"
LANGUAGES C CXX
)
string(TOLOWER ${PROJECT_NAME} PROJECT_NAME_LOWER)
string(TOUPPER ${PROJECT_NAME} PROJECT_NAME_UPPER)
# handle version number
set(RX_PROJ_TAG "${PROJECT_NAME_UPPER}")
set(RX_WS "[ \t]")
file(READ "${CMAKE_SOURCE_DIR}/include/${PROJECT_NAME_LOWER}/${PROJECT_NAME_LOWER}.h" _header_file)
string(REGEX MATCH "#${RX_WS}*define${RX_WS}+_?${RX_PROJ_TAG}_VER_MAJOR${RX_WS}+([0-9]+)" MAJOR_DUMMY ${_header_file})
set(_VERSION_MAJOR ${CMAKE_MATCH_1})
string(REGEX MATCH "#${RX_WS}*define${RX_WS}+_?${RX_PROJ_TAG}_VER_MINOR${RX_WS}+([0-9]+)" MINOR_DUMMY ${_header_file})
set(_VERSION_MINOR ${CMAKE_MATCH_1})
string(REGEX MATCH "#${RX_WS}*define${RX_WS}+_?${RX_PROJ_TAG}_VER_(PATCH|REVISION)${RX_WS}+([0-9]+)" PATCH_DUMMY ${_header_file})
set(_VERSION_PATCH ${CMAKE_MATCH_2})
# set project version number here
set(PROJECT_VERSION_MAJOR ${_VERSION_MAJOR})
set(PROJECT_VERSION_MINOR ${_VERSION_MINOR})
set(PROJECT_VERSION_PATCH ${_VERSION_PATCH})
set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")
# adhere strictly to C and C++ standards plus extensions. These are actually
# useless since we do not compile anything; they merely state our intention.
set(CMAKE_C_STANDARD 17)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS ON) # GNU extensions and POSIX standard
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS ON)
if(MSVC)
if(MSVC_VERSION LESS 1800)
add_compile_options("/wd4996")
endif()
if(MSVC_VERSION LESS 1930)
set(CMAKE_C_STANDARD 90)
set(CMAKE_CXX_STANDARD 98)
endif()
if(MSVC_USE_MT)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif(MSVC_USE_MT)
else(MSVC)
if(MSVC_USE_MT)
# this here just to absorb warning about not using `MSVC_USE_MT` (to
# enable **prepare_cmake.sh** to be simple)
endif(MSVC_USE_MT)
endif(MSVC)
# ##########################################################
# dependencies, includes, options
# ################################################
# includes - 1
include(BuildType)
include(LanguageFullVersion)
include(TargetMacros)
# ################################################
# dependencies, features, and options
# ######################################
# options
option(BUILD_EXAMPLES "Build examples" ON)
option(BUILD_TESTING "Build tests" ON)
# ######################################
# features
# ######################################
# dependencies
#
# required:
# - xTests - required for testing;
#
# optional:
# - STLSoft - required unless NO_B64_CPP_API is specified, and by xTests
# (for testing);
# - shwild - for enhanced match constructs in xTests;
# ############################
# STLSoft
if(BUILD_TESTING OR NOT NO_B64_CPP_API)
if(NOT DEFINED STLSOFT AND NOT DEFINED ENV{STLSOFT})
set(STLSoft_REQUIRED_VERSION_ 1.11)
find_package(STLSoft ${STLSoft_REQUIRED_VERSION_} REQUIRED)
message("-- CMake package STLSoft found (version ${STLSoft_VERSION}; ${STLSoft_REQUIRED_VERSION_} requested)")
else()
if(DEFINED STLSOFT)
message("-- STLSOFT provided as CMake variable with value '${STLSOFT}'")
set(STLSOFT_INCLUDE_DIR ${STLSOFT}/include)
else()
message("-- STLSOFT provided as environment variable with value '$ENV{STLSOFT}'")
set(STLSOFT_INCLUDE_DIR $ENV{STLSOFT}/include)
endif()
get_filename_component(STLSOFT_INCLUDE_DIR "${STLSOFT_INCLUDE_DIR}" ABSOLUTE)
include_directories(${STLSOFT_INCLUDE_DIR})
endif()
endif()
# ############################
# shwild (optional)
if(NOT (NO_SHWILD))
if(BUILD_TESTING)
find_package(shwild QUIET)
if(shwild_FOUND)
message("-- CMake package shwild found (version ${shwild_VERSION})")
add_compile_definitions(XTESTS_HAS_SHWILD)
endif(shwild_FOUND)
endif(BUILD_TESTING)
endif()
# ############################
# xTests
if(BUILD_TESTING)
set(xTests_REQUIRED_VERSION_ 0.26.3)
find_package(xTests ${xTests_REQUIRED_VERSION_} REQUIRED)
message("-- CMake package xTests found (version ${xTests_VERSION}; ${xTests_REQUIRED_VERSION_} requested)")
endif(BUILD_TESTING)
# ################################################
# includes - 2
include(CMakePackageConfigHelpers)
if(BUILD_TESTING)
include(CTest)
endif(BUILD_TESTING)
include(GNUInstallDirs)
# ##########################################################
# targets
# ################################################
# custom definitions
if(UNIX)
set(_BUILD_AS_UNIX 1)
message("-- Operating system Unix")
else(UNIX)
if(WIN32)
if(USE_UNIXEM)
set(_BUILD_AS_UNIX 1)
message("-- Operating system Unix (synthesised on Windows)")
else(USE_UNIXEM)
set(_BUILD_AS_WIN32 1)
message("-- Operating system Windows")
endif(USE_UNIXEM)
else(WIN32)
message("-- Operating system unknown")
endif(WIN32)
endif(UNIX)
# ################################################
# main libraries
add_subdirectory(src)
# ################################################
# examples
if(BUILD_EXAMPLES)
message("-- enabled building of examples ...")
add_subdirectory(examples)
else(BUILD_EXAMPLES)
message("-- disabled building of examples - define BUILD_EXAMPLES to enable")
endif(BUILD_EXAMPLES)
# ################################################
# tests
if(BUILD_TESTING)
message("-- enabled building of tests ...")
add_subdirectory(test)
else(BUILD_TESTING)
message("-- disabled building of tests - define BUILD_TESTING to enable")
endif(BUILD_TESTING)
# ##########################################################
# install
# ##########################################################
# export
set(EXPORT_NAME ${PROJECT_NAME_LOWER})
configure_package_config_file(
${CMAKE_CURRENT_SOURCE_DIR}/cmake/${EXPORT_NAME}-config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/cmake/${EXPORT_NAME}-config.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/${EXPORT_NAME}/cmake
)
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/cmake/${EXPORT_NAME}-config-version.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)
export(EXPORT project-targets
FILE "${CMAKE_CURRENT_BINARY_DIR}/cmake/${EXPORT_NAME}-targets.cmake"
NAMESPACE "${PROJECT_NAME}::"
)
install(EXPORT project-targets
NAMESPACE "${PROJECT_NAME}::"
FILE "${EXPORT_NAME}-targets.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${EXPORT_NAME}
)
install( FILES
"${CMAKE_CURRENT_BINARY_DIR}/cmake/${EXPORT_NAME}-config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/cmake/${EXPORT_NAME}-config-version.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${EXPORT_NAME}
)
# ##########################################################
# completion
message(NOTICE "Generating CMake build scripts for ${PROJECT_NAME} ${PROJECT_VERSION}, for C${CMAKE_C_STANDARD} C++${CMAKE_CXX_STANDARD}, with build type ${CMAKE_BUILD_TYPE}")
# ############################## end of file ############################# #