This repository has been archived by the owner on Nov 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
301 lines (270 loc) · 9.45 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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
cmake_minimum_required (VERSION 2.8.8)
include (CheckIncludeFiles)
project (MBExtender C CXX ASM)
if (UNIX)
# Set Unix-specific flags
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-unused-variable -std=c++14 -fvisibility=hidden")
enable_language (ASM)
# Force 32 bit
# NOTE: This causes issues with Xcode. You still have to explicitly set a 32-bit target.
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32")
set (CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -m32")
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m32")
set (CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -m32")
elseif (MSVC)
# Set VC++ settings
cmake_policy (SET CMP0054 NEW) # CMake complains otherwise when we call enable_language
set (CMAKE_CXX_STANDARD 14)
enable_language (ASM_MASM)
set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /SAFESEH:NO") # SAFESEH needs to be disabled because LDE64 doesn't support it
# Force use of static runtime library
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MDd /Zp8")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MD /Zp8")
endif ()
# Set OS X dylibs to be loaded from the executable directory
set (CMAKE_MACOSX_RPATH ON)
set (CMAKE_BUILD_WITH_INSTALL_RPATH ON)
set (CMAKE_INSTALL_NAME_DIR "@executable_path")
# Check for cpuid.h or intrin.h in order to use cpuid
check_include_files (cpuid.h HAVE_CPUID_H)
check_include_files (intrin.h HAVE_INTRIN_H)
if (NOT HAVE_CPUID_H AND NOT HAVE_INTRIN_H)
message (FATAL_ERROR "Either cpuid.h or intrin.h is required.")
endif ()
# Generate a config.h file
configure_file(${PROJECT_SOURCE_DIR}/config.h.in ${PROJECT_BINARY_DIR}/config.h)
add_definitions(-DHAVE_CONFIG_H)
# Register public include folder and build folder
include_directories (include ${PROJECT_BINARY_DIR})
# Launcher (Mac/Linux only)
if (UNIX)
add_executable (MBExtender src/MBExtender/main-unix.cpp)
endif ()
# Plugin loader
set (PLUGINLOADER_SRC
src/PluginLoader/BasicPluginInterface.cpp
src/PluginLoader/CodeAllocator.cpp
src/PluginLoader/CodeInjectionStream.cpp
src/PluginLoader/FuncInterceptor.cpp
src/PluginLoader/PluginLoader.cpp
src/PluginLoader/TrampolineGenerator.cpp
src/PluginLoader/Filesystem-common.cpp
src/PluginLoader/StringUtil.cpp
include/PluginLoader/PluginInterface.h
src/PluginLoader/BasicPluginInterface.h
src/PluginLoader/CodeAllocator.h
src/PluginLoader/CodeInjectionStream.h
src/PluginLoader/FuncInterceptor.h
src/PluginLoader/TrampolineGenerator.h
src/PluginLoader/Filesystem.h
src/PluginLoader/StringUtil.h
)
if (UNIX)
set (PLUGINLOADER_SRC ${PLUGINLOADER_SRC}
src/PluginLoader/unix/LDE64-as.s
src/PluginLoader/unix/main-unix.cpp
src/PluginLoader/unix/Memory-unix.cpp
src/PluginLoader/unix/SharedObject-unix.cpp
src/PluginLoader/unix/Filesystem-unix.cpp
)
elseif (WIN32)
set (PLUGINLOADER_SRC ${PLUGINLOADER_SRC}
src/PluginLoader/win32/LDE64-masm.asm
src/PluginLoader/win32/main-win32.cpp
src/PluginLoader/win32/Memory-win32.cpp
src/PluginLoader/win32/SharedObject-win32.cpp
src/PluginLoader/win32/Filesystem-win32.cpp
)
endif ()
add_library (PluginLoader SHARED ${PLUGINLOADER_SRC})
if (MSVC)
set_property (TARGET PluginLoader APPEND PROPERTY LINK_FLAGS "/DEF:\"${PROJECT_SOURCE_DIR}/src/PluginLoader/win32/PluginLoader.def\"")
endif ()
# TorqueLib
set (TORQUELIB_SRC
src/TorqueLib/TorqueLib.cpp
src/TorqueLib/math/mAngAxis.cpp
src/TorqueLib/math/mathUtils.cpp
src/TorqueLib/math/mBox.cpp
src/TorqueLib/math/mEase.cpp
src/TorqueLib/math/mMath_C.cpp
src/TorqueLib/math/mMathAMD.cpp
src/TorqueLib/math/mMathSSE.cpp
src/TorqueLib/math/mMatrix.cpp
src/TorqueLib/math/mOrientedBox.cpp
src/TorqueLib/math/mPlane.cpp
src/TorqueLib/math/mPlaneTransformer.cpp
src/TorqueLib/math/mPoint.cpp
src/TorqueLib/math/mQuat.cpp
src/TorqueLib/math/mRandom.cpp
src/TorqueLib/math/mRect.cpp
src/TorqueLib/math/mSolver.cpp
src/TorqueLib/math/mSphere.cpp
src/TorqueLib/math/util/quadTransforms.cpp
include/TorqueLib/TGE.h
include/TorqueLib/QuickOverride.h
include/TorqueLib/platform/platform.h
include/TorqueLib/platform/platformAssert.h
include/TorqueLib/math/mAngAxis.h
include/TorqueLib/math/mathUtils.h
include/TorqueLib/math/mBox.h
include/TorqueLib/math/mBoxBase.h
include/TorqueLib/math/mConstants.h
include/TorqueLib/math/mEase.h
include/TorqueLib/math/mMath.h
include/TorqueLib/math/mMathFn.h
include/TorqueLib/math/mMatrix.h
include/TorqueLib/math/mOrientedBox.h
include/TorqueLib/math/mPlane.h
include/TorqueLib/math/mPlaneSet.h
include/TorqueLib/math/mPlaneTransformer.h
include/TorqueLib/math/mPoint2.h
include/TorqueLib/math/mPoint3.h
include/TorqueLib/math/mPoint4.h
include/TorqueLib/math/mQuat.h
include/TorqueLib/math/mRandom.h
include/TorqueLib/math/mRandomDeck.h
include/TorqueLib/math/mRandomSet.h
include/TorqueLib/math/mRect.h
include/TorqueLib/math/mSilhouetteExtractor.h
include/TorqueLib/math/mSphere.h
include/TorqueLib/math/mTransform.h
include/TorqueLib/math/util/quadTransforms.h
include/TorqueLib/util/tVector.h
)
if (WIN32)
set (TORQUELIB_SRC ${TORQUELIB_SRC}
include/TorqueLib/win32/Addresses-win32.h
include/TorqueLib/win32/InterfaceMacros-win32.h
)
elseif (APPLE)
set (TORQUELIB_SRC ${TORQUELIB_SRC}
include/TorqueLib/osx/Addresses-osx.h
include/TorqueLib/linux/InterfaceMacros-linux.h
)
elseif (UNIX)
set (TORQUELIB_SRC ${TORQUELIB_SRC}
include/TorqueLib/linux/Addresses-linux.h
include/TorqueLib/linux/InterfaceMacros-linux.h
)
endif()
add_library (TorqueLib SHARED ${TORQUELIB_SRC})
set_property (TARGET TorqueLib APPEND PROPERTY INCLUDE_DIRECTORIES ${PROJECT_SOURCE_DIR}/include/TorqueLib/math ${PROJECT_SOURCE_DIR}/include/TorqueLib/math/util)
set (REWIND_SRC
plugins/Rewind/Frame.cpp
plugins/Rewind/Rewind.cpp
plugins/Rewind/Logging.cpp
plugins/Rewind/TorqueExports.cpp
plugins/Rewind/RewindManager.cpp
plugins/Rewind/RewindApi.cpp
plugins/Rewind/MemoryStream.cpp
plugins/Rewind/WorkerThread.cpp
plugins/Rewind/Dispatcher.cpp
plugins/Rewind/Frame.h
plugins/Rewind/Rewind.h
plugins/Rewind/RewindManager.h
plugins/Rewind/StringMath.h
plugins/Rewind/RewindApi.h
plugins/Rewind/MemoryStream.h
plugins/Rewind/WorkerThread.h
plugins/Rewind/Logging.h
plugins/Rewind/Dispatcher.h
)
# RewindPlugin
if (MBPBuild)
set(TARGETLIB MBPRewind)
else()
set(TARGETLIB Rewind)
endif()
add_library (${TARGETLIB} MODULE ${REWIND_SRC})
target_include_directories(${TARGETLIB} PRIVATE zlib)
option(MBPBUILD "MBP Features" OFF)
if (MBPBUILD)
add_definitions(-DMBP)
endif()
target_link_libraries (${TARGETLIB} TorqueLib)
if (MSVC)
target_link_libraries(${TARGETLIB} ${CMAKE_SOURCE_DIR}/zlibstat.lib)
elseif (APPLE)
target_link_libraries(${TARGETLIB} z)
endif()
function(import_framework NAME)
set(CMAKE_FIND_FRAMEWORK ONLY)
find_library(${NAME}_FRAMEWORK ${NAME})
if("${${NAME}_FRAMEWORK}" MATCHES "NOTFOUND\$")
message(SEND_ERROR "Unable to find ${NAME}.framework")
endif()
add_library(${NAME} SHARED IMPORTED GLOBAL)
set_target_properties(${NAME} PROPERTIES
IMPORTED_LOCATION "${${NAME}_FRAMEWORK}/${NAME}")
endfunction()
# DiscordRPC plugin
if(APPLE)
import_framework(AppKit)
endif()
add_subdirectory(${CMAKE_SOURCE_DIR}/external/rapidjson)
add_subdirectory(${CMAKE_SOURCE_DIR}/external/discord-rpc)
if (MSVC)
set (DISCORDRPC_SRC
plugins/DiscordRPC/main.cpp
plugins/DiscordRPC/include/win/discord_register.h
plugins/DiscordRPC/include/win/discord_rpc.h
)
else()
set (DISCORDRPC_SRC
plugins/DiscordRPC/main.cpp
plugins/DiscordRPC/include/osx/discord_register.h
plugins/DiscordRPC/include/osx/discord_rpc.h
)
endif()
add_library(DiscordRPC MODULE ${DISCORDRPC_SRC})
target_link_libraries(DiscordRPC TorqueLib discord-rpc)
# FrameRateUnlock
set (FRAMERATEUNLOCK_SRC
plugins/FrameRateUnlock/FrameRateUnlock.cpp
plugins/FrameRateUnlock/GameTimer.hpp
)
if (WIN32)
set (FRAMERATEUNLOCK_SRC ${FRAMERATEUNLOCK_SRC}
plugins/FrameRateUnlock/win32/HighPerformanceTimer-win32.cpp
plugins/FrameRateUnlock/win32/HighPerformanceTimer-win32.hpp
plugins/FrameRateUnlock/win32/MultimediaTimer-win32.cpp
plugins/FrameRateUnlock/win32/MultimediaTimer-win32.hpp
)
elseif (APPLE)
set (FRAMERATEUNLOCK_SRC ${FRAMERATEUNLOCK_SRC}
plugins/FrameRateUnlock/osx/MachTimer-osx.cpp
plugins/FrameRateUnlock/osx/MachTimer-osx.hpp
)
elseif (UNIX)
set (FRAMERATEUNLOCK_SRC ${FRAMERATEUNLOCK_SRC}
plugins/FrameRateUnlock/linux/MonotonicTimer-linux.cpp
plugins/FrameRateUnlock/linux/MonotonicTimer-linux.hpp
)
endif ()
add_library (FrameRateUnlock MODULE ${FRAMERATEUNLOCK_SRC})
target_link_libraries (FrameRateUnlock TorqueLib)
if (WIN32)
target_link_libraries (FrameRateUnlock winmm)
endif ()
# Remove the "lib" prefix from libraries
set_target_properties (PluginLoader TorqueLib DiscordRPC FrameRateUnlock ${TARGETLIB} PROPERTIES PREFIX "")
if (MBPBUILD)
set_target_properties(${TARGETLIB} PROPERTIES PREFIX "MBP")
endif()
# Install rules
if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set (CMAKE_INSTALL_PREFIX "${PROJECT_BINARY_DIR}/install" CACHE PATH "default install path" FORCE)
endif()
install (TARGETS PluginLoader RUNTIME DESTINATION bin LIBRARY DESTINATION bin)
install (TARGETS TorqueLib RUNTIME DESTINATION bin LIBRARY DESTINATION bin ARCHIVE DESTINATION lib)
install (TARGETS ${TARGETLIB} DESTINATION bin/plugins)
install (TARGETS DiscordRPC DESTINATION bin/plugins)
install (TARGETS FrameRateUnlock DESTINATION bin/plugins)
#if (WIN32)
#install (TARGETS MBGPatcher DESTINATION bin)
if (UNIX)
install (TARGETS MBExtender DESTINATION bin)
endif ()
install (DIRECTORY include/ DESTINATION include FILES_MATCHING PATTERN "*.h")