forked from LNXSeus/Advancely
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
391 lines (330 loc) · 15.6 KB
/
CMakeLists.txt
File metadata and controls
391 lines (330 loc) · 15.6 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
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
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
# Copyright (c) 2026 LNXSeus. All Rights Reserved.
#
# This project is proprietary software. You are granted a license to use the software as-is.
# You may not copy, distribute, modify, reverse-engineer, or use this software
# or its source code in any way without the express written permission of the copyright holder.
# Minimum CMake version required
cmake_minimum_required(VERSION 3.20)
# Project name and language
project(Advancely C CXX) # c for cJSON, C++ for the rest
# Read the content of main.h into a variable for version
file(READ "${CMAKE_SOURCE_DIR}/source/main.h" MAIN_H_CONTENTS)
# Use a regular expression to find the line with the version and capture the number
# This specifically looks for the pattern #define ADVANCELY_VERSION "vX.Y.Z"
# and captures only the "X.Y.Z" part.
string(REGEX MATCH "#define ADVANCELY_VERSION \"v([0-9]+\\.[0-9]+\\.[0-9]+)\"" _ ${MAIN_H_CONTENTS})
# The captured version number is now in the variable CMAKE_MATCH_1
if (CMAKE_MATCH_1)
set(PROJECT_VERSION ${CMAKE_MATCH_1})
message(STATUS "Project version set from main.h: ${PROJECT_VERSION}")
else ()
message(FATAL_ERROR "Could not parse ADVANCELY_VERSION from source/main.h!")
endif ()
# If running in GitHub Actions, export the version to the environment
if (DEFINED ENV{GITHUB_ENV})
file(APPEND "$ENV{GITHUB_ENV}" "PROJECT_VERSION=${PROJECT_VERSION}\n")
message(STATUS "Exporting PROJECT_VERSION=${PROJECT_VERSION} to GITHUB_ENV")
endif ()
# Enable the RC (Resource Compiler) language for Windows executables
if (WIN32)
enable_language(RC)
endif ()
# Set C standard
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED True)
set(CMAKE_CXX_STANDARD 17) # Use widely supported C++ 17
set(CMAKE_CXX_STANDARD_REQUIRED True)
# --- 1. DEFINE PATHS & SOURCE FILES ---
set(EXECUTABLE_NAME "Advancely")
set(SOURCE_FILES
"source/main.cpp"
"source/init_sdl.cpp"
"source/tracker.cpp"
"source/overlay.cpp"
"source/global_event_handler.cpp"
"source/settings.cpp"
"source/path_utils.cpp"
"source/settings_utils.cpp"
"source/file_utils.cpp"
"source/format_utils.cpp" # for formatting strings
"source/temp_creator.cpp"
"source/temp_creator_utils.cpp"
"source/template_scanner.cpp"
"source/update_checker.cpp"
"source/logger.cpp"
"source/dialog_utils.cpp"
# External libraries included as source and stay in C
"source/external/cJSON.c"
"source/external/miniz.c"
"source/external/tinyfiledialogs.c"
# dmon.h is header-only and included in main.cpp, so it doesn't need to be listed here.
# --- Add all the ImGui source files ---
"source/imgui/imgui.cpp"
"source/imgui/imgui_draw.cpp"
"source/imgui/imgui_tables.cpp"
"source/imgui/imgui_widgets.cpp"
"source/imgui/imgui_demo.cpp" # Recommended for development
"source/imgui/imgui_impl_sdl3.cpp"
"source/imgui/imgui_impl_sdlrenderer3.cpp"
)
# append windows specific source files
if (WIN32)
list(APPEND SOURCE_FILES
# Windows-specific resource file
"icon.rc"
)
endif ()
# --- RPATH CONFIGURATION ---
if (UNIX AND NOT APPLE)
# Making sure it can find the libraries after running .deb or .rpm
# 1. Set RPATH to look in the ./lib folder relative to the executable
set(CMAKE_INSTALL_RPATH "$ORIGIN/lib")
# 2. Don't skip RPATH during the build phase
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
endif()
# --- 2. CREATE THE EXECUTABLE ---
# Use the WIN32 keyword for graphical apps on Windows to hide the console.
if (WIN32)
add_executable(${EXECUTABLE_NAME} WIN32 ${SOURCE_FILES})
else ()
add_executable(${EXECUTABLE_NAME} ${SOURCE_FILES})
endif ()
# This command targets a specific source file and sets its properties ONLY FOR GCC
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set_source_files_properties(
source/external/miniz.c
PROPERTIES
# This adds a compiler flag ONLY when compiling this specific file.
# -Wno-type-limits will disable the "comparison is always false" warning.
COMPILE_FLAGS "-Wno-type-limits"
)
endif ()
# Add a specific rule for tinyfiledialogs.c to ignore the function cast warning.
set_source_files_properties(
source/external/tinyfiledialogs.c
PROPERTIES
# This generator expression applies the flag ONLY when the compiler is NOT MSVC.
COMPILE_FLAGS "$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wno-cast-function-type>"
)
# This command targets a specific source file and sets its properties.
set_source_files_properties(
source/external/miniz.c
PROPERTIES
# This uses a generator expression to apply the correct flags for each compiler.
# For MSVC, it disables warnings 4132 and 4127.
# For other compilers (like GCC/Clang), it applies -Wno-type-limits.
COMPILE_FLAGS "$<$<CXX_COMPILER_ID:MSVC>:/wd4132 /wd4127> $<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wno-type-limits>"
)
# Tell the compiler where to find your project's header files.
target_include_directories(Advancely PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/source"
# Add the path to your vendored libraries like cJSON and dmon
"${CMAKE_CURRENT_SOURCE_DIR}/source/external"
"${CMAKE_CURRENT_SOURCE_DIR}/source/imgui"
)
# --- 3. FIND DEPENDENCIES (Cross-Platform) ---
# Use the modern find_package command. This will find system-installed libraries.
# You will need to install these dependencies on your system (see notes below).
find_package(SDL3 REQUIRED)
find_package(SDL3_image REQUIRED)
find_package(SDL3_ttf REQUIRED)
find_package(CURL REQUIRED)
# The official SDL3_mixer is not yet released. If you are using an unofficial build
# or the older SDL2_mixer, you would find it here. For now, it's commented out.
# find_package(SDL2_mixer REQUIRED)
# --- 4. LINK LIBRARIES (Cross-Platform) ---
target_link_libraries(${EXECUTABLE_NAME} PRIVATE
# Link against the imported targets from find_package
SDL3::SDL3
SDL3_image::SDL3_image
SDL3_ttf::SDL3_ttf
CURL::libcurl
)
# Add platform-specific system libraries
if (WIN32)
# Link against common Windows libraries needed by SDL and advancely
target_link_libraries(${EXECUTABLE_NAME} PRIVATE gdi32 user32 winmm shell32 version ntdll urlmon)
elseif (APPLE)
# On macOS, link against required system frameworks
target_link_libraries(${EXECUTABLE_NAME} PRIVATE "-framework Cocoa" "-framework Metal" "-framework IOKit")
# This block now creates the .app bundle using your custom Info.plist
set_target_properties(${EXECUTABLE_NAME} PROPERTIES
MACOSX_BUNDLE TRUE
# Copy the icon file into the bundle's Resources directory
MACOSX_BUNDLE_ICON_FILE "${CMAKE_SOURCE_DIR}/resources/gui/Advancely_Logo_NoText.icns"
# Use your custom Info.plist as a template
MACOSX_BUNDLE_INFO_PLIST "${CMAKE_SOURCE_DIR}/Info.plist"
)
# Manually ensure the icon is copied to the bundle's Resources directory as a safeguard.
add_custom_command(TARGET ${EXECUTABLE_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${CMAKE_SOURCE_DIR}/resources/gui/Advancely_Logo_NoText.icns"
"$<TARGET_FILE_DIR:${EXECUTABLE_NAME}>/../Resources/Advancely_Logo_NoText.icns"
COMMENT "[CMAKE] Manually copying icon to macOS app bundle."
)
endif ()
# On Linux, find_package usually handles all necessary system library dependencies.
# --- 5. POST-BUILD COMMANDS ---
# This block will ONLY run for MinGW/GCC compilers (your local setup)
# and will copy your exact list of required DLLs.
if (WIN32 AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
get_filename_component(MINGW_BIN_DIR ${CMAKE_C_COMPILER} DIRECTORY)
set(MINGW_DLLS
"SDL3.dll" "SDL3_image.dll" "SDL3_ttf.dll"
"libbrotlicommon.dll" "libbrotlidec.dll" "libbz2-1.dll" "libcrypto-3-x64.dll"
"libcurl-4.dll" "libfreetype-6.dll" "libgcc_s_seh-1.dll" "libglib-2.0-0.dll"
"libgraphite2.dll" "libharfbuzz-0.dll" "libiconv-2.dll" "libidn2-0.dll"
"libintl-8.dll" "libnghttp2-14.dll" "libnghttp3-9.dll" "libngtcp2_crypto_ossl.dll"
"libngtcp2-16.dll" "libpcre2-8-0.dll" "libpng16-16.dll" "libpsl-5.dll"
"libsharpyuv-0.dll" "libssh2-1.dll" "libssl-3-x64.dll" "libstdc++-6.dll"
"libunistring-5.dll" "libwebp-7.dll" "libwebpdemux-2.dll" "libwinpthread-1.dll"
"libzstd.dll" "zlib1.dll"
)
foreach (DLL_NAME ${MINGW_DLLS})
add_custom_command(TARGET ${EXECUTABLE_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${MINGW_BIN_DIR}/${DLL_NAME}"
"$<TARGET_FILE_DIR:${EXECUTABLE_NAME}>"
)
endforeach ()
endif ()
# This command is needed on Windows/Linux platforms to copy the resources to where executable is
# macOS .app bundle is handled further above
if (NOT APPLE)
add_custom_command(TARGET ${EXECUTABLE_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
"${CMAKE_SOURCE_DIR}/resources"
"${CMAKE_BINARY_DIR}/resources"
COMMENT "[CMAKE] Copying resources to build directory"
)
endif ()
if (NOT APPLE)
# Move the _PLEASE_READ_ME.txt file to the output directory
add_custom_command(TARGET Advancely POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
"${CMAKE_SOURCE_DIR}/_PLEASE_READ_ME.txt"
"$<TARGET_FILE_DIR:Advancely>"
COMMENT "[CMAKE] Copying _PLEASE_READ_ME.txt to output directory..."
)
add_custom_command(TARGET Advancely POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
"${CMAKE_SOURCE_DIR}/LICENSES.txt"
"$<TARGET_FILE_DIR:Advancely>"
COMMENT "[CMAKE] Copying LICENSES.txt to output directory..."
)
add_custom_command(TARGET Advancely POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
"${CMAKE_SOURCE_DIR}/README.md"
"$<TARGET_FILE_DIR:Advancely>"
COMMENT "[CMAKE] Copying README.md to output directory..."
)
endif ()
# --- 6. COMPILER FLAGS & SANITIZERS ---
if (MSVC)
# Apply MSVC-specific warning flags
target_compile_options(${EXECUTABLE_NAME} PRIVATE
/W4 # Equivalent to -Wall / -Wextra, sets a high warning level
/WX # Equivalent to -Werror, treats warnings as errors
# Acceptable warnings
/wd4244 # Disable "possible loss of data" conversion warning
/wd4996 # Disable "unsafe function" warnings (for fopen, strncpy, etc.)
/wd4267 # Disable "size_t to int" conversion warning
/wd4456 # Disable "hides previous local declaration" warning
/wd4458 # Disable "hides class member" warning
/wd4101 # Disable "unreferenced local variable" warning
/wd4505 # Disable "unreferenced function" warning
/wd4132 # Disable "'object': const object should be initialized" warning
/wd4127 # Disable "conditional expression is constant" warning
)
else ()
# Apply GCC/Clang-specific warning flags
target_compile_options(${EXECUTABLE_NAME} PRIVATE
-Wall # Enable all standard warnings
-Wextra # Enable even more warnings
-Wpedantic # Warn on non-standard language extensions
-Wno-deprecated-declarations # Ignore sprintf deprecation error from MacOS
# -Werror # Treat all warnings as errors, forcing you to fix them, commented out for MacOS sprintf error
-Wno-unused-result # Ignore unused result warnings
# Disable specific GNU extension warning for Clang
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>>:-Wno-gnu-zero-variadic-macro-arguments>
)
# Add GCC-specific warning suppressions only when using the GCC compiler
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_compile_options(${EXECUTABLE_NAME} PRIVATE
-Wno-stringop-truncation
-Wno-format-truncation # Ignore truncation warnings
)
endif ()
endif ()
# Add sanitizers for Debug builds on non-Windows platforms (Linux, macOS)
if (NOT WIN32)
# This injects code to detect memory errors (like leaks, buffer overflows) at runtime.
target_compile_options(${EXECUTABLE_NAME} PRIVATE $<$<CONFIG:Debug>:-fsanitize=address>)
# Link the AddressSanitizer library for Debug builds.
target_link_options(${EXECUTABLE_NAME} PRIVATE $<$<CONFIG:Debug>:-fsanitize=address>)
endif ()
# --- 7. INSTALLATION AND PACKAGING ---
# This command ensures that CMake's install features are available.
include(InstallRequiredSystemLibraries)
# Define where to install the files
if (WIN32)
# Rule to install the main executable and its runtime dlls
install(TARGETS ${EXECUTABLE_NAME}
DESTINATION bin
BUNDLE DESTINATION .
)
# Rule to install the entire resources directory
install(DIRECTORY resources/ DESTINATION share/advancely/resources)
# Rule to install the text files alongside the executable
install(FILES
"${CMAKE_SOURCE_DIR}/_PLEASE_READ_ME.txt"
"${CMAKE_SOURCE_DIR}/LICENSES.txt"
"${CMAKE_SOURCE_DIR}/README.md"
DESTINATION bin
)
endif ()
# --- LINUX INSTALLATION ---
if (UNIX AND NOT APPLE)
# 1. Generate the 'version' file automatically
file(WRITE "${CMAKE_BINARY_DIR}/version" "${PROJECT_VERSION}")
# 2. Install the ACTUAL binary
install(TARGETS ${EXECUTABLE_NAME} DESTINATION share/advancely)
# 3. Install the LAUNCHER script
install(PROGRAMS packaging/linux/launcher DESTINATION bin RENAME advancely)
# 4. Install Resources and Version
install(DIRECTORY resources/ DESTINATION share/advancely/resources)
install(FILES "${CMAKE_BINARY_DIR}/version" DESTINATION share/advancely)
# Desktop Integration
install(FILES "packaging/linux/advancely.desktop" DESTINATION share/applications)
install(FILES "packaging/linux/advancely.png"
DESTINATION share/pixmaps
RENAME advancely.png
)
# Install the auto-generated file from the build directory
install(FILES "packaging/linux/dev.LNXSeus.Advancely.metainfo.xml" DESTINATION share/metainfo)
endif ()
# --- 8. CPACK PACKAGING (Generates .deb and .rpm) ---
if (UNIX AND NOT APPLE)
set(CPACK_PACKAGE_NAME "advancely")
set(CPACK_PACKAGE_VENDOR "LNXSeus")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "A highly customizable Minecraft progress tracker.")
set(CPACK_PACKAGE_VERSION "${PROJECT_VERSION}")
set(CPACK_PACKAGE_CONTACT "rodney@dfagaming.nl")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/LICENSES.txt")
# Set the package types we want to generate
set(CPACK_GENERATOR "DEB;RPM")
# --- DEBIAN (.deb) CONFIG ---
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Rodney van den Velden")
set(CPACK_DEBIAN_PACKAGE_SECTION "games")
set(CPACK_DEBIAN_PACKAGE_PRIORITY "optional")
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS OFF) # Automatically find dependencies
# Explicit dependencies if auto-detection fails (adjust names for Debian/Ubuntu)
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6, libcurl4, libfreetype6" "libsdl3-0" "libsdl3-image0" "libsdl3-ttf0")
# --- RPM (.rpm) CONFIG ---
set(CPACK_RPM_PACKAGE_LICENSE "Proprietary")
set(CPACK_RPM_PACKAGE_GROUP "Amusements/Games")
set(CPACK_RPM_PACKAGE_REQUIRES "curl, SDL3, SDL3_image, SDL3_ttf")
set(CPACK_RPM_PACKAGE_AUTOREQPROV OFF) # Turn OFF auto-detection
set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-v${PROJECT_VERSION}-Linux") # include the "v" in the version
include(CPack)
endif()