forked from QW-Group/mvdsv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
202 lines (163 loc) · 5.77 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
cmake_minimum_required(VERSION 3.9.0)
set(CMAKE_VERBOSE_MAKEFILE ON)
# Set project name and languge.
project(mvdsv C)
######################################################################################################
# Checkout shared qwprot repository
find_package(Git QUIET)
if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
option(GIT_SUBMODULE "Check submodules during build" ON)
if(GIT_SUBMODULE)
message(STATUS "Submodule update")
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE GIT_SUBMOD_RESULT)
if(NOT GIT_SUBMOD_RESULT EQUAL "0")
message(FATAL_ERROR "git submodule update --init --recursive failed with ${GIT_SUBMOD_RESULT}, please checkout submodules")
endif()
endif()
endif()
######################################################################################################
# Set where sources located.
set(DIR_SRC "src")
# Add sources
set(SRC_COMMON
"${DIR_SRC}/bothtools.c"
"${DIR_SRC}/build.c"
"${DIR_SRC}/cmd.c"
"${DIR_SRC}/cmodel.c"
"${DIR_SRC}/common.c"
"${DIR_SRC}/crc.c"
"${DIR_SRC}/cvar.c"
"${DIR_SRC}/fs.c"
"${DIR_SRC}/hash.c"
"${DIR_SRC}/mathlib.c"
"${DIR_SRC}/md4.c"
"${DIR_SRC}/net.c"
"${DIR_SRC}/net_chan.c"
"${DIR_SRC}/pmove.c"
"${DIR_SRC}/pmovetst.c"
"${DIR_SRC}/pr2_cmds.c"
"${DIR_SRC}/pr2_edict.c"
"${DIR_SRC}/pr2_exec.c"
"${DIR_SRC}/vm.c"
"${DIR_SRC}/vm_interpreted.c"
"${DIR_SRC}/vm_x86.c"
"${DIR_SRC}/pr_cmds.c"
"${DIR_SRC}/pr_edict.c"
"${DIR_SRC}/pr_exec.c"
"${DIR_SRC}/sha1.c"
"${DIR_SRC}/sha3.c"
"${DIR_SRC}/sv_ccmds.c"
"${DIR_SRC}/sv_demo.c"
"${DIR_SRC}/sv_demo_misc.c"
"${DIR_SRC}/sv_demo_qtv.c"
"${DIR_SRC}/sv_ents.c"
"${DIR_SRC}/sv_init.c"
"${DIR_SRC}/sv_login.c"
"${DIR_SRC}/sv_main.c"
"${DIR_SRC}/sv_master.c"
"${DIR_SRC}/sv_mod_frags.c"
"${DIR_SRC}/sv_move.c"
"${DIR_SRC}/sv_nchan.c"
"${DIR_SRC}/sv_phys.c"
"${DIR_SRC}/sv_save.c"
"${DIR_SRC}/sv_send.c"
"${DIR_SRC}/sv_user.c"
"${DIR_SRC}/vfs_os.c"
"${DIR_SRC}/vfs_pak.c"
"${DIR_SRC}/sv_world.c"
"${DIR_SRC}/zone.c"
)
# Check build target, and included sources
if(UNIX)
list(APPEND SRC_COMMON
"${DIR_SRC}/sv_sys_unix.c"
)
else()
list(APPEND SRC_COMMON
"${DIR_SRC}/sv_sys_win.c"
"${DIR_SRC}/sv_windows.c"
"${DIR_SRC}/winquake.rc"
)
endif()
######################################################################################################
# Check for curl, and include sources and libs, if found
find_package(CURL)
if(NOT CURL_FOUND)
message(STATUS "Curl library not found")
else()
list(APPEND SRC_COMMON
"${DIR_SRC}/central.c"
)
endif()
######################################################################################################
# Check for PCRE. if found, include it; if not found, use bundled PCRE.
find_library(PCRE_LIBRARIES pcre)
if(PCRE_LIBRARIES)
set(PCRE_FOUND 1)
find_path(PCRE_INCLUDE_DIR pcre.h)
endif(PCRE_LIBRARIES)
if(NOT PCRE_FOUND)
message(STATUS "PCRE library not found. Using bundled PCRE instead.")
list(APPEND SRC_COMMON
"${DIR_SRC}/pcre/get.c"
"${DIR_SRC}/pcre/pcre.c"
)
else()
message(STATUS "Found PCRE: ${PCRE_LIBRARIES}")
endif()
######################################################################################################
# Set base compiler flags
set(CFLAGS -Wall)
set(LFLAGS)
######################################################################################################
# Set target
add_executable(${PROJECT_NAME} ${SRC_COMMON})
set_target_properties(${PROJECT_NAME}
PROPERTIES #PREFIX "" # Strip lib prefix.
C_VISIBILITY_PRESET hidden # Hide all symbols unless excplicitly marked to export.
)
######################################################################################################
# Set include directories
target_include_directories(${PROJECT_NAME} PRIVATE ${DIR_SRC}/qwprot/src)
target_include_directories(${PROJECT_NAME} PRIVATE ${CURL_INCLUDE_DIRS})
target_include_directories(${PROJECT_NAME} PRIVATE ${PCRE_INCLUDE_DIR})
######################################################################################################
# Check build target, and included sources and libs
if(UNIX)
target_link_libraries(${PROJECT_NAME} m)
target_link_libraries(${PROJECT_NAME} ${CMAKE_DL_LIBS})
else()
target_link_libraries(${PROJECT_NAME} ws2_32)
target_link_libraries(${PROJECT_NAME} winmm)
set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc")
endif()
######################################################################################################
# Set defines for the build
target_compile_definitions(${PROJECT_NAME} PRIVATE SERVERONLY)
target_compile_definitions(${PROJECT_NAME} PRIVATE USE_PR2)
target_compile_definitions(${PROJECT_NAME} PRIVATE MVD_PEXT1_SERVERSIDEWEAPON)
target_compile_definitions(${PROJECT_NAME} PRIVATE MVD_PEXT1_SERVERSIDEWEAPON2)
target_compile_definitions(${PROJECT_NAME} PRIVATE FTE_PEXT2_VOICECHAT)
include (TestBigEndian)
TEST_BIG_ENDIAN(IS_BIG_ENDIAN)
if(IS_BIG_ENDIAN)
target_compile_definitions(${PROJECT_NAME} PRIVATE __BIG_ENDIAN__Q__)
message(STATUS "BIG_ENDIAN")
else()
target_compile_definitions(${PROJECT_NAME} PRIVATE __LITTLE_ENDIAN__Q__)
message(STATUS "LITTLE_ENDIAN")
endif()
if(CURL_FOUND)
target_compile_definitions(${PROJECT_NAME} PRIVATE WWW_INTEGRATION)
target_link_libraries(${PROJECT_NAME} ${CURL_LIBRARIES})
endif()
if(PCRE_FOUND)
target_link_libraries(${PROJECT_NAME} ${PCRE_LIBRARIES})
endif()
######################################################################################################
# Assign compiler flags
target_compile_options(${PROJECT_NAME} PRIVATE ${CFLAGS})
target_link_libraries(${PROJECT_NAME} -lpthread)
######################################################################################################