-
Notifications
You must be signed in to change notification settings - Fork 37
/
CMakeLists.txt
252 lines (218 loc) · 8.17 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
cmake_minimum_required (VERSION 3.12)
option(COF "Set COF_BUILD preprocessor flag if enabled" OFF)
option(SOFT "Set SOFTWARE_BUILD preprocessor flag if enabled" OFF)
option(HLSDK10 "Set HLSDK10_BUILD preprocessor flag if enabled" OFF)
set (CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/CMake")
if (NOT CMAKE_GENERATOR MATCHES "Visual Studio .+")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32")
endif ()
# Call project() after setting -m32 so it is taken into account.
# Specifically, this allows CMAKE_SIZEOF_VOID_P to get the correct 32-bit value.
project (BunnymodXT)
if (MSVC)
if (MSVC_TOOLSET_VERSION MATCHES "141")
set (MINHOOK_PROJECT_DIR "VC15")
elseif (MSVC_TOOLSET_VERSION MATCHES "142")
set (MINHOOK_PROJECT_DIR "VC16")
elseif (MSVC_TOOLSET_VERSION MATCHES "143")
set (MINHOOK_PROJECT_DIR "VC17")
else ()
message (FATAL_ERROR "Visual Studio 2017, 2019 or 2022 is required")
endif()
if (NOT CMAKE_GENERATOR_PLATFORM MATCHES "Win32")
message (FATAL_ERROR "Only the Win32 platform is supported. Pass -A Win32 to CMake")
endif ()
# Enable link-time code generation.
set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELEASE} /GL")
set (CMAKE_STATIC_LINKER_FLAGS_RELEASE "${CMAKE_STATIC_LINKER_FLAGS} ${CMAKE_STATIC_LINKER_FLAGS_RELEASE} /LTCG")
set (CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS} ${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /LTCG:incremental")
# Switch to the static runtime.
set (flag_variables
CMAKE_C_FLAGS_DEBUG
CMAKE_C_FLAGS_MINSIZEREL
CMAKE_C_FLAGS_RELEASE
CMAKE_C_FLAGS_RELWITHDEBINFO
CMAKE_CXX_FLAGS_DEBUG
CMAKE_CXX_FLAGS_MINSIZEREL
CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_RELWITHDEBINFO
)
foreach (variable ${flag_variables})
if (${variable} MATCHES "/MD")
string (REPLACE "/MD" "/MT" ${variable} "${${variable}}")
endif ()
endforeach ()
# If we're building for Windows XP, add a special compiler flag to fix a crash on Windows XP.
# http://stackoverflow.com/a/32953859/4214632
if (CMAKE_GENERATOR_TOOLSET MATCHES "_xp")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zc:threadSafeInit-")
endif ()
if (COF)
add_definitions(-DCOF_BUILD)
endif()
if (SOFT)
add_definitions(-DSOFTWARE_BUILD)
endif()
if (HLSDK10)
add_definitions(-DHLSDK10_BUILD)
endif()
else ()
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=pentium-m -mfpmath=387 -mno-sse -g -Wall -Wextra -Wno-unused-parameter")
if (NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# Not supported on Clang.
# Required for reproducibility of hlstrafe between different optimization levels.
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ffloat-store")
endif ()
if (NOT CMAKE_BUILD_TYPE OR CMAKE_BUILD_TYPE STREQUAL "Debug")
option (GLIBCXX_DEBUG "Enable libstdc++ debug checks." ON)
else ()
option (GLIBCXX_DEBUG "Enable libstdc++ debug checks." OFF)
endif ()
set(CMAKE_SHARED_LINKER_FLAGS
"${CMAKE_SHARED_LINKER_FLAGS} -static-libgcc -static-libstdc++")
endif ()
include(cotire)
include(GetGitRevisionDescription)
get_git_head_revision(GIT_REFSPEC GIT_SHA1)
git_describe(GIT_TAG --tags)
git_local_changes(GIT_LOCAL_CHANGES)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/BunnymodXT/git_revision.cpp.in" "${CMAKE_CURRENT_BINARY_DIR}/BunnymodXT/git_revision.cpp" @ONLY)
# Add discord-rpc
set(BUILD_EXAMPLES OFF CACHE BOOL "build discord-rpc examples" FORCE)
set(CLANG_FORMAT_SUFFIX "-dummy")
add_subdirectory(discord-rpc)
if(MSVC)
target_compile_options(discord-rpc PRIVATE
/wd4191 # 'reinterpret_cast': unsafe conversion from 'FARPROC' to 'RegSetKeyValueW_T'
/wd4571 # Informational: catch(...) semantics changed since Visual C++ 7.1; structured exceptions (SEH) are no longer caught
/wd4623 # 'std::_UInt_is_zero': default constructor was implicitly defined as deleted
/wd5039 # '_Thrd_start': pointer or reference to potentially throwing function passed to extern C function under -EHc. Undefined behavior may occur if this function throws an exception.
/wd5045 # "Compiler will insert Spectre mitigation if /Qspectre is enabled"
)
else(MSVC)
if(NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang")
target_compile_options(discord-rpc PRIVATE
$<$<COMPILE_LANGUAGE:CXX>:-Wno-class-memaccess>)
endif(NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang")
endif(MSVC)
find_package (Boost 1.57.0 REQUIRED)
include_directories (SYSTEM ${Boost_INCLUDE_DIR})
set (RapidJSON_ROOT "${CMAKE_SOURCE_DIR}/rapidjson")
# hltas is already included as part of hlstrafe.
add_subdirectory (hlstrafe)
add_subdirectory (taslogger)
include_directories ("." taslogger)
include_directories (SYSTEM ${RapidJSON_INCLUDE_DIR})
include_directories (SYSTEM cereal/include)
set (LIBRARY_OUTPUT_DIRECTORY ".")
set (WINDOWS_FILES
SPTLib/Windows/DetoursUtils.cpp
SPTLib/Windows/Hooks_win.cpp
SPTLib/Windows/MemUtils_win.cpp
SPTLib/Windows/DetoursUtils.hpp
BunnymodXT/Windows/conutils.cpp
BunnymodXT/Windows/dllmain.cpp
BunnymodXT/Windows/interprocess.cpp
BunnymodXT/Windows/conutils.hpp)
set (LINUX_FILES
SPTLib/Linux/Hooks_linux.cpp
SPTLib/Linux/MemUtils_linux.cpp
BunnymodXT/modules/PMSharedHooks_linux.cpp
BunnymodXT/Linux/main_linux.cpp
BunnymodXT/Linux/interprocess.cpp)
set (HEADER_FILES
SPTLib/IHookableModule.hpp
SPTLib/IHookableDirFilter.hpp
SPTLib/IHookableNameFilter.hpp
SPTLib/IHookableNameFilterOrdered.hpp
SPTLib/Hooks.hpp
SPTLib/MemUtils.hpp
SPTLib/patterns.hpp
SPTLib/sptlib.hpp
BunnymodXT/modules/HwDLL.hpp
BunnymodXT/modules/ClientDLL.hpp
BunnymodXT/modules/ServerDLL.hpp
BunnymodXT/modules/SDL.hpp
BunnymodXT/bunnymodxt.hpp
BunnymodXT/cmd_wrapper.hpp
BunnymodXT/custom_triggers.hpp
BunnymodXT/cvars.hpp
BunnymodXT/discord_integration.hpp
BunnymodXT/hud_custom.hpp
BunnymodXT/interprocess.hpp
BunnymodXT/modules.hpp
BunnymodXT/patterns.hpp
BunnymodXT/shared.hpp
BunnymodXT/sptlib-wrapper.hpp
BunnymodXT/stdafx.hpp
BunnymodXT/triangle_drawing.hpp
BunnymodXT/triangle_utils.hpp
BunnymodXT/opengl_utils.hpp
BunnymodXT/TEA.hpp
BunnymodXT/runtime_data.hpp
BunnymodXT/input_editor.hpp
BunnymodXT/simulation_ipc.hpp
BunnymodXT/splits.hpp
BunnymodXT/helper_functions.hpp
BunnymodXT/git_revision.hpp)
set (SOURCE_FILES
SPTLib/IHookableModule.cpp
SPTLib/IHookableDirFilter.cpp
SPTLib/IHookableNameFilter.cpp
SPTLib/IHookableNameFilterOrdered.cpp
SPTLib/Hooks.cpp
SPTLib/MemUtils.cpp
SPTLib/sptlib.cpp
BunnymodXT/modules/HwDLL.cpp
BunnymodXT/modules/ClientDLL.cpp
BunnymodXT/modules/ServerDLL.cpp
BunnymodXT/modules/SDL.cpp
BunnymodXT/custom_triggers.cpp
BunnymodXT/cvars.cpp
BunnymodXT/discord_integration.cpp
BunnymodXT/hud_custom.cpp
BunnymodXT/triangle_drawing.cpp
BunnymodXT/triangle_utils.cpp
BunnymodXT/opengl_utils.cpp
BunnymodXT/TEA.cpp
BunnymodXT/runtime_data.cpp
BunnymodXT/input_editor.cpp
BunnymodXT/simulation_ipc.cpp
BunnymodXT/splits.cpp
BunnymodXT/helper_functions.cpp
${CMAKE_CURRENT_BINARY_DIR}/BunnymodXT/git_revision.cpp)
if (MSVC)
include_external_msproject (MinHook "${CMAKE_SOURCE_DIR}/SPTLib/Windows/minhook/build/${MINHOOK_PROJECT_DIR}/libMinHook.vcxproj")
include_directories ("SPTLib/Windows/minhook/include")
set (SOURCE_FILES ${SOURCE_FILES} ${WINDOWS_FILES} ${HEADER_FILES})
else ()
set (SOURCE_FILES ${SOURCE_FILES} ${LINUX_FILES} ${HEADER_FILES})
endif ()
add_library (BunnymodXT SHARED ${SOURCE_FILES})
set_target_properties(BunnymodXT PROPERTIES
CXX_STANDARD 17
CXX_STANDARD_REQUIRED ON)
# Interaction between Cotire and C++17 enforcement breaks Clang,
# and due to something severely outdated in Cotire GCC refuses to use its precompiled headers too.
if (MSVC)
set_target_properties(BunnymodXT PROPERTIES
COTIRE_CXX_PREFIX_HEADER_INIT "BunnymodXT/stdafx.hpp")
cotire(BunnymodXT)
endif ()
if (NOT MSVC)
if (GLIBCXX_DEBUG)
# Don't enable on HLStrafe because the VCT becomes unusably slow with this.
target_compile_definitions (BunnymodXT PRIVATE _GLIBCXX_DEBUG)
# If I don't enable it on hltas-cpp, BXT crashes when trying to call HLTAS::Input::Clear().
target_compile_definitions (hltas-cpp PRIVATE _GLIBCXX_DEBUG)
message (STATUS "Enabled the libstdc++ debug mode")
endif ()
endif ()
target_link_libraries (BunnymodXT hltas-cpp hlstrafe taslogger discord-rpc)
if (NOT MSVC)
target_link_libraries (BunnymodXT pthread rt GL)
else()
add_dependencies (BunnymodXT MinHook)
target_link_libraries (BunnymodXT opengl32)
endif ()
install (TARGETS BunnymodXT)