-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathCMakeLists.txt
302 lines (273 loc) · 13.2 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
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
project(ShmNFrame)
message("CMAKE_VERSION: ${CMAKE_VERSION} ")
message("CMAKE_HOST_SYSTEM_NAME: ${CMAKE_HOST_SYSTEM_NAME} ")
message("CMAKE_HOST_SYSTEM: ${CMAKE_HOST_SYSTEM} ")
message("CMAKE_SYSTEM_NAME: ${CMAKE_SYSTEM_NAME} ")
message("CMAKE_SYSTEM: ${CMAKE_SYSTEM} ")
message("CMAKE_HOST_UNIX: ${CMAKE_HOST_UNIX} ")
message("CMAKE_HOST_WIN32: ${CMAKE_HOST_WIN32} ")
#---------------------------------------------------------------------------------------
# Compiler config
#---------------------------------------------------------------------------------------
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set(CMAKE_CXX_STANDARD 11)
if (UNIX)
if (${CMAKE_VERSION} VERSION_LESS "3.22.0")
set(DISTRO_ID "centos")
set(DISTRO_VERSION_ID 7)
message("DISTRO_ID: ${DISTRO_ID} ")
message("DISTRO_VERSION_ID: ${DISTRO_VERSION_ID} ")
else ()
cmake_host_system_information(RESULT PRETTY_NAME QUERY DISTRIB_PRETTY_NAME)
message(STATUS "${PRETTY_NAME}")
cmake_host_system_information(RESULT DISTRO QUERY DISTRIB_INFO)
foreach (VAR IN LISTS DISTRO)
message(STATUS "${VAR}=`${${VAR}}`")
endforeach ()
endif ()
endif ()
if (WIN32)
add_compile_options(/wd4819)
add_compile_options(/wd4091)
add_compile_options(/wd4251)
add_compile_options(/wd4996)
add_compile_options(/wd4275)
add_compile_options(/wd4316)
add_compile_options(/wd4244)
add_compile_options(/wd4267)
add_compile_options(/wd4244)
add_compile_options(/wd4099)
add_compile_options(/wd4018)
add_compile_options(/wd4834)
add_compile_options(/wd4065)
add_compile_options(/wd4311)
add_compile_options(/wd4309)
add_compile_options(/wd4013)
add_compile_options(/wd4024)
add_compile_options(/wd4477)
add_compile_options(/wd4133)
add_compile_options(/wd4047)
add_compile_options(/wd4099)
add_compile_options(/wd4217)
add_compile_options(/wd4286)
add_compile_options(/wd4291)
endif ()
if (CMAKE_BUILD_TYPE STREQUAL "Release")
set(CMAKE_BUILD_TYPE "Release")
if (UNIX)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -std=c++11 -g -O3 -Wall")
add_definitions(
-DNDEBUG
-Wcomment
-DNF_STATIC_PLUGIN
-DEVPP_HTTP_CLIENT_SUPPORTS_SSL #evpp http client ssl
-DEVPP_HTTP_SERVER_SUPPORTS_SSL #evpp http server ssl
-DH_HAVE_CAMERON314_CONCURRENTQUEUE #evpp need
-DLUA_COMPAT_5_1
-DLUA_USE_LINUX
-fPIC
)
else (WIN32)
set(CMAKE_CXX_FLAGS_RELEASE "/MT")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zi /O2 -DNDEBUG -DWIN32_LEAN_AND_MEAN -D_WINSOCK_DEPRECATED_NO_WARNINGS -D_LIB -D_WIN32 -D_CONSOLE -DNF_NONCLIENT_BUILD -DUNICODE -D_UNICODE -D_WINDOWS -DWIN32 -DNF_STATIC_PLUGIN -DLUA_COMPAT_5_1 -D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE -D_USRDLL -DDLL_EXPORTS -DMYSQLPP_MAKING_DLL -DHAVE_MYSQL_SSL_SET -DBUILDING_LIBCURL -DCURL_STATICLIB ")
endif ()
elseif (CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CMAKE_BUILD_TYPE "Debug")
if (UNIX)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -O0 -Wall -g -ggdb -fPIC")
add_definitions(
-D_DEBUG
-Wcomment
-DNF_STATIC_PLUGIN
-DEVPP_HTTP_CLIENT_SUPPORTS_SSL #evpp http client ssl
-DEVPP_HTTP_SERVER_SUPPORTS_SSL #evpp http server ssl
-DH_HAVE_CAMERON314_CONCURRENTQUEUE #evpp need
-DLUA_COMPAT_5_1
-DLUA_USE_LINUX
-fPIC
)
else (WIN32)
set(CMAKE_CXX_FLAGS_DEBUG "/MTd")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DWIN32_LEAN_AND_MEAN -D_WINSOCK_DEPRECATED_NO_WARNINGS -D_LIB -D_WIN32 -D_CONSOLE -DNF_NONCLIENT_BUILD -DUNICODE -D_UNICODE -D_WINDOWS -DWIN32 -D_DEBUG -DNF_STATIC_PLUGIN -DLUA_COMPAT_5_1 -D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE -D_USRDLL -DDLL_EXPORTS -DMYSQLPP_MAKING_DLL -DHAVE_MYSQL_SSL_SET -DBUILDING_LIBCURL -DCURL_STATICLIB ")
endif ()
elseif (CMAKE_BUILD_TYPE STREQUAL "DynamicDebug")
set(CMAKE_BUILD_TYPE "DynamicDebug")
if (UNIX)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -O0 -Wall -g3 -ggdb -fPIC -Wextra -Wno-unused-parameter -Wno-conversion-null -Wno-unused-but-set-variable -Wno-int-to-pointer-cast -Wno-array-bounds")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -O0 -Wall -g3 -ggdb -fPIC")
add_definitions(
-D_DEBUG
-DCHECK_MEM_LEAK
-Wcomment
-DLUA_COMPAT_5_1
-DLUA_USE_LINUX
-DNF_DYNAMIC_PLUGIN
-DEVPP_HTTP_CLIENT_SUPPORTS_SSL #evpp http client ssl
-DEVPP_HTTP_SERVER_SUPPORTS_SSL #evpp http server ssl
-DH_HAVE_CAMERON314_CONCURRENTQUEUE #evpp need
-fPIC
-Wno-error
)
else (WIN32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DWIN32_LEAN_AND_MEAN -D_WINSOCK_DEPRECATED_NO_WARNINGS -D_LIB -D_WIN32 -D_CONSOLE -DNF_NONCLIENT_BUILD -DUNICODE -D_UNICODE -D_WINDOWS -DWIN32 -D_DEBUG -DNF_STATIC_PLUGIN -DLUA_COMPAT_5_1 -D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE -D_USRDLL -DDLL_EXPORTS -DMYSQLPP_MAKING_DLL -DHAVE_MYSQL_SSL_SET -DBUILDING_LIBCURL -DCURL_STATICLIB ")
endif ()
elseif (CMAKE_BUILD_TYPE STREQUAL "DynamicRelease")
set(CMAKE_BUILD_TYPE "DynamicRelease")
if (UNIX)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -std=c++11 -O3 -g -Wall")
#don't use -O3 用-O3来编译所有的软件包将产生更大体积更耗内存的二进制文件,
#大大增加编译失败的机会或不可预知的程序行为(包括错误)。 这样做将得不偿失,记住过犹不及。 在gcc 4.x.中使用-O3是不推荐的
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -O2 -Wall -fPIC")
add_definitions(
-DNDEBUG
-Wcomment
-DLUA_COMPAT_5_1
-DLUA_USE_LINUX
-DNF_DYNAMIC_PLUGIN
-DEVPP_HTTP_CLIENT_SUPPORTS_SSL #evpp http client ssl
-DEVPP_HTTP_SERVER_SUPPORTS_SSL #evpp http server ssl
-DH_HAVE_CAMERON314_CONCURRENTQUEUE #evpp need
-fPIC
-Wno-error
)
else (WIN32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DWIN32_LEAN_AND_MEAN -D_WINSOCK_DEPRECATED_NO_WARNINGS -D_LIB -D_WIN32 -D_CONSOLE -DNF_NONCLIENT_BUILD -DUNICODE -D_UNICODE -D_WINDOWS -DWIN32 -D_DEBUG -DNF_STATIC_PLUGIN -DLUA_COMPAT_5_1 -D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE -D_USRDLL -DDLL_EXPORTS -DMYSQLPP_MAKING_DLL -DHAVE_MYSQL_SSL_SET -DBUILDING_LIBCURL -DCURL_STATICLIB ")
endif ()
endif ()
message("PROJECT_SOURCE_DIR = ${PROJECT_SOURCE_DIR}")
message("CMAKE_SOURCE_DIR = ${CMAKE_SOURCE_DIR}")
message("CMAKE_C_FLAGS = ${CMAKE_C_FLAGS}")
message("CMAKE_CXX_FLAGS = ${CMAKE_CXX_FLAGS}")
message("CONTRCT_VERSION_FILE = ${CONTRCT_VERSION_FILE}")
message("CONTRCT_VERSION_FILE2 = ${CONTRCT_VERSION_FILE2}")
if (UNIX)
SET(INCLUDE_DIR "/usr/local/include"
"${CMAKE_SOURCE_DIR}/thirdparty"
"${CMAKE_SOURCE_DIR}/thirdparty/LuaBind/lua"
"${CMAKE_SOURCE_DIR}/thirdparty/common/"
"${CMAKE_SOURCE_DIR}/thirdparty/mysql/include"
"${CMAKE_SOURCE_DIR}/thirdparty/mysql/linux"
"${CMAKE_SOURCE_DIR}/thirdparty/"
"${CMAKE_SOURCE_DIR}/thirdparty/Theron/Include"
"${CMAKE_SOURCE_DIR}/thirdparty/zdb"
"${CMAKE_SOURCE_DIR}/thirdparty/libevent/include"
"${CMAKE_SOURCE_DIR}/thirdparty/libevent/linux/include"
"${CMAKE_SOURCE_DIR}/thirdparty/zookeeper/include"
"${CMAKE_SOURCE_DIR}/thirdparty/common/hiredis/hiredis_linux"
"${CMAKE_SOURCE_DIR}/src"
"${CMAKE_SOURCE_DIR}/src/NFrame"
"${CMAKE_SOURCE_DIR}/src/NFServer"
"${CMAKE_SOURCE_DIR}/src/NFrame/NFComm/NFKernelMessage"
"${CMAKE_SOURCE_DIR}/src/NFrame/NFComm/NFMessageDefine"
"${CMAKE_SOURCE_DIR}/src/NFServer/NFServerComm/NFServerMessage")
else (WIN32)
SET(INCLUDE_DIR "/usr/local/include"
"${CMAKE_SOURCE_DIR}/thirdparty"
"${CMAKE_SOURCE_DIR}/thirdparty/LuaBind/lua"
"${CMAKE_SOURCE_DIR}/thirdparty/common/"
"${CMAKE_SOURCE_DIR}/thirdparty/mysql/include"
"${CMAKE_SOURCE_DIR}/thirdparty/mysql/win"
"${CMAKE_SOURCE_DIR}/thirdparty/"
"${CMAKE_SOURCE_DIR}/thirdparty/Theron/Include"
"${CMAKE_SOURCE_DIR}/thirdparty/zdb"
"${CMAKE_SOURCE_DIR}/thirdparty/libevent/include"
"${CMAKE_SOURCE_DIR}/thirdparty/libevent/win/include"
"${CMAKE_SOURCE_DIR}/thirdparty/zookeeper/include"
"${CMAKE_SOURCE_DIR}/thirdparty/common/hiredis/hiredis_win"
"${CMAKE_SOURCE_DIR}/src"
"${CMAKE_SOURCE_DIR}/src/NFrame"
"${CMAKE_SOURCE_DIR}/src/NFServer"
"${CMAKE_SOURCE_DIR}/src/NFrame/NFComm/NFKernelMessage"
"${CMAKE_SOURCE_DIR}/src/NFrame/NFComm/NFMessageDefine"
"${CMAKE_SOURCE_DIR}/src/NFServer/NFServerComm/NFServerMessage")
endif ()
if (CMAKE_BUILD_TYPE STREQUAL "Release")
if (UNIX)
SET(LIB_DIR "/usr/lib"
"${CMAKE_SOURCE_DIR}/thirdparty/lib64_release"
"${CMAKE_SOURCE_DIR}/Build/Lib/Release")
SET(LIB_LINK_DEP resolv dl rt pthread libprotobuf.a libCommon.a libLuaBind.a libNFMessageDefine.a libNFCore.a libNFPluginModule.a)
SET(LIB_LINK_NF libNFKernelPlugin.a NFTestPlugin.a)
else (WIN32)
SET(LIB_DIR "${CMAKE_SOURCE_DIR}/thirdparty/lib64_release"
"${CMAKE_SOURCE_DIR}/Build/Lib/Release")
endif ()
elseif (CMAKE_BUILD_TYPE STREQUAL "Debug")
if (UNIX)
SET(LIB_DIR "/usr/lib"
"${CMAKE_SOURCE_DIR}/thirdparty/lib64_debug"
"${CMAKE_SOURCE_DIR}/Build/Lib/Debug")
SET(LIB_LINK_DEP resolv dl rt pthread libprotobuf.a libCommon.a libLuaBind.a libNFMessageDefine.a libNFCore.a libNFPluginModule.a)
SET(LIB_LINK_NF libNFKernelPlugin.a NFTestPlugin.a)
else (WIN32)
SET(LIB_DIR "${CMAKE_SOURCE_DIR}/thirdparty/lib64_debug"
"${CMAKE_SOURCE_DIR}/Build/Lib/Debug")
endif ()
elseif (CMAKE_BUILD_TYPE STREQUAL "DynamicRelease")
if (UNIX)
message("DISTRO_ID: ${DISTRO_ID} ")
message("DISTRO_VERSION_ID: ${DISTRO_VERSION_ID} ")
if (DISTRO_ID STREQUAL "centos")
message("DISTRO_ID: ${DISTRO_ID} ")
message("DISTRO_VERSION_ID: ${DISTRO_VERSION_ID} ")
SET(LIB_DIR "/usr/lib"
"${CMAKE_SOURCE_DIR}/thirdparty/lib64_release"
"${CMAKE_SOURCE_DIR}/Build/Lib/Release"
"${CMAKE_SOURCE_DIR}/Install/Bin/Dynamic_Release"
)
elseif (DISTRO_ID STREQUAL "ubuntu")
SET(LIB_DIR "/usr/lib"
"${CMAKE_SOURCE_DIR}/thirdparty/lib64_release/ubuntu"
"${CMAKE_SOURCE_DIR}/Build/Lib/Release"
"${CMAKE_SOURCE_DIR}/Install/Bin/Dynamic_Release"
)
endif ()
SET(LIB_LINK_DEP resolv dl rt pthread)
endif ()
elseif (CMAKE_BUILD_TYPE STREQUAL "DynamicDebug")
if (UNIX)
message("DISTRO_ID: ${DISTRO_ID} ")
message("DISTRO_VERSION_ID: ${DISTRO_VERSION_ID} ")
if (DISTRO_ID STREQUAL "centos")
SET(LIB_DIR "/usr/lib"
"${CMAKE_SOURCE_DIR}/thirdparty/lib64_debug"
"${CMAKE_SOURCE_DIR}/Build/Lib/Debug"
"${CMAKE_SOURCE_DIR}/Install/Bin/Dynamic_Debug"
)
elseif (DISTRO_ID STREQUAL "ubuntu")
SET(LIB_DIR "/usr/lib"
"${CMAKE_SOURCE_DIR}/thirdparty/lib64_debug/ubuntu"
"${CMAKE_SOURCE_DIR}/Build/Lib/Debug"
"${CMAKE_SOURCE_DIR}/Install/Bin/Dynamic_Debug"
)
endif ()
SET(LIB_LINK_DEP resolv dl rt pthread)
endif ()
endif ()
include_directories(${INCLUDE_DIR})
link_directories(${LIB_DIR})
if (CMAKE_BUILD_TYPE STREQUAL "Release")
ADD_SUBDIRECTORY("thirdparty")
ADD_SUBDIRECTORY("src")
ADD_SUBDIRECTORY("game")
elseif (CMAKE_BUILD_TYPE STREQUAL "Debug")
ADD_SUBDIRECTORY("thirdparty")
ADD_SUBDIRECTORY("src")
ADD_SUBDIRECTORY("game")
elseif (CMAKE_BUILD_TYPE STREQUAL "DynamicRelease")
ADD_SUBDIRECTORY("thirdparty")
ADD_SUBDIRECTORY("src")
ADD_SUBDIRECTORY("game")
elseif (CMAKE_BUILD_TYPE STREQUAL "DynamicDebug")
ADD_SUBDIRECTORY("thirdparty")
ADD_SUBDIRECTORY("src")
ADD_SUBDIRECTORY("game")
endif ()