-
-
Notifications
You must be signed in to change notification settings - Fork 30
/
CMakeLists.txt
135 lines (111 loc) · 4.27 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
cmake_minimum_required(VERSION 3.19)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/")
cmake_policy(SET CMP0091 NEW)
include(VcpkgIntegration)
include(VcpkgAndroid)
option(BUILD_CLIENT "Build client library" ON)
option(BUILD_SERVER "Build server library" ON)
option(BUILD_UTILS "Build developer utilities (map/models compilers, etc.)" ON)
option(BUILD_GAME_LAUNCHER "Build game launcher executable" ON)
option(ENABLE_PHYSX "Enable PhysX support" ON)
option(ENABLE_VGUI_COMPATIBILITY "Enable VGUI compatibility (for better compatibility with old code)" OFF)
option(ENABLE_ASAN "Enable AddressSanitizer globally" OFF)
option(ENABLE_STATIC_CRT_LINKING "Enable static runtime linking for project targets" ON)
set(GAMEDIR "primext" CACHE STRING "Game directory name")
set(SERVER_INSTALL_DIR "bin" CACHE STRING "Server library path relative to game directory")
set(CLIENT_INSTALL_DIR "bin" CACHE STRING "Client library path relative to game directory")
set(UTILS_INSTALL_DIR "devkit" CACHE STRING "Utilities path relative to game directory")
set(SERVER_LIBRARY_NAME "server" CACHE STRING "Library name for Linux/MacOS/Windows")
set(CMAKE_CXX_STANDARD 17)
if(BUILD_CLIENT)
list(APPEND VCPKG_MANIFEST_FEATURES "client")
endif()
if(BUILD_SERVER)
list(APPEND VCPKG_MANIFEST_FEATURES "server")
if(ENABLE_PHYSX)
list(APPEND VCPKG_MANIFEST_FEATURES "physx")
endif()
endif()
if(BUILD_UTILS)
list(APPEND VCPKG_MANIFEST_FEATURES "utils")
endif()
project(PrimeXT)
# Xash3D FWGS Library Naming Scheme compliance
# Documentation: https://github.com/FWGS/xash3d-fwgs/blob/master/Documentation/library-naming.md
include(LibraryNaming)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
message(STATUS "Building for 64-bit")
else()
message(STATUS "Building for 32-bit")
endif()
# get current git commit short hash
execute_process(COMMAND "git" "describe" "--always" "--dirty" "--abbrev=7"
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE SHORT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(SHORT_HASH)
message(STATUS "Current Git commit hash: ${SHORT_HASH}")
add_definitions(-DXASH_BUILD_COMMIT="${SHORT_HASH}")
else()
message(STATUS "Failed to set current Git commit hash")
endif()
# multithreaded build flag for MSVC
add_compile_options($<$<CXX_COMPILER_ID:MSVC>:/MP>)
# these should be BEFORE any add_library/add_executable calls
if(NOT MSVC)
#add_compile_options(-Wempty-body) # GCC/Clang flag
add_compile_options(-Wreturn-type) # GCC/Clang flag
add_compile_options(-Wno-invalid-offsetof)
add_compile_options(-Wno-conversion-null)
else()
add_definitions(-D_CRT_SILENCE_NONCONFORMING_TGMATH_H)
endif()
# enable AddressSanitizer globally for all subprojects
if(ENABLE_ASAN)
if(MSVC)
add_compile_options(/fsanitize=address)
else()
add_compile_options(-fsanitize=address)
add_link_options(-fsanitize=address)
endif()
endif()
if(BUILD_CLIENT)
add_subdirectory(client)
endif()
if(BUILD_SERVER)
add_subdirectory(server)
endif()
if(BUILD_UTILS)
add_subdirectory(utils)
endif()
if(BUILD_GAME_LAUNCHER)
add_subdirectory(game_launcher)
endif()
# set build output directory
set(DIR_COMMON_OUTPUT
${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/${GAMEDIR}/bin/
)
message(STATUS "Compiled binaries output directory: ${DIR_COMMON_OUTPUT}")
if(BUILD_CLIENT)
set_target_properties(client PROPERTIES DEBUG_POSTFIX "${XASH_BUILD_POSTFIX}")
set_target_properties(client PROPERTIES RELEASE_POSTFIX "${XASH_BUILD_POSTFIX}")
set_target_properties(client PROPERTIES RELWITHDEBINFO_POSTFIX "${XASH_BUILD_POSTFIX}")
set_target_properties(client PROPERTIES MINSIZEREL_POSTFIX "${XASH_BUILD_POSTFIX}")
set_target_properties(client PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY ${DIR_COMMON_OUTPUT}
LIBRARY_OUTPUT_DIRECTORY ${DIR_COMMON_OUTPUT}
RUNTIME_OUTPUT_DIRECTORY ${DIR_COMMON_OUTPUT}
)
endif()
if(BUILD_SERVER)
set_target_properties(server PROPERTIES DEBUG_POSTFIX "${XASH_BUILD_POSTFIX}")
set_target_properties(server PROPERTIES RELEASE_POSTFIX "${XASH_BUILD_POSTFIX}")
set_target_properties(server PROPERTIES RELWITHDEBINFO_POSTFIX "${XASH_BUILD_POSTFIX}")
set_target_properties(server PROPERTIES MINSIZEREL_POSTFIX "${XASH_BUILD_POSTFIX}")
set_target_properties(server PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY ${DIR_COMMON_OUTPUT}
LIBRARY_OUTPUT_DIRECTORY ${DIR_COMMON_OUTPUT}
RUNTIME_OUTPUT_DIRECTORY ${DIR_COMMON_OUTPUT}
)
endif()