-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
210 lines (179 loc) · 5.93 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
CMAKE_MINIMUM_REQUIRED(VERSION 3.12)
PROJECT(quake3e)
SET(CNAME "quake3e")
SET(DNAME "quake3e.ded")
SET(RENDERER_PREFIX ${CNAME})
SET(RENDERER_DEFAULT opengl) # valid options: opengl, vulkan, opengl2
OPTION(USE_SDL "" ON)
OPTION(USE_CURL "" ON)
OPTION(USE_LOCAL_HEADERS "" ON)
OPTION(USE_VULKAN "" ON)
OPTION(USE_SYSTEM_JPEG "" OFF)
OPTION(USE_RENDERER_DLOPEN "" ON)
SET(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules)
AUX_SOURCE_DIRECTORY(code/qcommon QCOMMON_SRCS)
# exclude platform-dependent QVM bytecode compilers
list(FILTER QCOMMON_SRCS EXCLUDE REGEX ".*vm_[alx].*.c")
# add platform-dependent QVM bytecode compilers
IF(CMAKE_SYSTEM_PROCESSOR MATCHES AMD64|x86|i*86)
IF(CMAKE_SYSTEM_PROCESSOR MATCHES AMD64)
IF(WIN32)
SET(BINEXT .x64)
ELSE()
SET(BINEXT .x86_64)
ENDIF()
SET(RENDEXT _x86_64)
ELSE()
#SET(BINEXT .x86)
SET(RENDEXT _x86)
ENDIF()
list(APPEND QCOMMON_SRCS code/qcommon/vm_x86.c)
ELSEIF(CMAKE_SYSTEM_PROCESSOR MATCHES aarch64|arm64)
SET(BINEXT .aarch64)
SET(RENDEXT _aarch64)
list(APPEND QCOMMON_SRCS code/qcommon/vm_aarch64.c)
ELSEIF(CMAKE_SYSTEM_PROCESSOR MATCHES arm*)
SET(BINEXT .arm)
SET(RENDEXT _arm)
list(APPEND QCOMMON_SRCS code/qcommon/vm_armv7l.c)
ELSE()
TARGET_COMPILE_DEFINITIONS(qcommon PRIVATE -DNO_VM_COMPILED)
TARGET_COMPILE_DEFINITIONS(qcommon_ded PRIVATE -DNO_VM_COMPILED)
ENDIF()
# botlib
AUX_SOURCE_DIRECTORY(code/botlib BOTLIB_SRCS)
ADD_LIBRARY(botlib OBJECT ${BOTLIB_SRCS})
TARGET_COMPILE_DEFINITIONS(botlib PRIVATE BOTLIB)
AUX_SOURCE_DIRECTORY(code/server SERVER_SRCS)
list(REMOVE_ITEM SERVER_SRCS code/server/sv_rankings.c)
# universal binary
ADD_LIBRARY(qcommon OBJECT ${QCOMMON_SRCS} ${SERVER_SRCS})
# dedicated server
ADD_LIBRARY(qcommon_ded OBJECT ${QCOMMON_SRCS} ${SERVER_SRCS})
TARGET_COMPILE_DEFINITIONS(qcommon_ded PUBLIC DEDICATED)
# client + cURL
AUX_SOURCE_DIRECTORY(code/client CLIENT_SRCS)
IF(NOT USE_CURL)
list(REMOVE_ITEM CLIENT_SRCS code/client/cl_curl.c)
ENDIF()
#ADD_LIBRARY(client OBJECT ${CLIENT_SRCS})
# jpeg
IF(USE_SYSTEM_JPEG)
ADD_LIBRARY(client OBJECT ${CLIENT_SRCS})
find_package(JPEG REQUIRED)
TARGET_COMPILE_DEFINITIONS(client PRIVATE -DUSE_SYSTEM_JPEG)
TARGET_LINK_LIBRARIES(client ${JPEG_LIBRARIES})
ELSE()
AUX_SOURCE_DIRECTORY(code/libjpeg JPEG_SRCS)
#ADD_LIBRARY(jpeg ${JPEG_SRCS})
#TARGET_LINK_LIBRARIES(client jpeg)
ADD_LIBRARY(client OBJECT ${CLIENT_SRCS} ${JPEG_SRCS})
ENDIF()
# renderers
AUX_SOURCE_DIRECTORY(code/renderercommon RENDERER_COMMON_SRCS)
AUX_SOURCE_DIRECTORY(code/renderer RENDERER_GL_SRCS)
AUX_SOURCE_DIRECTORY(code/renderervk RENDERER_VK_SRCS)
IF(USE_RENDERER_DLOPEN)
SET(AUX_SRCS
code/qcommon/q_shared.c
code/qcommon/puff.c
code/qcommon/q_math.c
)
TARGET_COMPILE_DEFINITIONS(client PRIVATE USE_RENDERER_DLOPEN RENDERER_PREFIX="${RENDERER_PREFIX}" RENDERER_DEFAULT="${RENDERER_DEFAULT}")
ADD_LIBRARY(${RENDERER_PREFIX}_opengl${RENDEXT} SHARED ${RENDERER_GL_SRCS} ${RENDERER_COMMON_SRCS} ${AUX_SRCS})
TARGET_COMPILE_DEFINITIONS(${RENDERER_PREFIX}_opengl${RENDEXT} PRIVATE USE_RENDERER_DLOPEN)
ADD_LIBRARY(${RENDERER_PREFIX}_vulkan${RENDEXT} SHARED ${RENDERER_VK_SRCS} ${RENDERER_COMMON_SRCS} ${AUX_SRCS})
TARGET_COMPILE_DEFINITIONS(${RENDERER_PREFIX}_vulkan${RENDEXT} PRIVATE USE_RENDERER_DLOPEN)
ELSE()
IF(USE_VULKAN)
ADD_LIBRARY(${RENDERER_PREFIX}_vulkan OBJECT ${RENDERER_VK_SRCS} ${RENDERER_COMMON_SRCS})
ELSE()
ADD_LIBRARY(${RENDERER_PREFIX}_opengl OBJECT ${RENDERER_GL_SRCS} ${RENDERER_COMMON_SRCS})
ENDIF()
ENDIF()
# common function, window system
IF(UNIX)
SET (Q3_SRCS
code/unix/unix_main.c
code/unix/unix_shared.c
code/unix/linux_signals.c)
IF(USE_SDL)
AUX_SOURCE_DIRECTORY(code/sdl Q3_UI_SRCS)
ELSE()
SET(Q3_UI_SRCS
code/unix/linux_glimp.c
code/unix/linux_qgl.c
code/unix/linux_snd.c
code/unix/x11_dga.c
code/unix/x11_randr.c
code/unix/x11_vidmode.c)
IF(USE_VULKAN)
list(APPEND Q3_UI_SRCS code/unix/linux_qvk.c)
ENDIF()
ENDIF()
IF(APPLE)
SET(EXE_TYPE MACOSX_BUNDLE)
list(APPEND Q3_SRCS code/unix/quake3_flat.icns)
set_source_files_properties(code/unix/quake3_flat.icns PROPERTIES
MACOSX_PACKAGE_LOCATION Resources)
SET(MACOSX_BUNDLE_ICON_FILE quake3_flat.icns)
ENDIF()
ELSEIF(WIN32)
SET(EXE_TYPE WIN32)
IF(MSVC)
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /MANIFEST:NO")
ADD_COMPILE_DEFINITIONS(_CRT_SECURE_NO_WARNINGS) # v3.12+
ENDIF()
SET(Q3_SRCS
code/win32/win_main.c
code/win32/win_shared.c
code/win32/win_syscon.c
code/win32/win_resource.rc)
SET(Q3_UI_SRCS
code/win32/win_gamma.c
code/win32/win_glimp.c
code/win32/win_input.c
code/win32/win_minimize.c
code/win32/win_qgl.c
code/win32/win_snd.c
code/win32/win_wndproc.c)
IF(USE_VULKAN)
list(APPEND Q3_UI_SRCS code/win32/win_qvk.c)
ENDIF()
ENDIF(UNIX)
ADD_LIBRARY(q3ui OBJECT ${Q3_UI_SRCS})
IF(NOT MSVC)
IF(USE_SDL)
find_package(SDL2 REQUIRED)
TARGET_LINK_LIBRARIES(q3ui SDL2::Main)
ELSEIF(UNIX)
find_package (X11 REQUIRED)
TARGET_LINK_LIBRARIES(q3ui ${X11_LIBRARIES})
ENDIF()
ENDIF()
IF(USE_VULKAN)
TARGET_COMPILE_DEFINITIONS(q3ui PRIVATE USE_VULKAN_API)
TARGET_COMPILE_DEFINITIONS(client PRIVATE USE_VULKAN_API)
ENDIF()
# client executable
ADD_EXECUTABLE(${CNAME}${BINEXT} ${EXE_TYPE} ${Q3_SRCS})
TARGET_LINK_LIBRARIES(${CNAME}${BINEXT} qcommon botlib client q3ui)
#TARGET_LINK_OPTIONS(${CNAME} PRIVATE -fno-pie) # v3.13+
IF(NOT USE_RENDERER_DLOPEN)
IF(USE_VULKAN)
TARGET_LINK_LIBRARIES(${CNAME}${BINEXT} ${RENDERER_PREFIX}_vulkan)
ELSE()
TARGET_LINK_LIBRARIES(${CNAME}${BINEXT} ${RENDERER_PREFIX}_opengl)
ENDIF()
ENDIF()
# dedicated server executable
ADD_EXECUTABLE(${DNAME}${BINEXT} ${EXE_TYPE} ${Q3_SRCS})
TARGET_LINK_LIBRARIES(${DNAME}${BINEXT} qcommon_ded botlib)
#TARGET_LINK_OPTIONS(${DNAME} PRIVATE -fno-pie) # v3.13+
IF(WIN32)
TARGET_LINK_LIBRARIES(${CNAME}${BINEXT} winmm comctl32 ws2_32)
TARGET_LINK_LIBRARIES(${DNAME}${BINEXT} winmm comctl32 ws2_32)
ELSE()
TARGET_LINK_LIBRARIES(${CNAME}${BINEXT} m ${CMAKE_DL_LIBS})
TARGET_LINK_LIBRARIES(${DNAME}${BINEXT} m ${CMAKE_DL_LIBS})
ENDIF()