-
Notifications
You must be signed in to change notification settings - Fork 33
/
CMakeLists.txt
320 lines (264 loc) · 10.4 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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
cmake_minimum_required(VERSION 3.21)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
project(globed2 VERSION 1.0.1)
# set ios archs
if (${CMAKE_SYSTEM_NAME} STREQUAL "iOS")
message(STATUS "building for ios")
unset(CMAKE_OSX_ARCHITECTURES)
set(CMAKE_OSX_ARCHITECTURES "arm64")
set(CMAKE_OSX_DEPLOYMENT_TARGET "14.0")
set(CMAKE_SYSTEM_NAME "iOS")
else()
message(STATUS "building for mac")
set(CMAKE_OSX_ARCHITECTURES "arm64;x86_64")
endif()
option(GLOBED_OSS_BUILD "Open source build that does not require closed-source dependencies" OFF)
option(GLOBED_NATIVE_ARCH "Native architecture build" OFF)
# on windows use precompiled, on other platforms compile libsodium
if (WIN32)
option(GLOBED_COMPILE_LIBS "Don't use precompiled libraries and compile manually" OFF)
else()
option(GLOBED_COMPILE_LIBS "Don't use precompiled libraries and compile manually" ON)
endif()
# check if compiler is clang
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(GLOBED_IS_CLANG ON)
else()
set(GLOBED_IS_CLANG OFF)
endif()
# check if it's clang-cl or clang
if (CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "GNU")
set(GLOBED_IS_CLANG_CL OFF)
else()
set(GLOBED_IS_CLANG_CL ON)
endif()
# Check for debug build
option(ENABLE_DEBUG "Debug mode" OFF)
option(GLOBED_RELEASE "Release build" OFF)
if (CMAKE_BUILD_TYPE STREQUAL "Debug" OR "${CMAKE_BUILD_TYPE}asdf" STREQUAL "asdf" OR ENABLE_DEBUG)
set(GLOBED_IS_DEBUG ON)
endif()
# Debug/Release options
if (GLOBED_IS_DEBUG)
add_compile_definitions(GLOBED_DEBUG=1)
add_compile_definitions(GEODE_DEBUG=1)
add_compile_definitions(ASP_ENABLE_DEBUG=1)
# # turn on asan
# if (GLOBED_IS_CLANG)
# if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/libs/stl_asan.lib")
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
# set(GLOBED_LINK_TO_ASAN ON)
# endif()
# # no omit frame pointer
# if (NOT GLOBED_IS_CLANG_CL)
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-omit-frame-pointer")
# endif()
# endif()
elseif (GLOBED_RELEASE)
# Enable LTO in release (2.5x less binary size, costs only a few extra seconds of build time)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
endif()
# add thingies depending on the current system
if (ANDROID)
file(GLOB_RECURSE OS_SOURCES "src/platform/os/android/*.cpp" "src/platform/arch/arm/*.cpp")
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "iOS")
file(GLOB_RECURSE OS_SOURCES "src/platform/os/ios/*.cpp" "src/platform/arch/arm/*.cpp")
elseif (APPLE)
file(GLOB_RECURSE OS_SOURCES "src/platform/os/mac/*.cpp" "src/platform/arch/x86/*.cpp" "src/platform/arch/arm/*.cpp")
elseif (WIN32)
file(GLOB_RECURSE OS_SOURCES "src/platform/os/windows/*.cpp" "src/platform/arch/x86/*.cpp")
else()
message(FATAL_ERROR "Unsupported operating system")
endif()
# source files
file(GLOB_RECURSE SOURCES
src/audio/*.cpp
src/crypto/*.cpp
src/data/*.cpp
src/globed/*.cpp
src/game/*.cpp
src/hooks/*.cpp
src/managers/*.cpp
src/net/*.cpp
src/ui/*.cpp
src/util/*.cpp
src/main.cpp
${OS_SOURCES}
)
add_library(${PROJECT_NAME} SHARED ${SOURCES})
# Windows - do stuff
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
add_compile_definitions(WIN32_LEAN_AND_MEAN=1) # geode moment
if (NOT MSVC)
set(GLOBED_WINDOWS_CLANG ON)
endif()
endif()
if (GLOBED_RELEASE)
target_compile_definitions(${PROJECT_NAME} PRIVATE GLOBED_RELEASE=1)
endif()
# export some symbols
target_compile_definitions(${PROJECT_NAME} PRIVATE GLOBED_EXPORTING)
if (CMAKE_HOST_SYSTEM MATCHES "Linux" AND CMAKE_SYSTEM_NAME STREQUAL "Windows")
target_compile_definitions(${PROJECT_NAME} PRIVATE GLOBED_LINUX_COMPILATION=1)
endif()
if (NOT DEFINED ENV{GEODE_SDK})
message(FATAL_ERROR "Unable to find Geode SDK! Please define GEODE_SDK environment variable to point to Geode")
else()
message(STATUS "Found Geode: $ENV{GEODE_SDK}")
endif()
add_subdirectory($ENV{GEODE_SDK} ${CMAKE_CURRENT_BINARY_DIR}/geode)
# done so you can include root files with <file.hpp>
target_include_directories(${PROJECT_NAME} PRIVATE src/)
target_include_directories(${PROJECT_NAME} PRIVATE libs/)
# our favorite libraries
CPMAddPackage("gh:dankmeme01/uibuilder#c30755a")
CPMAddPackage(
NAME Boost
VERSION 1.86.0
URL https://github.com/boostorg/boost/releases/download/boost-1.86.0/boost-1.86.0-cmake.7z
URL_HASH SHA256=ee6e0793b5ec7d13e7181ec05d3b1aaa23615947295080e4b9930324488e078f
OPTIONS "BOOST_ENABLE_CMAKE ON" "BOOST_INCLUDE_LIBRARIES describe\\\;stacktrace\\\;thread" # escape with \\\;
)
CPMAddPackage("gh:dankmeme01/asp2#2378a82")
# asp defines
if (WIN32)
if (GLOBED_IS_DEBUG)
# debug
target_compile_definitions(asp PRIVATE _HAS_ITERATOR_DEBUGGING=0)
endif()
# thingy
target_compile_definitions(asp PRIVATE ASP_ENABLE_FORMAT=1)
target_compile_definitions(${PROJECT_NAME} PRIVATE ASP_ENABLE_FORMAT=1)
endif()
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/globed-codegen")
target_include_directories("${PROJECT_NAME}" PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/globed-codegen")
include(cmake/baked_resources_gen.cmake)
generate_baked_resources_header("${CMAKE_CURRENT_SOURCE_DIR}/embedded-resources.json" "${CMAKE_CURRENT_BINARY_DIR}/globed-codegen/embedded_resources.hpp")
if (GLOBED_NATIVE_ARCH)
# Apply native architecture
add_compile_options("-march=native")
endif()
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
target_compile_options(${PROJECT_NAME} PRIVATE "-Wno-deprecated-declarations")
# target_compile_options(${PROJECT_NAME} PRIVATE "-ftime-trace")
# target_compile_options(asp PRIVATE "-ftime-trace")
# if (WIN32)
# target_compile_options(${PROJECT_NAME} PRIVATE "-Wno-vla-cxx-extension")
# endif()
endif()
target_link_libraries(${PROJECT_NAME} UIBuilder Boost::describe Boost::thread asp)
# if (GLOBED_LINK_TO_ASAN)
# target_link_libraries(
# ${PROJECT_NAME}
# "${CMAKE_CURRENT_SOURCE_DIR}/libs/stl_asan.lib"
# "${CMAKE_CURRENT_SOURCE_DIR}/libs/clang_rt.asan_dynamic-x86_64.lib"
# "${CMAKE_CURRENT_SOURCE_DIR}/libs/clang_rt.asan_dynamic_runtime_thunk-x86_64.lib"
# )
# endif()
if (GLOBED_IS_DEBUG)
target_link_libraries(${PROJECT_NAME} Boost::stacktrace)
endif()
if (GLOBED_COMPILE_LIBS)
CPMAddPackage("gh:dankmeme01/libsodium-cmake#226abba")
CPMAddPackage("gh:xiph/opus#v1.5.2")
# disable some warnings
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
target_compile_options(sodium PRIVATE "-Wno-inaccessible-base" "-Wno-pointer-sign" "-Wno-user-defined-warnings")
endif()
target_link_libraries(${PROJECT_NAME} sodium opus)
else()
# download headers (binaries based off of 1.0.20 too)
CPMAddPackage(
NAME sodium
GIT_REPOSITORY "https://github.com/jedisct1/libsodium.git"
GIT_TAG "1.0.20-RELEASE"
)
CPMAddPackage(
NAME opus
GIT_REPOSITORY "https://github.com/xiph/opus.git"
GIT_TAG "v1.5.2"
DOWNLOAD_ONLY YES
)
add_library(sodium STATIC IMPORTED)
set_target_properties(sodium PROPERTIES IMPORTED_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/libs/sodium/libsodium.lib")
add_library(opus STATIC IMPORTED)
set_target_properties(opus PROPERTIES IMPORTED_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/libs/opus/opus.lib")
target_compile_definitions(${PROJECT_NAME} PRIVATE SODIUM_STATIC=1)
target_include_directories(${PROJECT_NAME} PRIVATE "${sodium_SOURCE_DIR}/src/libsodium/include")
target_include_directories(${PROJECT_NAME} PRIVATE "${opus_SOURCE_DIR}/include")
set(SODIUM_VERSION_IN "${CMAKE_CURRENT_SOURCE_DIR}/libs/sodium/version.h")
set(SODIUM_VERSION_OUT "${sodium_SOURCE_DIR}/src/libsodium/include/sodium/")
if (NOT EXISTS "${SODIUM_VERSION_OUT}/version.h")
message(STATUS "Copied version.h to ${SODIUM_VERSION_OUT}")
file(COPY "${SODIUM_VERSION_IN}" DESTINATION "${SODIUM_VERSION_OUT}")
else()
file(READ "${SODIUM_VERSION_IN}" CONTENT_IN)
file(READ "${SODIUM_VERSION_OUT}/version.h" CONTENT_OUT)
if (NOT "${CONTENT_IN}" STREQUAL "${CONTENT_OUT}")
message(STATUS "Copied version.h to ${SODIUM_VERSION_OUT}")
file(COPY "${SODIUM_VERSION_IN}" DESTINATION "${SODIUM_VERSION_OUT}")
endif()
endif()
target_link_libraries(${PROJECT_NAME} sodium opus)
endif()
# Windows - link to winsock and wmi
if (WIN32)
target_link_libraries(${PROJECT_NAME} ws2_32)
endif()
# Apple - link to iokit
if (APPLE)
find_library(IOKIT_LIBRARY IOKit)
target_link_libraries(${PROJECT_NAME} ${IOKIT_LIBRARY})
endif()
# link to libcurl
CPMAddPackage(
NAME curl
GIT_REPOSITORY "https://github.com/curl/curl.git"
GIT_TAG "curl-8_11_0"
DOWNLOAD_ONLY YES
)
add_library(curl STATIC IMPORTED)
if (ANDROID)
if (ANDROID_ABI STREQUAL "arm64-v8a")
set(LIB_PLATFORM "android64")
else()
set(LIB_PLATFORM "android32")
endif()
elseif (WIN32)
set(LIB_PLATFORM "win64")
else()
set(LIB_PLATFORM "macos")
endif()
target_compile_definitions(${PROJECT_NAME} PRIVATE CURL_STATICLIB=1)
# we are kinda leeching off of geode but we can always snatch those libraries in the future
if (WIN32)
set_target_properties(curl PROPERTIES IMPORTED_LOCATION "$ENV{GEODE_SDK}/loader/include/link/${LIB_PLATFORM}/libcurl.lib")
else()
set_target_properties(curl PROPERTIES IMPORTED_LOCATION "$ENV{GEODE_SDK}/loader/include/link/${LIB_PLATFORM}/libcurl.a")
endif()
target_include_directories(${PROJECT_NAME} PRIVATE "${curl_SOURCE_DIR}/include")
target_link_libraries(${PROJECT_NAME} curl)
# mac needs this for curl
if (APPLE)
target_link_libraries(${PROJECT_NAME} z)
elseif (WIN32)
# windows needs this ig?
target_link_libraries(${PROJECT_NAME} crypt32)
elseif (ANDROID)
target_link_libraries(${PROJECT_NAME} android)
endif()
# link to bb
if (GLOBED_OSS_BUILD)
message(STATUS "Building open-source version, not linking to bb")
target_compile_definitions(${PROJECT_NAME} PRIVATE GLOBED_OSS_BUILD=1)
else()
if (WIN32)
target_link_libraries(${PROJECT_NAME} "${CMAKE_CURRENT_SOURCE_DIR}/libs/bb/bb.lib")
target_link_libraries(${PROJECT_NAME} ntdll.lib userenv.lib runtimeobject.lib Iphlpapi.lib)
else ()
target_link_libraries(${PROJECT_NAME} "${CMAKE_CURRENT_SOURCE_DIR}/libs/bb/bb-${LIB_PLATFORM}.a")
endif()
endif()
setup_geode_mod(${PROJECT_NAME})