This repository has been archived by the owner on Jan 2, 2022. It is now read-only.
forked from zeroxs/aegis.cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
307 lines (237 loc) · 9.88 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
message(STATUS "CMake version: ${CMAKE_VERSION}")
cmake_minimum_required(VERSION 3.8)
file(READ ${CMAKE_CURRENT_SOURCE_DIR}/include/aegis/version.hpp version_hpp)
if (NOT version_hpp MATCHES "AEGIS_VERSION_SHORT ([0-9][0-9])([0-9][0-9])([0-9][0-9])")
message(FATAL_ERROR "Cannot get AEGIS_VERSION_SHORT from version.hpp. ${CMAKE_CURRENT_SOURCE_DIR}/include/aegis/version.hpp")
endif ()
math(EXPR AEGIS_VERSION_MAJOR ${CMAKE_MATCH_1})
math(EXPR AEGIS_VERSION_MINOR ${CMAKE_MATCH_2})
math(EXPR AEGIS_VERSION_PATCH ${CMAKE_MATCH_3})
string(CONCAT AEGIS_VERSION ${AEGIS_VERSION_MAJOR}.${AEGIS_VERSION_MINOR}.${AEGIS_VERSION_PATCH})
if(MSVC)
add_compile_options("/W3" "$<$<CONFIG:RELEASE>:/O2>")
else()
set(CMAKE_SHARED_LINKER_FLAGS ${CMAKE_SHARED_LINKER_FLAGS} "-Wl,--no-undefined")
set(AEGIS_CFLAGS -Wno-sign-compare -Wno-unknown-pragmas -Wno-unused-variable -Wno-noexcept-type -Wno-unused-result -Wno-unused-parameter -Wno-unused-but-set-variable -Wno-missing-field-initializers)
add_compile_options("$<$<CONFIG:RELEASE>:-O2>")
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
add_compile_options("-stdlib=libc++")
else()
# nothing special for gcc at the moment
endif()
endif()
project(libaegis VERSION ${AEGIS_VERSION} LANGUAGES CXX)
list(INSERT CMAKE_MODULE_PATH 0 ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
find_package(Asio 1.12.0 REQUIRED MODULE)
find_package(JSON 3.1.2 REQUIRED MODULE)
find_package(Spdlog 1.6.0 REQUIRED MODULE)
find_package(Websocketpp 0.7.0 REQUIRED MODULE)
find_package(OpenSSL 1.0.1 REQUIRED MODULE)
find_package(ZLIB REQUIRED MODULE)
set(REQUIRED_LIBS OpenSSL::SSL ZLIB::ZLIB Spdlog::Spdlog JSON::JSON Asio::Asio dl Threads::Threads)
option(BUILD_SHARED_LIBS "Build the shared library" ON)
option(BUILD_EXAMPLES "Build example programs" OFF)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin)
set(CMAKE_BUILD_TYPE Release)
set(AEGIS_FILES
include/aegis/impl/channel.cpp
include/aegis/impl/core.cpp
include/aegis/impl/guild.cpp
include/aegis/impl/user.cpp
include/aegis/impl/permission.cpp
include/aegis/impl/snowflake.cpp
include/aegis/rest/impl/rest_controller.cpp
include/aegis/shards/impl/shard.cpp
include/aegis/shards/impl/shard_mgr.cpp
include/aegis/gateway/objects/impl/message.cpp)
if (AEGIS_DEBUG_HISTORY)
set(AEGIS_FLAGS ${AEGIS_FLAGS} AEGIS_DEBUG_HISTORY)
endif ()
if (AEGIS_PROFILING)
set(AEGIS_FLAGS ${AEGIS_FLAGS} AEGIS_PROFILING)
endif ()
if (AEGIS_DISABLE_ALL_CACHE)
set(AEGIS_FLAGS ${AEGIS_FLAGS} AEGIS_DISABLE_ALL_CACHE)
endif ()
if (AEGIS_HAS_STD_OPTIONAL)
set(AEGIS_FLAGS ${AEGIS_FLAGS} AEGIS_HAS_STD_OPTIONAL)
endif ()
set(AEGIS_PACKAGE_INCLUDE_DIRS
$<BUILD_INTERFACE:${Asio_INCLUDE_DIR}>
$<BUILD_INTERFACE:${nlohmann_json_INCLUDE_DIR}>
$<BUILD_INTERFACE:${Spdlog_INCLUDE_DIR}>
$<BUILD_INTERFACE:${Websocketpp_INCLUDE_DIR}>
$<BUILD_INTERFACE:${OpenSSL_INCLUDE_DIR}>
$<BUILD_INTERFACE:${ZLIB_INCLUDE_DIR}>
)
include(GNUInstallDirs)
set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/Aegis)
install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
#SET(PKG_CONFIG_REQUIRES )
SET(PKG_CONFIG_LIBDIR
"\${prefix}/lib"
)
SET(PKG_CONFIG_INCLUDEDIR
"\${prefix}/include"
)
if (BUILD_SHARED_LIBS)
add_library(aegis SHARED ${AEGIS_FILES})
add_library(Aegis::aegis ALIAS aegis)
set_target_properties(aegis PROPERTIES POSITION_INDEPENDENT_CODE 1)
set_target_properties(aegis PROPERTIES SOVERSION 4)
set_target_properties(aegis PROPERTIES LINKER_LANGUAGE CXX)
target_compile_definitions(aegis PUBLIC AEGIS_DYN_LINK AEGIS_SOURCE ${AEGIS_FLAGS})
target_compile_definitions(aegis PRIVATE AEGIS_SOURCE)
target_link_libraries(aegis PUBLIC ${REQUIRED_LIBS})
target_include_directories(aegis
PUBLIC
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
${AEGIS_PACKAGE_INCLUDE_DIRS}
)
if ((CXX_STANDARD EQUAL "17") OR (CMAKE_CXX_STANDARD EQUAL "17"))
target_compile_features(aegis PUBLIC cxx_std_17)
set_target_properties(aegis PROPERTIES CXX_STANDARD 17)
else ()
target_compile_features(aegis PUBLIC cxx_std_14)
set_target_properties(aegis PROPERTIES CXX_STANDARD 14)
endif ()
set_target_properties(aegis PROPERTIES CXX_STANDARD_REQUIRED ON)
target_compile_options(aegis PRIVATE ${AEGIS_CFLAGS})
set_target_properties(aegis PROPERTIES EXPORT_NAME Aegis)
install(TARGETS aegis
EXPORT aegis-targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
SET(PKG_CONFIG_LIBS
"-L\${libdir} -laegis -lssl -lcrypto -lpthread -lz -ldl"
)
SET(PKG_CONFIG_CFLAGS
"-I/usr/include -I\${includedir} -I${Asio_INCLUDE_DIR} -I${JSON_INCLUDE_DIR} -I${Spdlog_INCLUDE_DIR} -I${Websocketpp_INCLUDE_DIR} -I${ZLIB_INCLUDE_DIR} -DAEGIS_DYN_LINK"
)
CONFIGURE_FILE(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/aegis.pc.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/aegis.pc"
)
INSTALL(FILES "${CMAKE_CURRENT_BINARY_DIR}/aegis.pc" DESTINATION lib/pkgconfig)
else ()
add_library(aegis_static STATIC ${AEGIS_FILES})
add_library(Aegis::aegis ALIAS aegis_static)
set_target_properties(aegis_static PROPERTIES OUTPUT_NAME "aegis")
set_target_properties(aegis_static PROPERTIES LINKER_LANGUAGE CXX)
target_compile_definitions(aegis_static PUBLIC AEGIS_SEPARATE_COMPILATION ${AEGIS_FLAGS})
target_link_libraries(aegis_static PUBLIC ${REQUIRED_LIBS})
target_include_directories(aegis_static
PUBLIC
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
${AEGIS_PACKAGE_INCLUDE_DIRS}
)
if ((CXX_STANDARD EQUAL "17") OR (CMAKE_CXX_STANDARD EQUAL "17"))
target_compile_features(aegis_static PUBLIC cxx_std_17)
set_target_properties(aegis_static PROPERTIES CXX_STANDARD 17)
else ()
target_compile_features(aegis_static PUBLIC cxx_std_14)
set_target_properties(aegis_static PROPERTIES CXX_STANDARD 14)
endif ()
set_target_properties(aegis_static PROPERTIES CXX_STANDARD_REQUIRED ON)
target_compile_options(aegis_static PRIVATE ${AEGIS_CFLAGS})
install(TARGETS aegis_static
EXPORT aegis-targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
SET(PKG_CONFIG_STATIC_LIBS
"-L\${libdir} -l:libaegis.a -lssl -lcrypto -lpthread -lz -ldl"
)
SET(PKG_CONFIG_STATIC_CFLAGS
"-I/usr/include -I\${includedir} -I${Asio_INCLUDE_DIR} -I${JSON_INCLUDE_DIR} -I${Spdlog_INCLUDE_DIR} -I${Websocketpp_INCLUDE_DIR} -I${ZLIB_INCLUDE_DIR} -DAEGIS_SEPARATE_COMPILATION"
)
CONFIGURE_FILE(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/aegis_static.pc.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/aegis.pc"
)
INSTALL(FILES "${CMAKE_CURRENT_BINARY_DIR}/aegis.pc" DESTINATION lib/pkgconfig)
endif ()
install(EXPORT aegis-targets
FILE
AegisTargets.cmake
NAMESPACE
Aegis::
DESTINATION
${INSTALL_CONFIGDIR}
)
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/AegisConfigVersion.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)
if (BUILD_SHARED_LIBS)
configure_package_config_file(${CMAKE_CURRENT_LIST_DIR}/cmake/AegisConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/AegisConfig.cmake
INSTALL_DESTINATION ${INSTALL_CONFIGDIR}
PATH_VARS AEGIS_PACKAGE_INCLUDE_DIRS
)
else ()
configure_package_config_file(${CMAKE_CURRENT_LIST_DIR}/cmake/AegisConfig_static.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/AegisConfig.cmake
INSTALL_DESTINATION ${INSTALL_CONFIGDIR}
PATH_VARS AEGIS_PACKAGE_INCLUDE_DIRS
)
endif ()
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/AegisConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/AegisConfigVersion.cmake
${CMAKE_CURRENT_LIST_DIR}/cmake/FindAsio.cmake
${CMAKE_CURRENT_LIST_DIR}/cmake/FindJSON.cmake
${CMAKE_CURRENT_LIST_DIR}/cmake/FindSpdlog.cmake
${CMAKE_CURRENT_LIST_DIR}/cmake/FindWebsocketpp.cmake
DESTINATION ${INSTALL_CONFIGDIR}
)
export(EXPORT aegis-targets FILE ${CMAKE_CURRENT_BINARY_DIR}/AegisTargets.cmake NAMESPACE Aegis::)
export(PACKAGE Aegis)
if (BUILD_EXAMPLES)
add_executable(aegis_example src/example_main.cpp src/example.cpp)
add_executable(aegis_minimal src/minimal.cpp)
add_executable(aegis_headeronly_no_cache src/minimal.cpp)
target_compile_definitions(aegis_headeronly_no_cache PRIVATE AEGIS_DISABLE_ALL_CACHE)
set_property(TARGET aegis_example PROPERTY CXX_STANDARD 14)
set_property(TARGET aegis_example PROPERTY CXX_STANDARD_REQUIRED ON)
set_property(TARGET aegis_minimal PROPERTY CXX_STANDARD 14)
set_property(TARGET aegis_minimal PROPERTY CXX_STANDARD_REQUIRED ON)
set_property(TARGET aegis_headeronly_no_cache PROPERTY CXX_STANDARD 14)
set_property(TARGET aegis_headeronly_no_cache PROPERTY CXX_STANDARD_REQUIRED ON)
if(MSVC)
target_link_libraries(aegis_example PRIVATE Aegis::aegis ${REQUIRED_LIBS})
target_link_libraries(aegis_minimal PRIVATE Aegis::aegis ${REQUIRED_LIBS})
target_link_libraries(aegis_headeronly_no_cache PRIVATE Aegis::aegis ${REQUIRED_LIBS})
else()
target_link_libraries(aegis_example PRIVATE Aegis::aegis ${REQUIRED_LIBS})
target_link_libraries(aegis_minimal PRIVATE Aegis::aegis ${REQUIRED_LIBS})
target_link_libraries(aegis_headeronly_no_cache PRIVATE Aegis::aegis ${REQUIRED_LIBS})
endif()
target_compile_options(aegis_example PRIVATE ${AEGIS_CFLAGS})
target_compile_options(aegis_minimal PRIVATE ${AEGIS_CFLAGS})
target_compile_options(aegis_headeronly_no_cache PRIVATE ${AEGIS_CFLAGS})
target_include_directories(aegis_example
PUBLIC
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
)
target_include_directories(aegis_minimal
PUBLIC
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
)
target_include_directories(aegis_headeronly_no_cache
PUBLIC
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
)
endif ()