-
Notifications
You must be signed in to change notification settings - Fork 8
/
CMakeLists.txt
136 lines (110 loc) · 5 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
# Based off Solokiller's Half Life Unified SDK, modified for MSR
# https://github.com/twhl-community/halflife-unified-sdk
cmake_minimum_required( VERSION 3.23 )
if (WIN32)
set(CMAKE_GENERATOR_PLATFORM win32)
endif(WIN32)
if (MSVC)
set(CMAKE_SYSTEM_VERSION 10.0)
endif()
project(msr
VERSION 1.0.0
LANGUAGES CXX)
set(CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "" FORCE)
# Disable the use of absolute paths in library paths even in development builds.
set(CMAKE_SKIP_BUILD_RPATH ON)
# Link statically with the runtime
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
# Because we have 2 libraries that use the same symbols we have to default visibility to hidden so there are no collisions,
# and so the symbols don't merge and cause problems like server code calling the client version of a function.
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
# 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()
if(MSVC)
set(VS_DEBUG_WORK_DIR "" CACHE PATH "Set working directory for VS Debug. This should be the directory where your MSRebirth test server is.")
set(VS_DEBUG_CMD_ARGS "" CACHE STRING "The arguements to start the program with.")
endif()
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
# Modern VS versions default to C++14 anyway, so make it consistent
# But in the future we may want so support C++20
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(BASEDIR "${CMAKE_CURRENT_SOURCE_DIR}")
function(set_common_properties TARGET_NAME)
# Compile Flags and such.
set_target_properties(${TARGET_NAME} PROPERTIES PREFIX "")
if (UNIX)
target_compile_definitions(${TARGET_NAME} PRIVATE
_snprintf=snprintf
_stricmp=strcasecmp
_strnicmp=strncasecmp
_strdup=strdup
_vsnprintf=vsnprintf)
endif(UNIX)
# Make sure C++ exceptions are enabled.
if (MSVC)
target_compile_options(${TARGET_NAME} PUBLIC /EHsc)
else()
target_compile_options(${TARGET_NAME} PUBLIC -fexceptions)
endif()
target_compile_definitions(${TARGET_NAME} PRIVATE
_CRT_SECURE_NO_WARNINGS
$<$<CONFIG:DEBUG>:_DEBUG>
$<$<PLATFORM_ID:Linux>:POSIX _POSIX LINUX _LINUX GNUC>)
target_compile_options(${TARGET_NAME} PRIVATE
# force 387 for FP math so the precision between win32 and linux and osx match
# Note: the pentium-m arch setting is not used for AMD systems in the original makefile
# Since the arch settings used are i686 this means including the setting ensures original settings are used,
# but it could cause problems for AMD targets
$<$<CXX_COMPILER_ID:GNU>:-fpermissive -fno-strict-aliasing -Wno-invalid-offsetof -Wno-write-strings -Wno-pointer-arith -march=pentium-m -mfpmath=387>
# flifetime-dse=1 is needed to disable a compiler optimization that optimizes out std::memset calls in CBaseEntity::operator new
# See https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html#index-flifetime-dse for more information about this flag
# fno-gnu-unique is needed to disable a compiler optimization that prevents dlclose from unloading mod dlls,
# causing them to retain state and crash when the engine tries to access memory in an invalid way
# See https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#index-fno-gnu-unique for more information about this flag
$<$<CXX_COMPILER_ID:GNU>:-fno-lifetime-dse -fno-gnu-unique>
# Can't set warning level to W4 until the compiler can deal with std::visit containing static_assert, which currently causes false positive "Unreachable code" warnings
$<$<CXX_COMPILER_ID:MSVC>:/W3 /MP>)
# Disable certain compiler warnings.
if (MSVC)
target_compile_options(${TARGET_NAME} PRIVATE
# int or float down-conversion
/wd4244
# int or float data truncation
/wd4305
# unreferenced inline function removed
/wd4514
# unreferenced formal parameter
/wd4100
# Variable is uninitialized
/wd26495
# Arithmetic overflow
/wd26451
# The enum type is unscoped
/wd26812)
endif()
target_link_options(${TARGET_NAME} PRIVATE
$<$<CXX_COMPILER_ID:GNU>:-Wl,--no-undefined>
$<$<PLATFORM_ID:Linux>:-static-libstdc++ -Wl,-Map,${TARGET_NAME}_map.txt>)
endfunction(set_common_properties)
add_compile_definitions($<$<CONFIG:Debug>:DEBUG> $<$<CONFIG:Debug>:_DEBUG>)
add_compile_definitions($<$<CONFIG:Release>:NDEBUG>)
# Add Projects
add_subdirectory(src/game/client)
add_subdirectory(src/game/server)
# Set Visual Studio starting project
if (MSVC)
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT client)
endif()
if(MSVC)
set_target_properties(client PROPERTIES
RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_CURRENT_SOURCE_DIR}/bins/debug
RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_CURRENT_SOURCE_DIR}/bins/release)
endif()
set_target_properties(server PROPERTIES
RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_CURRENT_SOURCE_DIR}/bins/debug
RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_CURRENT_SOURCE_DIR}/bins/release)