-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
161 lines (131 loc) · 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
CMAKE_MINIMUM_REQUIRED(VERSION 3.0.0)
# Define the solutions name.
SET(NAME aggligator)
PROJECT(${NAME} C CXX) # CMAKE_CURRENT_SOURCE_DIR
# C/CXX compiler configurations.
SET(CMAKE_C_FLAGS "-fPIC -fvisibility=hidden -Wno-format -Wno-implicit-function-declaration")
SET(CMAKE_CXX_FLAGS "-fPIC -fvisibility=hidden -Wno-format -Wno-inconsistent-missing-override -Wno-pointer-bool-conversion -Wno-unsequenced -Wno-null-dereference -Wno-gnu-variable-sized-type-not-at-end -Wno-tautological-undefined-compare -Wno-deprecated-declarations")
# Configure predefined compilation macros.
ADD_DEFINITIONS(-DJEMALLOC)
# ENV.
SET(PLATFORM_DEBUG FALSE)
IF(CMAKE_BUILD_TYPE STREQUAL "Debug" OR BT MATCHES "Debug")
SET(PLATFORM_DEBUG TRUE)
ENDIF()
SET(PLATFORM_COMPILER_CLANG FALSE)
SET(PLATFORM_SYSTEM_LINUX FALSE)
SET(PLATFORM_SYSTEM_DARWIN FALSE)
IF(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
SET(PLATFORM_COMPILER_CLANG TRUE)
ENDIF()
IF(CMAKE_SYSTEM_NAME STREQUAL "Darwin" OR CMAKE_SYSTEM_NAME MATCHES "Darwin")
SET(PLATFORM_SYSTEM_DARWIN TRUE)
ELSE()
SET(PLATFORM_SYSTEM_LINUX TRUE)
ENDIF()
# C
IF(PLATFORM_DEBUG)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_DEBUG -g3")
ELSE()
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3")
ENDIF()
# C/CXX
IF(PLATFORM_DEBUG)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_DEBUG -g3")
ELSE()
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
ENDIF()
# When compiling only linux kernel distributions >= 5.10 and later,
# You can enable this macro to get the new io_uring asynchronous event driver model support.
# IF(PLATFORM_SYSTEM_LINUX)
# ADD_DEFINITIONS(-DBOOST_ASIO_HAS_IO_URING=1)
# ADD_DEFINITIONS(-DBOOST_ASIO_DISABLE_EPOLL=1)
# ENDIF()
# Check C/CXX compiler supports.
INCLUDE(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++17" COMPILER_SUPPORTS_CXX17)
CHECK_CXX_COMPILER_FLAG("-std=c++1z" COMPILER_SUPPORTS_CXX1Z)
# According to the type of operating system to determine whether you need to check whether the compiler supports C/C++17,
# On the MACOS system, the following check code is invalid, so directly specify the standard version of C/C++,
# If an error or compilation does not pass, it means that you need to upgrade the LLVM GCC/CLANG compiler installed on MACOS.
IF(PLATFORM_SYSTEM_DARWIN)
# The mandatory version is C++17.
SET(CMAKE_CXX_STANDARD 17)
ADD_DEFINITIONS(-D_GNU_SOURCE)
ADD_DEFINITIONS(-DBOOST_STACKTRACE_GNU_SOURCE_NOT_REQUIRED)
ELSE()
# CXX17
IF(COMPILER_SUPPORTS_CXX17)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
ELSEIF(COMPILER_SUPPORTS_CXX1Z)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1z")
ELSE()
MESSAGE(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++ 17 support. Please use a different C++ compiler.")
ENDIF()
# -rdynamic -Wl,-Bstatic -Wl,-Bdynamic -lstdc++ -lpthread -ldl -lz -lrt
SET(CMAKE_EXE_LINKER_FLAGS "-static-libstdc++ -rdynamic -Wl,-Bstatic")
ENDIF()
# Set the tripartite library directorys.
SET(THIRD_PARTY_LIBRARY_DIR /root/dev)
# Set the compiled header file search directorys.
INCLUDE_DIRECTORIES(
${PROJECT_SOURCE_DIR}/
${THIRD_PARTY_LIBRARY_DIR}/boost
${THIRD_PARTY_LIBRARY_DIR}/jemalloc/include
${THIRD_PARTY_LIBRARY_DIR}/openssl/include
)
# Set the third library connection directory to searchs.
LINK_DIRECTORIES(
${THIRD_PARTY_LIBRARY_DIR}/boost/stage/lib
${THIRD_PARTY_LIBRARY_DIR}/jemalloc/lib
${THIRD_PARTY_LIBRARY_DIR}/openssl
)
# List of common cpp source files compilations for aggligator/unix cmake solution projects.
FILE(GLOB_RECURSE SOURCE_FILES
${PROJECT_SOURCE_DIR}/main.cpp
${PROJECT_SOURCE_DIR}/DateTime.cpp
${PROJECT_SOURCE_DIR}/aggligator.cpp
)
# Add the compiled output binary files.
ADD_EXECUTABLE(${NAME} ${SOURCE_FILES} ${PLATFORM_SOURCE_FILES})
# Set the compilation output files path.
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
# Set up library connections to dependent libraries.
IF(PLATFORM_SYSTEM_DARWIN)
SET(BUILD_SHARED_LIBS ON) # System
TARGET_LINK_LIBRARIES(${NAME}
${THIRD_PARTY_LIBRARY_DIR}/openssl/libssl.a
${THIRD_PARTY_LIBRARY_DIR}/openssl/libcrypto.a
${THIRD_PARTY_LIBRARY_DIR}/jemalloc/lib/libjemalloc.a
dl
pthread
${THIRD_PARTY_LIBRARY_DIR}/boost/stage/lib/libboost_system.a
${THIRD_PARTY_LIBRARY_DIR}/boost/stage/lib/libboost_coroutine.a
${THIRD_PARTY_LIBRARY_DIR}/boost/stage/lib/libboost_context.a)
ELSEIF(PLATFORM_COMPILER_CLANG)
SET(BUILD_SHARED_LIBS ON)
TARGET_LINK_LIBRARIES(${NAME}
libssl.a
libcrypto.a
libjemalloc.a
# liburing.a
atomic
dl
pthread
libboost_system.a
libboost_coroutine.a
libboost_context.a)
ELSE()
TARGET_LINK_LIBRARIES(${NAME}
libc.a
libssl.a
libcrypto.a
libjemalloc.a
# liburing.a
atomic
dl
pthread
libboost_system.a
libboost_coroutine.a
libboost_context.a)
ENDIF()