cmake fix

This commit is contained in:
2025-11-30 14:32:52 +01:00
parent 33994ec9db
commit dd0ac54ee5
3 changed files with 80 additions and 4 deletions

View File

@ -29,7 +29,7 @@ find_package(SDL3_image CONFIG REQUIRED)
find_package(cpr CONFIG REQUIRED)
find_package(nlohmann_json CONFIG REQUIRED)
add_executable(tetris
set(TETRIS_SOURCES
src/main.cpp
src/gameplay/core/Game.cpp
src/core/GravityManager.cpp
@ -58,12 +58,24 @@ add_executable(tetris
src/states/PlayingState.cpp
)
if(APPLE)
add_executable(tetris MACOSX_BUNDLE ${TETRIS_SOURCES})
else()
add_executable(tetris ${TETRIS_SOURCES})
endif()
if (WIN32)
# Embed the application icon into the executable
set_source_files_properties(src/app_icon.rc PROPERTIES LANGUAGE RC)
target_sources(tetris PRIVATE src/app_icon.rc)
endif()
if(APPLE)
set_target_properties(tetris PROPERTIES
MACOSX_BUNDLE_INFO_PLIST "${CMAKE_SOURCE_DIR}/cmake/MacBundleInfo.plist.in"
)
endif()
if (WIN32)
# Ensure favicon.ico is available in the build directory for the resource compiler
set(FAVICON_SRC "${CMAKE_SOURCE_DIR}/assets/favicon/favicon.ico")
@ -88,6 +100,32 @@ if (WIN32)
)
endif()
if(APPLE)
set(_mac_copy_commands)
if(EXISTS "${CMAKE_SOURCE_DIR}/assets")
list(APPEND _mac_copy_commands
COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_SOURCE_DIR}/assets" "$<TARGET_FILE_DIR:tetris>/assets"
)
endif()
if(EXISTS "${CMAKE_SOURCE_DIR}/fonts")
list(APPEND _mac_copy_commands
COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_SOURCE_DIR}/fonts" "$<TARGET_FILE_DIR:tetris>/fonts"
)
endif()
if(EXISTS "${CMAKE_SOURCE_DIR}/FreeSans.ttf")
list(APPEND _mac_copy_commands
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_SOURCE_DIR}/FreeSans.ttf" "$<TARGET_FILE_DIR:tetris>/FreeSans.ttf"
)
endif()
if(_mac_copy_commands)
add_custom_command(TARGET tetris POST_BUILD
${_mac_copy_commands}
COMMENT "Copying game assets into macOS bundle"
)
endif()
endif()
endif()
target_link_libraries(tetris PRIVATE SDL3::SDL3 SDL3_ttf::SDL3_ttf SDL3_image::SDL3_image cpr::cpr nlohmann_json::nlohmann_json)
if (WIN32)

View File

@ -12,6 +12,7 @@ PACKAGE_DIR=""
VERSION="$(date +"%Y.%m.%d")"
CLEAN=0
PACKAGE_ONLY=0
PACKAGE_RUNTIME_DIR=""
print_usage() {
cat <<'USAGE'
@ -127,17 +128,24 @@ copy_binary_or_bundle() {
if [[ -n ${APP_BUNDLE_PATH:-} ]]; then
log INFO "Copying app bundle..."
rsync -a "$APP_BUNDLE_PATH" "$PACKAGE_DIR/"
PACKAGE_BINARY="${APP_BUNDLE_PATH##*/}/Contents/MacOS/${PROJECT_NAME}"
local app_name="${APP_BUNDLE_PATH##*/}"
PACKAGE_BINARY="${app_name}/Contents/MacOS/${PROJECT_NAME}"
PACKAGE_RUNTIME_DIR="$PACKAGE_DIR/${app_name}/Contents/MacOS"
else
log INFO "Copying executable..."
cp "$EXECUTABLE_PATH" "$PACKAGE_DIR/${PROJECT_NAME}"
chmod +x "$PACKAGE_DIR/${PROJECT_NAME}"
PACKAGE_BINARY="${PROJECT_NAME}"
PACKAGE_RUNTIME_DIR="$PACKAGE_DIR"
fi
log OK "Binary ready (${PACKAGE_BINARY})"
}
copy_assets() {
if [[ -n ${APP_BUNDLE_PATH:-} ]]; then
log INFO "Assets already bundled inside the .app; skipping external copy."
return
fi
log INFO "Copying assets..."
local folders=("assets" "fonts")
for folder in "${folders[@]}"; do
@ -173,7 +181,7 @@ copy_dependencies() {
fi
done
if (( !seen )); then
cp "$dylib" "$PACKAGE_DIR/"
cp "$dylib" "$PACKAGE_RUNTIME_DIR/"
copied_names+=("$name")
log OK "Copied $name"
fi
@ -242,7 +250,11 @@ EOF
validate_package() {
log INFO "Validating package contents..."
local missing=()
for required in "$PACKAGE_BINARY" assets FreeSans.ttf; do
local required=("$PACKAGE_BINARY")
if [[ -z ${APP_BUNDLE_PATH:-} ]]; then
required+=(assets FreeSans.ttf)
fi
for required in "${required[@]}"; do
if [[ ! -e "$PACKAGE_DIR/$required" ]]; then
missing+=("$required")
fi

View File

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>${MACOSX_BUNDLE_EXECUTABLE_NAME}</string>
<key>CFBundleIdentifier</key>
<string>com.example.tetris</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>Tetris</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>LSMinimumSystemVersion</key>
<string>12.0</string>
<key>NSHighResolutionCapable</key>
<true/>
</dict>
</plist>