This repository has been archived by the owner on Oct 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathCMakeLists.txt
209 lines (178 loc) · 4.94 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
cmake_minimum_required(VERSION 3.15)
project(
OpenHack
VERSION 2.4.0
HOMEPAGE_URL "https://github.com/Prevter/OpenHack"
LANGUAGES C CXX
)
# Set the C++ standard to C++20
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
# Enable C++ exceptions for Clang-cl
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Xclang -fcxx-exceptions)
endif()
# Create build options
option(BUILD_STANDALONE "Build the standalone version" OFF)
option(BUILD_GEODE "Build the Geode version" ON)
# Get the latest abbreviated commit hash of the working branch
execute_process(
COMMAND git log -1 --format=%h
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
OUTPUT_VARIABLE GIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
# Set the default build type to RelWithDebInfo
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "Choose the type of build" FORCE)
endif()
# Configure the project version
configure_file(
${CMAKE_CURRENT_LIST_DIR}/cmake/version.h.in
${CMAKE_BINARY_DIR}/version.h
)
# ========================================
# | Shared files
# ========================================
file(
GLOB_RECURSE SHARED_SOURCE_FILES
${CMAKE_CURRENT_LIST_DIR}/src/shared/*.cpp
${CMAKE_CURRENT_LIST_DIR}/src/shared/*.hpp
)
add_library(
${PROJECT_NAME}
INTERFACE
"${CMAKE_BINARY_DIR}/version.h"
)
add_subdirectory(libs)
target_include_directories(
${PROJECT_NAME}
INTERFACE
${CMAKE_BINARY_DIR}
libs/glew/include
)
target_link_libraries(
${PROJECT_NAME}
INTERFACE
external_libs
opengl32
)
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
# Windows 64
target_link_libraries(
${PROJECT_NAME}
INTERFACE
${CMAKE_SOURCE_DIR}/libs/glew/lib/Release/x64/glew32.lib
)
else()
# Windows 32
target_link_libraries(
${PROJECT_NAME}
INTERFACE
${CMAKE_SOURCE_DIR}/libs/glew/lib/Release/Win32/glew32.lib
)
endif()
if (PROJECT_IS_TOP_LEVEL)
target_compile_definitions(${PROJECT_NAME} INTERFACE OPENHACK_EXPORT)
endif()
# ========================================
# | Geode build
# ========================================
if (NOT BUILD_GEODE)
message(STATUS "Geode build disabled")
elseif (NOT DEFINED ENV{GEODE_SDK})
message(STATUS "Geode SDK not found, skipping Geode build")
else()
message(STATUS "Found Geode: $ENV{GEODE_SDK}")
file(
GLOB_RECURSE GEODE_SOURCE_FILES
${CMAKE_CURRENT_LIST_DIR}/src/geode/*.cpp
${CMAKE_CURRENT_LIST_DIR}/src/geode/*.hpp
)
# Export symbols for better debugging
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
add_library(
${PROJECT_NAME}-Geode
SHARED
${SHARED_SOURCE_FILES}
${GEODE_SOURCE_FILES}
)
add_subdirectory($ENV{GEODE_SDK} ${CMAKE_CURRENT_BINARY_DIR}/geode)
set(HAS_IMGUI ON)
add_subdirectory(libs/imgui-cocos)
target_link_libraries(
${PROJECT_NAME}-Geode
${PROJECT_NAME}
imgui-cocos
)
# Set "OPENHACK_GEODE" to 1
target_compile_definitions(
${PROJECT_NAME}-Geode
PRIVATE
OPENHACK_GEODE=1
)
setup_geode_mod(${PROJECT_NAME}-Geode)
endif()
# ========================================
# | Standalone build
# ========================================
if (BUILD_STANDALONE)
message(ERROR "Standalone build is deprecated, please use Geode instead")
return()
endif()
if (NOT BUILD_STANDALONE)
message(STATUS "Standalone build disabled")
return()
endif()
file(
GLOB_RECURSE STANDALONE_SOURCE_FILES
${CMAKE_CURRENT_LIST_DIR}/src/standalone/*.cpp
${CMAKE_CURRENT_LIST_DIR}/src/standalone/*.hpp
${CMAKE_CURRENT_LIST_DIR}/src/standalone/*.def
)
add_library(
${PROJECT_NAME}-Standalone
SHARED
${SHARED_SOURCE_FILES}
${STANDALONE_SOURCE_FILES}
)
add_subdirectory(libs/minhook)
add_subdirectory(libs/spdlog)
add_subdirectory(libs/curl)
add_subdirectory(libs/cocos-headers)
target_include_directories(
${PROJECT_NAME}-Standalone
PRIVATE
libs/imgui-markdown
libs/glew/include
)
target_link_libraries(
${PROJECT_NAME}-Standalone
${PROJECT_NAME}
minhook
spdlog::spdlog
libcurl
cocos2d
)
# Set "OPENHACK_STANDALONE" to 1
target_compile_definitions(
${PROJECT_NAME}-Standalone
PRIVATE
OPENHACK_STANDALONE=1
)
set_target_properties(
${PROJECT_NAME}-Standalone
PROPERTIES
OUTPUT_NAME "xinput1_4"
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/bin"
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/bin"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/bin"
)
# Create "openhack" directory in the output directory and copy everything from "resources" to it
add_custom_command(
TARGET ${PROJECT_NAME}-Standalone
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_SOURCE_DIR}/bin/openhack"
COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_SOURCE_DIR}/resources" "${CMAKE_SOURCE_DIR}/bin/openhack"
)