-
Notifications
You must be signed in to change notification settings - Fork 115
/
CMakeLists.txt
executable file
·226 lines (192 loc) · 9.15 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
cmake_minimum_required(VERSION 3.0)
# UNIX : is TRUE on all UNIX-like OS's, including Apple OS X and CygWin
# WIN32 : is TRUE on Windows. Prior to 2.8.4 this included CygWin
# APPLE : is TRUE on Apple systems. Note this does not imply the system is Mac OS X, only that APPLE is #defined in C/C++ header files.
# MINGW : is TRUE when using the MinGW compiler in Windows
# MSYS : is TRUE when using the MSYS developer environment in Windows
# CYGWIN : is TRUE on Windows when using the CygWin version of cmake
#---------------------------------------------------------------------------------------
# Set default build type to release
#---------------------------------------------------------------------------------------
if (UNIX)
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose Release or Debug" FORCE)
endif ()
endif ()
#---------------------------------------------------------------------------------------
# Set CMAKE_MACOSX_RPATH
#---------------------------------------------------------------------------------------
if (APPLE)
set(CMAKE_MACOSX_RPATH 1)
endif ()
# CMake 3.9 and newer remove any effect the following settings may have on the install_name of a target on macOS:
#
# BUILD_WITH_INSTALL_RPATH target property
# SKIP_BUILD_RPATH target property
# CMAKE_SKIP_RPATH variable
# CMAKE_SKIP_INSTALL_RPATH variable
if (APPLE AND (${CMAKE_MAJOR_VERSION} GREATER_EQUAL 3 AND ${CMAKE_MINOR_VERSION} GREATER_EQUAL 9))
#message("cmake version is ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}")
option(MACOS_NO_RPATH "CMake 3.9 and newer remove any effect of RPATH" ON)
endif ()
#---------------------------------------------------------------------------------------
# Compiler config
#---------------------------------------------------------------------------------------
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
#---------------------------------------------------------------------------------------
# 3rd cmake modules
#---------------------------------------------------------------------------------------
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
#---------------------------------------------------------------------------------------
# CMake switches
#---------------------------------------------------------------------------------------
option(ASIO_STANDALONE "Enable asio standalone" OFF) # used by zephyr
option(ARK_BUILD_TESTS "Enable build tests" ON)
option(ARK_BUILD_EXAMPLES "Enable build examples" ON)
#---------------------------------------------------------------------------------------
# project switches
#---------------------------------------------------------------------------------------
option(ARK_USE_GUID_32 "use 32 bits GUID" OFF)
if (ARK_USE_GUID_32)
add_definitions(-DARK_USE_GUID_32)
endif (ARK_USE_GUID_32)
option(ARK_DOCKER_ALPINE "build docker image by alpine" OFF)
if (ARK_DOCKER_ALPINE)
add_definitions(-DARK_DOCKER_ALPINE)
endif (ARK_DOCKER_ALPINE)
option(ARK_OPEN_FILE_LOG "write log into file" ON)
if (ARK_OPEN_FILE_LOG)
add_definitions(-DOPEN_FILE_LOG)
endif (ARK_OPEN_FILE_LOG)
#---------------------------------------------------------------------------------------
# Get version number.
#---------------------------------------------------------------------------------------
include(cmake/utils.cmake)
ark_extract_version()
#---------------------------------------------------------------------------------------
# ARK project
#---------------------------------------------------------------------------------------
project(ark VERSION ${ARK_VERSION} LANGUAGES CXX C)
message(STATUS "Build ark: v${ARK_VERSION}")
set(ROOT_DIR ${PROJECT_SOURCE_DIR})
set(BIN_OUTPUT_DIR ${ROOT_DIR}/build/bin)
set(3RD_PARTY_DIR ${ROOT_DIR}/3rdparty)
set(3RD_PARTY_LIB_DIR ${BIN_OUTPUT_DIR})
#---------------------------------------------------------------------------------------
# 3rdparty
#---------------------------------------------------------------------------------------
#set(SELF_BUILD_TYPE ${CMAKE_BUILD_TYPE})
#add_subdirectory(3rdparty)
#set(CMAKE_BUILD_TYPE ${SELF_BUILD_TYPE})
if (WIN32)
if (MSVC_VERSION LESS 1911)
message(FATAL_ERROR "need msvc++ 14.1 Visual Studio 2017+")
endif (MSVC_VERSION LESS 1911)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++latest /bigobj -D_CRT_SECURE_NO_WARNINGS -D_SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG "${BIN_OUTPUT_DIR}")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG "${BIN_OUTPUT_DIR}")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG "${BIN_OUTPUT_DIR}")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE "${BIN_OUTPUT_DIR}")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE "${BIN_OUTPUT_DIR}")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE "${BIN_OUTPUT_DIR}")
add_definitions(-DWIN32_LEAN_AND_MEAN -D_WIN32_WINNT=0x0601)
else (UNIX)
if (CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.0)
message(FATAL_ERROR "need gcc7.0+ to support C++17")
endif ()
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g -ggdb -Wall -Wextra -D_DEBUG -fPIC")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -Wall -Wextra -DNDEBUG -fPIC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
#add_definitions(-Wno-unused-variable -Wno-unused-parameter -Wno-unused-function -Wno-strict-aliasing -Wno-pmf-conversions -Wignored-qualifiers)
add_definitions(-Wno-unused-parameter -Wno-unused-variable -Wno-unused-function)
if (XCODE)
# set the output dir for xcode
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG "${BIN_OUTPUT_DIR}")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG "${BIN_OUTPUT_DIR}")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG "${BIN_OUTPUT_DIR}")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE "${BIN_OUTPUT_DIR}")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE "${BIN_OUTPUT_DIR}")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE "${BIN_OUTPUT_DIR}")
endif (XCODE)
endif ()
# protobuf
find_package(Protobuf 3.0.0 REQUIRED)
if (PROTOBUF_FOUND)
message(STATUS "protobuf library found")
include_directories(${Protobuf_INCLUDE_DIRS})
else ()
message(FATAL_ERROR "protobuf library is needed but can't be found")
endif ()
if (${ASIO_STANDALONE})
# standalone asio
add_definitions(-DASIO_STANDALONE)
include_directories(${3RD_PARTY_DIR}/zephyr/asio/asio/include)
else ()
# boost.asio
find_package(Boost 1.69.0 REQUIRED)
if (Boost_FOUND)
message(STATUS "boost library found")
else ()
message(FATAL_ERROR "boost library is needed but can‘t be found")
endif ()
include_directories(${Boost_INCLUDE_DIRS})
link_directories(${Boost_LIBRARY_DIRS})
endif ()
# include and link directories
include_directories(
${3RD_PARTY_DIR}
${3RD_PARTY_DIR}/zephyr/include
${3RD_PARTY_DIR}/spdlog/include
${ROOT_DIR}
${ROOT_DIR}/src
${ROOT_DIR}/src/plugin
${ROOT_DIR}/src/server
${ROOT_DIR}/src/escort)
link_directories(${3RD_PARTY_LIB_DIR})
#---------------------------------------------------------------------------------------
# log
#---------------------------------------------------------------------------------------
message(STATUS "Current system is [${CMAKE_SYSTEM}]")
message(STATUS "ROOT_DIR=${ROOT_DIR}")
message(STATUS "3RD_PARTY_LIB_DIR=${3RD_PARTY_LIB_DIR}")
message(STATUS "BIN_OUTPUT_DIR=${BIN_OUTPUT_DIR}")
message(STATUS "CMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}")
#---------------------------------------------------------------------------------------
# codecov
#---------------------------------------------------------------------------------------
#find_package(codecov)
#---------------------------------------------------------------------------------------
# sub projects
#---------------------------------------------------------------------------------------
message(STATUS "Start to build all ...")
#---------------------------------------------------------------------------------------
# Self defined postfix
#---------------------------------------------------------------------------------------
set(CMAKE_DEBUG_POSTFIX "_d" CACHE STRING "Set debug library postfix")
#---------------------------------------------------------------------------------------
# Building ARK source.
#---------------------------------------------------------------------------------------
message(STATUS "Start to build all source...")
add_subdirectory(src/app)
add_subdirectory(src/proto)
add_subdirectory(src/plugin)
add_subdirectory(src/server)
#---------------------------------------------------------------------------------------
# Building samples
#---------------------------------------------------------------------------------------
if (${ARK_BUILD_EXAMPLES})
message(STATUS "Building examples ...")
add_subdirectory(examples)
endif ()
#---------------------------------------------------------------------------------------
# Building tests
#---------------------------------------------------------------------------------------
if (${ARK_BUILD_TESTS})
message(STATUS "Building tests ...")
enable_testing()
add_subdirectory(test)
endif ()