forked from MSRevive/MasterSwordRebirth
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
160 lines (129 loc) · 5.9 KB
/
CMakeLists.txt
File metadata and controls
160 lines (129 loc) · 5.9 KB
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
# Based off Solokiller's Half Life Unified SDK, modified for MSR
# https://github.com/twhl-community/halflife-unified-sdk
cmake_minimum_required( VERSION 3.24 )
if (WIN32)
set(CMAKE_GENERATOR_PLATFORM win32)
endif(WIN32)
if (MSVC)
set(CMAKE_SYSTEM_VERSION 10.0)
endif()
if (UNIX)
# the name of the target operating system
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR i386)
# which compilers to use for C and C++
set(CMAKE_C_COMPILER gcc)
set(CMAKE_CXX_COMPILER g++)
set(CMAKE_CXX_FLAGS "-m32 -static-libgcc -static-libstdc++ -D_GLIBCXX_USE_CXX11_ABI=0")
set(CMAKE_MAKE_PROGRAM make)
set(VCPKG_TARGET_TRIPLET x86-linux)
# TODO: ultra-hack - cmake seems to be failing to create a directory to do a test compile in, so it won't run, but pretending that the compiler is fine works
set(CMAKE_CXX_COMPILER_FORCED true)
# include(${CMAKE_CURRENT_LIST_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake)
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()
option(INSTALL_DIR "Directory to copy built binaries to" "")
if(MSVC)
option(VS_DEBUG_WORK_DIR "Set working directory for VS Debug. This should be the directory where your MSRebirth test server is." "")
option(VS_DEBUG_CMD_ARGS "The arguements to start the program with." "")
endif()
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
# We now support C++ standard 20
set(CMAKE_CXX_STANDARD 20)
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 -Wno-narrowing -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
# /utf-8 is required for spdlog Unicode support
$<$<CXX_COMPILER_ID:MSVC>:/W3 /MP /utf-8>)
# 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)
add_subdirectory(src/game/tools/scriptpack)
# 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)
set_target_properties(scriptpack PROPERTIES
RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_CURRENT_SOURCE_DIR}/bins/debug
RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_CURRENT_SOURCE_DIR}/bins/release)