-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathCMakeLists.txt
442 lines (345 loc) · 13.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
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
cmake_minimum_required(VERSION 3.13 FATAL_ERROR)
#-----------------------------------------------------------------
# The project
#-----------------------------------------------------------------
project (SolidFrame VERSION 12.2)
message("SolidFrame version: ${PROJECT_VERSION} - ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}")
#-----------------------------------------------------------------
# Set policies
#-----------------------------------------------------------------
cmake_policy(SET CMP0074 NEW)
#-----------------------------------------------------------------
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
#-----------------------------------------------------------------
# Extra user definitions
#-----------------------------------------------------------------
set(EXTRA_COMPILE_OPTIONS "" CACHE STRING "Extra compiler options")
add_compile_options("SHELL: ${EXTRA_COMPILE_OPTIONS}")
set(EXTRA_LINK_OPTIONS "" CACHE STRING "Extra linker options")
add_link_options("SHELL: ${EXTRA_LINK_OPTIONS}")
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
find_package(Threads REQUIRED)
#-----------------------------------------------------------------
# C++ Standard
#-----------------------------------------------------------------
if(NOT CMAKE_CXX_STANDARD)
file (READ "${CMAKE_CURRENT_SOURCE_DIR}/cmake/check/cpp20.cpp" source_code)
set(CMAKE_CXX_STANDARD 20)
include(CheckCXXSourceCompiles)
CHECK_CXX_SOURCE_COMPILES("${source_code}" SOLID_COMPILE_CXX20)
if(NOT SOLID_COMPILE_CXX20)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
file (READ "${CMAKE_CURRENT_SOURCE_DIR}/cmake/check/cpp17.cpp" source_code)
CHECK_CXX_SOURCE_COMPILES("${source_code}" SOLID_COMPILE_CXX17)
if(NOT SOLID_COMPILE_CXX17)
message(FATAL_ERROR "SolidFrame needs at least CXX17!")
endif()
endif()
endif()
message("C++ Standard: ${CMAKE_CXX_STANDARD}")
set(CMAKE_CXX_STANDARD_REQUIRED ON)
#-----------------------------------------------------------------
# Prepare the external path
#-----------------------------------------------------------------
set(EXTERNAL_DIR "" CACHE PATH "External dependencies directory")
set(FORTIFY "ON" CACHE BOOL "Fortify C++")
message("Install directory: \"${CMAKE_INSTALL_PREFIX}\"")
message("External directory: \"${EXTERNAL_DIR}\"")
message("Fortify: \"${FORTIFY}\"")
list(APPEND CMAKE_PREFIX_PATH ${EXTERNAL_PATH})
#-----------------------------------------------------------------
# Prepare the definitions for build types
#-----------------------------------------------------------------
if(NOT CMAKE_BUILD_TYPE)
message(STATUS "Setting build type to 'release' as none was specified.")
set(CMAKE_BUILD_TYPE "release" CACHE STRING "Choose the type of build." FORCE)
# Set the possible values of build type for cmake-gui
if(CMAKE_SYSTEM MATCHES "Windows*")
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
"release" "debug" "maintain" "custom")
else()
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
"release" "debug" "maintain" "custom" "coverage")
endif()
endif()
string(TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE)
if(CMAKE_BUILD_TYPE STREQUAL "release")
#force a single configuration type on Windows builds
set(CMAKE_CONFIGURATION_TYPES "release")
set(CONFIGURATION_TYPE "release")
set(SOLID_HAS_STATISTICS TRUE)
endif()
if(CMAKE_BUILD_TYPE STREQUAL "maintain")
#set(CMAKE_VERBOSE_MAKEFILE ON)
set(SOLID_HAS_DEBUG TRUE)
set(SOLID_HAS_STATISTICS TRUE)
set(SOLID_HAS_ASSERT TRUE)
#force a single configuration type on Windows builds
set(CMAKE_CONFIGURATION_TYPES "RelWithDebInfo")
set(CONFIGURATION_TYPE "RelWithDebInfo")
endif()
if(CMAKE_BUILD_TYPE STREQUAL "debug")
#set(CMAKE_VERBOSE_MAKEFILE ON)
set(SOLID_HAS_DEBUG TRUE)
set(SOLID_HAS_NO_INLINES TRUE)
set(SOLID_HAS_STATISTICS TRUE)
set(SOLID_HAS_ASSERT TRUE)
#force a single configuration type on Windows builds
set(CMAKE_CONFIGURATION_TYPES "debug")
set(CONFIGURATION_TYPE "debug")
endif()
if((NOT CMAKE_SYSTEM MATCHES "Windows*") AND CMAKE_BUILD_TYPE STREQUAL "coverage")
#set(CMAKE_VERBOSE_MAKEFILE ON)
set(SOLID_HAS_DEBUG TRUE)
set(SOLID_HAS_NO_INLINES TRUE)
set(SOLID_HAS_STATISTICS TRUE)
set(SOLID_HAS_ASSERT TRUE)
#force a single configuration type on Windows builds
set(CMAKE_CONFIGURATION_TYPES "debug")
set(CONFIGURATION_TYPE "debug")
add_compile_options("SHELL: -coverage -fprofile-arcs -ftest-coverage")
add_link_options("SHELL: -fprofile-arcs -ftest-coverage")
elseif(CMAKE_SYSTEM MATCHES "Windows*" AND CMAKE_BUILD_TYPE STREQUAL "coverage")
message(FATAL_ERROR "\r\n === Coverage not yet supported for Windows systems ===\r\n")
endif()
if(CMAKE_BUILD_TYPE STREQUAL "custom")
#force a single configuration type on Windows builds
set(CMAKE_CONFIGURATION_TYPES "custom")
set(CONFIGURATION_TYPE "custom")
endif()
set(CMAKE_CONFIGURATION_TYPES "${CMAKE_CONFIGURATION_TYPES}" CACHE STRING
"Add the native configuration"
FORCE)
mark_as_advanced(CMAKE_CONFIGURATION_TYPES)
set(SOLID_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
set(SOLID_VERSION_MINOR ${PROJECT_VERSION_MINOR})
set(SOLID_VERSION_PATCH ${PROJECT_VERSION_PATCH})
set(SYSTEM_BASIC_LIBRARIES "")
option(SOLID_FRAME_AIO_REACTOR_USE_SPINLOCK "Use SpinLock on AIO Reactor" ON)
option(SOLID_MPRPC_USE_SHARED_PTR_MESSAGE "Use std::shared_ptr with mprpc::Message" OFF)
#-----------------------------------------------------------------
# Per OS configuration
#-----------------------------------------------------------------
message("")
message("CMake's system: ${CMAKE_SYSTEM}")
message("")
set(ON_FOUND FALSE)
set(SOLID_ON_FREEBSD FALSE)
set(SOLID_ON_DARWIN FALSE)
set(SOLID_ON_LINUX FALSE)
set(SOLID_ON_POSIX FALSE)
set(SOLID_ON_SOLARIS FALSE)
set(SOLID_ON_WINDOWS FALSE)
if(CMAKE_SYSTEM MATCHES "FreeBSD*")
message("Detected system ON_FREEBSD")
set(ON_FOUND TRUE)
set(SOLID_ON_FREEBSD TRUE)
set(SOLID_ON_POSIX TRUE)
add_compile_options(
"$<$<CONFIG:MAINTAIN>:SHELL: ${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -Wall -Wshorten-64-to-32 -Wunreachable-code -Wconditional-uninitialized>"
"$<$<CONFIG:CUSTOM>:>"
)
set(SYSTEM_BASIC_LIBRARIES pmc rt Threads::Threads)
find_library(EXECINFO_LIBRARY NAMES execinfo)
if(EXECINFO_LIBRARY)
message("Execinfo library found: ${EXECINFO_LIBRARY}")
list(APPEND SYSTEM_BASIC_LIBRARIES ${EXECINFO_LIBRARY})
endif()
endif()
if(CMAKE_SYSTEM MATCHES "Darwin*")
message("Detected system ON_DARWIN")
set(ON_FOUND TRUE)
set(SOLID_ON_DARWIN TRUE)
set(SOLID_ON_POSIX TRUE)
add_compile_options(
"$<$<CONFIG:MAINTAIN>:SHELL: ${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -Wall -Wshorten-64-to-32 -Wunreachable-code -Wconditional-uninitialized -Wabi>"
"$<$<CONFIG:CUSTOM>:>"
)
string(APPEND CMAKE_EXE_LINKER_FLAGS "-framework ApplicationServices -framework CoreFoundation")
set(SYSTEM_BASIC_LIBRARIES Threads::Threads)
endif()
if(CMAKE_SYSTEM MATCHES "Linux*")
message("Detected system ON_LINUX")
set(ON_FOUND TRUE)
set(SOLID_ON_LINUX TRUE)
set(SOLID_ON_POSIX TRUE)
if(CMAKE_BUILD_TYPE STREQUAL "coverage")
add_link_options("SHELL: -lgcov")
endif()
if(CMAKE_CXX_COMPILER MATCHES "clang")
add_compile_options(
"$<$<CONFIG:MAINTAIN>:SHELL: ${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -Wall -Wshorten-64-to-32 -Wunreachable-code -Wconditional-uninitialized -Wdelete-non-virtual-dtor -Wnon-virtual-dtor>"
"$<$<CONFIG:CUSTOM>:>"
)
else()
add_compile_options(
"$<$<CONFIG:MAINTAIN>:SHELL: ${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -Wall -Wdelete-non-virtual-dtor -Wnon-virtual-dtor>"
"$<$<CONFIG:CUSTOM>:>"
)
endif()
set(SYSTEM_BASIC_LIBRARIES Threads::Threads rt)
find_library(ATOMIC_LIBRARY NAMES atomic atomic.so.1 libatomic.so.1)
if(ATOMIC_LIBRARY)
message("Atomic library found: ${ATOMIC_LIBRARY}")
list(APPEND SYSTEM_BASIC_LIBRARIES atomic)
endif()
endif()
if(CMAKE_SYSTEM MATCHES "Windows*")
message("Detected system ON_WINDOWS")
set(ON_FOUND TRUE)
set(SOLID_ON_WINDOWS TRUE)
add_compile_options(
#"$<$<CONFIG:RELASE>:/D_CRT_SECURE_NO_WARNINGS;/Ox>"
#"$<$<CONFIG:DEBUG>:/D_CRT_SECURE_NO_WARNINGS;/Zi;/Od>"
"$<$<CONFIG:MAINTAIN>:/D_CRT_SECURE_NO_WARNINGS;/Zi;/Od>"
"$<$<CONFIG:CUSTOM>:>"
)
add_compile_options(-D_WIN32_WINNT=0x0601 -DWINVER=0x0601)
endif(CMAKE_SYSTEM MATCHES "Windows*")
if(CMAKE_SYSTEM MATCHES "Android*")
message("Detected system ON_ANDROID")
set(ON_FOUND TRUE)
set(ON_CROSS TRUE)
set(ON_ANDROID TRUE)
set(SOLID_ON_LINUX TRUE)
set(SOLID_ON_POSIX TRUE)
set(SOLID_USE_GCC_BSWAP TRUE)
set(NO_EXTERNAL TRUE)
add_compile_options(
"$<$<CONFIG:MAINTAIN>:SHELL: ${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -Wall>"
"$<$<CONFIG:CUSTOM>:>"
)
set(SYSTEM_BASIC_LIBRARIES rt)
endif()
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm")
add_compile_options("SHELL: -mcpu=native")
endif()
if(NOT ON_FOUND)
message(FATAL_ERROR "\r\n === Unsupported system - please contact project owner ===\r\n")
endif(NOT ON_FOUND)
if(FORTIFY AND (SOLID_ON_LINUX OR SOLID_ON_FREEBSD OR SOLID_ON_DARWIN))
message("Fortifying C++")
include(CheckCXXSymbolExists)
if(cxx_std_20 IN_LIST CMAKE_CXX_COMPILE_FEATURES)
set(header version)
else()
set(header ciso646)
endif()
check_cxx_symbol_exists(_LIBCPP_VERSION ${header} LIBCPP)
if(LIBCPP)
# Logic for libc++
endif()
check_cxx_symbol_exists(__GLIBCXX__ ${header} GLIBCXX)
if(GLIBCXX)
# Logic for libstdc++
add_compile_options(
#-fpie -Wl,-pie
#-fpic -shared
"$<$<CONFIG:MAINTAIN>:SHELL: -D_FORTIFY_SOURCE=2 -D_GLIBCXX_ASSERTIONS -pipe -fasynchronous-unwind-tables -fexceptions -fstack-clash-protection -fcf-protection -Wl,-z,relro>"
"$<$<CONFIG:DEBUG>:SHELL: -Wall -O2 -D_FORTIFY_SOURCE=2 -D_GLIBCXX_ASSERTIONS -pipe -fasynchronous-unwind-tables -fexceptions -fstack-clash-protection -fcf-protection -Wl,-z,relro>"
"$<$<CONFIG:RELEASE>:SHELL: -Wall -D_FORTIFY_SOURCE=2 -D_GLIBCXX_ASSERTIONS -pipe -fasynchronous-unwind-tables -fexceptions -fstack-clash-protection -fcf-protection -Wl,-z,relro>"
"$<$<CONFIG:CUSTOM>:>"
)
endif()
endif()
#-----------------------------------------------------------------
# Find external libraries
#-----------------------------------------------------------------
if(ON_ANDROID)
set(EXTERNAL_DIR "${EXTERNAL_DIR}/${ANDROID_ABI}")
endif()
if(NOT NO_EXTERNAL)
include(ExternalProject)
include(cmake/build-snappy.cmake)
include(cmake/build-cxxopts.cmake)
include_directories(${CMAKE_BINARY_DIR}/external/include)
if(EXTERNAL_DIR STREQUAL "" OR NOT EXISTS ${EXTERNAL_DIR})
set(EXTERNAL_DIR "${CMAKE_CURRENT_BINARY_DIR}/external")
include(cmake/build-openssl.cmake)
else()
#define dummy targets
add_custom_target(build-openssl)
include(cmake/find-openssl.cmake)
include_directories(${EXTERNAL_DIR}/include)
endif()
else()
set(OPENSSL_FOUND TRUE)
endif()
#-----------------------------------------------------------------
# config.h support
#-----------------------------------------------------------------
if(NOT ON_CROSS)
include(cmake/check.config.cmake)
elseif(ON_ANDROID)
set(SOLID_USE_EPOLL TRUE)
set(SOLID_USE_EVENTFD TRUE)
endif()
#-----------------------------------------------------------------
# Global include directories
#-----------------------------------------------------------------
include_directories(
"${SolidFrame_SOURCE_DIR}"
"${CMAKE_CURRENT_BINARY_DIR}"
)
#-----------------------------------------------------------------
# Global link directories
#-----------------------------------------------------------------
link_directories(
${EXTERNAL_DIR}/lib
)
#-----------------------------------------------------------------
# Static Analisys
#-----------------------------------------------------------------
include(cmake/clang-tidy.cmake)
#-----------------------------------------------------------------
# Testing support (CTest & CDash)
#-----------------------------------------------------------------
if(NOT ON_CROSS)
find_program( MEMORYCHECK_COMMAND valgrind )
set( MEMORYCHECK_COMMAND_OPTIONS "--trace-children=yes --leak-check=full" )
set( MEMORYCHECK_SUPPRESSIONS_FILE "${PROJECT_SOURCE_DIR}/cmake/valgrind_suppress.txt" )
set(SOLID_TEST_ALL TRUE CACHE BOOL "Enable/Disable all tests")
enable_testing()
include(CTest)
else()
set(SOLID_TEST_ALL FALSE)
endif()
#-----------------------------------------------------------------
# Project subdirectories
#-----------------------------------------------------------------
add_subdirectory (solid)
add_custom_target(libraries
DEPENDS
solid_system
solid_utility
solid_reflection_v1
solid_serialization_v3
solid_frame
solid_frame_aio
solid_frame_aio_openssl
solid_frame_file
solid_frame_mprpc
)
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/SolidFrameConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)
export(EXPORT SolidFrameConfig FILE SolidFrameConfig.cmake NAMESPACE SolidFrame::)
install(EXPORT SolidFrameConfig DESTINATION lib/cmake/SolidFrame COMPONENT Devel NAMESPACE SolidFrame::)
install(
FILES
"${CMAKE_CURRENT_BINARY_DIR}/SolidFrameConfigVersion.cmake"
DESTINATION
lib/cmake/SolidFrame
COMPONENT
Devel
)
if(NOT ON_CROSS)
add_subdirectory (examples)
add_subdirectory (tutorials)
endif()
include(cmake/clang-format.cmake)