forked from ValveSoftware/source-sdk-2013
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
268 lines (230 loc) · 9.12 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
cmake_minimum_required( VERSION 3.27 FATAL_ERROR )
if( CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR )
message( FATAL_ERROR "Prevented in-tree build. Please create a `build` directory and run \"cmake -S ${CMAKE_SOURCE_DIR} -B .\" from there" )
endif()
if ( APPLE )
message( FATAL_ERROR "Aurora Source has discontinued OSX support, please use either Windows or Linux." )
endif()
if ("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
message( FATAL_ERROR "Aurora Source only supports 32-bit generation for now" )
endif()
set( CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "" FORCE )
message( NOTICE "Running CMake v${CMAKE_VERSION}" )
project(
AuroraSource
VERSION 0.1.0
DESCRIPTION "A \"branch\" of the source engine, forked off SDK 2013's codebase."
HOMEPAGE_URL "https://github.com/ENDERZOMBI102/Aurora-Source"
LANGUAGES CXX C ASM
)
# For some reason, checking if CMAKE_BUILD_TYPE is defined is unreliable
# So simply check if it's empty instead
if ("${CMAKE_BUILD_TYPE}" STREQUAL "")
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Build type" FORCE)
endif()
# We use C++ 23
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
# Setup rpath
set(CMAKE_BUILD_RPATH_USE_ORIGIN 1)
set(CMAKE_BUILD_RPATH $ORIGIN)
set(CMAKE_INSTALL_RPATH $ORIGIN)
set(CMAKE_BUILD_WITH_INSTALL_RPATH 1)
# This is a way to emulate groups.vgc
set( BUILD_GROUP "game" CACHE STRING "Build Group" )
# For the CMake GUIs that support a combobox list
set_property( CACHE BUILD_GROUP PROPERTY STRINGS
"everything"
"game"
"shaders"
"compilers"
)
# Which game are we building?
set( BUILD_GAME "hl2mp" CACHE STRING "Build Game" )
set_property( CACHE BUILD_GAME PROPERTY STRINGS
"hl2mp" # Only hl2mp at the moment
)
set( SRCDIR "${CMAKE_CURRENT_LIST_DIR}/src" )
set( GAMEDIR "${CMAKE_CURRENT_LIST_DIR}/game" )
set( THIRDPARTYDIR "${CMAKE_CURRENT_LIST_DIR}/thirdparty" )
# Compile options that are populated and set for each target depending on their type
set( ADDITIONAL_COMPILE_OPTIONS_EXE )
set( ADDITIONAL_COMPILE_OPTIONS_DLL )
set( ADDITIONAL_COMPILE_OPTIONS_LIB )
# Libraries that are linked to for each target depending on their type
set( ADDITIONAL_LINK_LIBRARIES_EXE )
set( ADDITIONAL_LINK_LIBRARIES_DLL )
# Linker options that are populated and set for each target depending on their type
set( ADDITIONAL_LINK_OPTIONS_EXE )
set( ADDITIONAL_LINK_OPTIONS_DLL )
set( ADDITIONAL_LINK_OPTIONS_LIB )
# Sources that are added to each target depending on their type
set( ADDITIONAL_SOURCES_EXE )
set( ADDITIONAL_SOURCES_DLL )
set( ADDITIONAL_SOURCES_LIB )
# Compile definitions that are added to each target depending on their type
set( ADDITIONAL_COMPILE_DEFINITIONS_EXE )
set( ADDITIONAL_COMPILE_DEFINITIONS_DLL )
set( ADDITIONAL_COMPILE_DEFINITIONS_LIB )
# SETUP THIRD PARTY, before we "customize" our compilation process
include( "thirdparty/init.cmake" )
# Init project structure
include( "_cmake_scripts/pch_skip.cmake" )
include( "_cmake_scripts/platform_dirs.cmake" )
include( "_cmake_scripts/base.cmake" )
include( "_cmake_scripts/video_base.cmake" )
include( "_cmake_scripts/helpers.cmake" )
set( LIBPUBLIC "${SRCDIR}/lib/public${PLATSUBDIR}" )
set( LIBCOMMON "${SRCDIR}/lib/common${PLATSUBDIR}" )
link_directories(
${LIBPUBLIC}
${LIBCOMMON}
)
include_directories(
"${SRCDIR}/common"
"${SRCDIR}/public"
"${SRCDIR}/public/tier0"
"${SRCDIR}/public/tier1"
)
if ( ${IS_WINDOWS} )
include( "_cmake_scripts/windows_base.cmake" )
elseif ( ${IS_POSIX} )
include("_cmake_scripts/posix_base.cmake")
endif()
# import the projects
include("_cmake_scripts/groups.cmake")
# Store all targets in a variable name ( See: https://stackoverflow.com/questions/37434946/how-do-i-iterate-over-all-cmake-targets-programmatically/62311397#62311397 )
function(get_all_targets var)
set(targets)
get_all_targets_recursive(targets ${CMAKE_CURRENT_SOURCE_DIR})
set(${var} ${targets} PARENT_SCOPE)
endfunction()
macro(get_all_targets_recursive targets dir)
get_property(subdirectories DIRECTORY ${dir} PROPERTY SUBDIRECTORIES)
foreach(subdir ${subdirectories})
set( found )
string( FIND REVERSE ${subdir} "thirdparty" ${found} )
# avoid checking in the third-party targets
if ( "${found}" STREQUAL "-1" )
get_all_targets_recursive(${targets} ${subdir})
endif ()
endforeach()
get_property(current_targets DIRECTORY ${dir} PROPERTY BUILDSYSTEM_TARGETS)
list(APPEND ${targets} ${current_targets})
endmacro()
get_all_targets(ALL_TARGETS)
# Set of helper functions to add defintions/options/libs for each target in a filtered way
function(add_compile_definitions_filtered target definitions)
foreach(additional_definition IN LISTS ${definitions})
set(SHOULD_EXCLUDE 0)
# Exclude the compile definition if target defines an exclude list
foreach(exclude IN LISTS "${target}_exclude_compile_definitions")
if (${additional_definition} STREQUAL ${exclude})
set(SHOULD_EXCLUDE 1)
break()
endif()
endforeach()
if (NOT ${SHOULD_EXCLUDE})
target_compile_definitions(${target} PRIVATE ${additional_definition})
endif()
endforeach()
endfunction()
function(add_compile_options_filtered target options)
foreach(additional_option IN LISTS ${options})
set(SHOULD_EXCLUDE 0)
# Exclude the compile options if target defines an exclude list
foreach(exclude IN LISTS "${target}_exclude_compile_options")
if (${additional_option} STREQUAL ${exclude})
set(SHOULD_EXCLUDE 1)
break()
endif()
endforeach()
if (NOT ${SHOULD_EXCLUDE})
target_compile_options(${target} PRIVATE "$<$<COMPILE_LANGUAGE:C,CXX>:${additional_option}>")
endif()
endforeach()
endfunction()
function(add_sources_filtered target sources)
foreach(additional_source IN LISTS ${sources})
set(SHOULD_EXCLUDE 0)
# Exclude the source if target defines an exclude list
foreach(exclude IN LISTS "${target}_exclude_source")
if (${additional_source} STREQUAL ${exclude})
set(SHOULD_EXCLUDE 1)
break()
endif()
endforeach()
if (NOT ${SHOULD_EXCLUDE})
target_sources(${target} PRIVATE ${additional_source})
endif()
endforeach()
endfunction()
function(add_libraries_filtered target libraries)
foreach(additional_lib IN LISTS ${libraries})
set(SHOULD_EXCLUDE 0)
# Exclude the lib if target defines an exclude list
foreach(exclude IN LISTS "${target}_exclude_lib")
if (${additional_lib} STREQUAL ${exclude})
set(SHOULD_EXCLUDE 1)
break()
endif()
endforeach()
if (NOT ${SHOULD_EXCLUDE})
get_target_property(libraries ${target} LINK_LIBRARIES)
# Don't bother adding it if the target already links it manually
foreach(lib IN LISTS libraries)
if (${additional_lib} STREQUAL ${lib})
set(SHOULD_EXCLUDE 1)
break()
endif()
endforeach()
endif()
if (NOT ${SHOULD_EXCLUDE})
target_link_libraries(${target} PRIVATE ${additional_lib})
endif()
endforeach()
endfunction()
# Iterates over all the targets and add necessary definitions/options/libs
# This is an incredible hack, but it allows for targets to specify exclude lists
# This allows us to emulate -$File and such from VPC
foreach(target ${ALL_TARGETS})
# Define an empty exclude list if one isn't defined
if (NOT DEFINED "${target}_exclude_compile_options")
set("${target}_exclude_compile_options")
endif()
# Define an empty exclude list if one isn't defined
if (NOT DEFINED "${target}_exclude_lib")
set("${target}_exclude_lib")
endif()
# Define an empty exclude list if one isn't defined
if (NOT DEFINED "${target}_exclude_source")
set("${target}_exclude_source")
endif()
get_target_property(target_type ${target} TYPE)
if (${target_type} STREQUAL "EXECUTABLE")
add_compile_options_filtered(${target} ADDITIONAL_COMPILE_OPTIONS_EXE)
add_libraries_filtered(${target} ADDITIONAL_LINK_LIBRARIES_EXE)
add_sources_filtered(${target} ADDITIONAL_SOURCES_EXE)
target_link_options(${target} PRIVATE ${ADDITIONAL_LINK_OPTIONS_EXE})
target_compile_definitions(${target} PRIVATE MEMOVERRIDE_MODULE=$<TARGET_NAME_IF_EXISTS:${target}>)
add_compile_definitions_filtered(${target} ADDITIONAL_COMPILE_DEFINITIONS_EXE)
# Only applies to Linux
target_strip_symbols(${target})
elseif((${target_type} STREQUAL "SHARED_LIBRARY") OR (${target_type} STREQUAL "MODULE_LIBRARY"))
add_compile_options_filtered(${target} ADDITIONAL_COMPILE_OPTIONS_DLL)
add_libraries_filtered(${target} ADDITIONAL_LINK_LIBRARIES_DLL)
add_sources_filtered(${target} ADDITIONAL_SOURCES_DLL)
target_link_options(${target} PRIVATE ${ADDITIONAL_LINK_OPTIONS_DLL})
target_compile_definitions(${target} PRIVATE MEMOVERRIDE_MODULE=$<TARGET_NAME_IF_EXISTS:${target}> DLLNAME=$<TARGET_NAME_IF_EXISTS:${target}>)
add_compile_definitions_filtered(${target} ADDITIONAL_COMPILE_DEFINITIONS_DLL)
# Only applies to Linux
target_strip_symbols(${target})
elseif(${target_type} STREQUAL "STATIC_LIBRARY")
add_compile_options_filtered(${target} ADDITIONAL_COMPILE_OPTIONS_LIB)
add_sources_filtered(${target} ADDITIONAL_SOURCES_LIB)
target_link_options(${target} PRIVATE ${ADDITIONAL_LINK_OPTIONS_LIB})
target_compile_definitions(${target} PRIVATE LIBNAME=$<TARGET_NAME_IF_EXISTS:${target}>)
add_compile_definitions_filtered(${target} ADDITIONAL_COMPILE_DEFINITIONS_LIB)
endif()
endforeach()