cmake fix
This commit is contained in:
@ -29,7 +29,7 @@ find_package(SDL3_image CONFIG REQUIRED)
|
|||||||
find_package(cpr CONFIG REQUIRED)
|
find_package(cpr CONFIG REQUIRED)
|
||||||
find_package(nlohmann_json CONFIG REQUIRED)
|
find_package(nlohmann_json CONFIG REQUIRED)
|
||||||
|
|
||||||
add_executable(tetris
|
set(TETRIS_SOURCES
|
||||||
src/main.cpp
|
src/main.cpp
|
||||||
src/gameplay/core/Game.cpp
|
src/gameplay/core/Game.cpp
|
||||||
src/core/GravityManager.cpp
|
src/core/GravityManager.cpp
|
||||||
@ -58,12 +58,24 @@ add_executable(tetris
|
|||||||
src/states/PlayingState.cpp
|
src/states/PlayingState.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if(APPLE)
|
||||||
|
add_executable(tetris MACOSX_BUNDLE ${TETRIS_SOURCES})
|
||||||
|
else()
|
||||||
|
add_executable(tetris ${TETRIS_SOURCES})
|
||||||
|
endif()
|
||||||
|
|
||||||
if (WIN32)
|
if (WIN32)
|
||||||
# Embed the application icon into the executable
|
# Embed the application icon into the executable
|
||||||
set_source_files_properties(src/app_icon.rc PROPERTIES LANGUAGE RC)
|
set_source_files_properties(src/app_icon.rc PROPERTIES LANGUAGE RC)
|
||||||
target_sources(tetris PRIVATE src/app_icon.rc)
|
target_sources(tetris PRIVATE src/app_icon.rc)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(APPLE)
|
||||||
|
set_target_properties(tetris PROPERTIES
|
||||||
|
MACOSX_BUNDLE_INFO_PLIST "${CMAKE_SOURCE_DIR}/cmake/MacBundleInfo.plist.in"
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
if (WIN32)
|
if (WIN32)
|
||||||
# Ensure favicon.ico is available in the build directory for the resource compiler
|
# Ensure favicon.ico is available in the build directory for the resource compiler
|
||||||
set(FAVICON_SRC "${CMAKE_SOURCE_DIR}/assets/favicon/favicon.ico")
|
set(FAVICON_SRC "${CMAKE_SOURCE_DIR}/assets/favicon/favicon.ico")
|
||||||
@ -88,6 +100,32 @@ if (WIN32)
|
|||||||
)
|
)
|
||||||
endif()
|
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)
|
target_link_libraries(tetris PRIVATE SDL3::SDL3 SDL3_ttf::SDL3_ttf SDL3_image::SDL3_image cpr::cpr nlohmann_json::nlohmann_json)
|
||||||
|
|
||||||
if (WIN32)
|
if (WIN32)
|
||||||
|
|||||||
@ -12,6 +12,7 @@ PACKAGE_DIR=""
|
|||||||
VERSION="$(date +"%Y.%m.%d")"
|
VERSION="$(date +"%Y.%m.%d")"
|
||||||
CLEAN=0
|
CLEAN=0
|
||||||
PACKAGE_ONLY=0
|
PACKAGE_ONLY=0
|
||||||
|
PACKAGE_RUNTIME_DIR=""
|
||||||
|
|
||||||
print_usage() {
|
print_usage() {
|
||||||
cat <<'USAGE'
|
cat <<'USAGE'
|
||||||
@ -127,17 +128,24 @@ copy_binary_or_bundle() {
|
|||||||
if [[ -n ${APP_BUNDLE_PATH:-} ]]; then
|
if [[ -n ${APP_BUNDLE_PATH:-} ]]; then
|
||||||
log INFO "Copying app bundle..."
|
log INFO "Copying app bundle..."
|
||||||
rsync -a "$APP_BUNDLE_PATH" "$PACKAGE_DIR/"
|
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
|
else
|
||||||
log INFO "Copying executable..."
|
log INFO "Copying executable..."
|
||||||
cp "$EXECUTABLE_PATH" "$PACKAGE_DIR/${PROJECT_NAME}"
|
cp "$EXECUTABLE_PATH" "$PACKAGE_DIR/${PROJECT_NAME}"
|
||||||
chmod +x "$PACKAGE_DIR/${PROJECT_NAME}"
|
chmod +x "$PACKAGE_DIR/${PROJECT_NAME}"
|
||||||
PACKAGE_BINARY="${PROJECT_NAME}"
|
PACKAGE_BINARY="${PROJECT_NAME}"
|
||||||
|
PACKAGE_RUNTIME_DIR="$PACKAGE_DIR"
|
||||||
fi
|
fi
|
||||||
log OK "Binary ready (${PACKAGE_BINARY})"
|
log OK "Binary ready (${PACKAGE_BINARY})"
|
||||||
}
|
}
|
||||||
|
|
||||||
copy_assets() {
|
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..."
|
log INFO "Copying assets..."
|
||||||
local folders=("assets" "fonts")
|
local folders=("assets" "fonts")
|
||||||
for folder in "${folders[@]}"; do
|
for folder in "${folders[@]}"; do
|
||||||
@ -173,7 +181,7 @@ copy_dependencies() {
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
if (( !seen )); then
|
if (( !seen )); then
|
||||||
cp "$dylib" "$PACKAGE_DIR/"
|
cp "$dylib" "$PACKAGE_RUNTIME_DIR/"
|
||||||
copied_names+=("$name")
|
copied_names+=("$name")
|
||||||
log OK "Copied $name"
|
log OK "Copied $name"
|
||||||
fi
|
fi
|
||||||
@ -242,7 +250,11 @@ EOF
|
|||||||
validate_package() {
|
validate_package() {
|
||||||
log INFO "Validating package contents..."
|
log INFO "Validating package contents..."
|
||||||
local missing=()
|
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
|
if [[ ! -e "$PACKAGE_DIR/$required" ]]; then
|
||||||
missing+=("$required")
|
missing+=("$required")
|
||||||
fi
|
fi
|
||||||
|
|||||||
26
cmake/MacBundleInfo.plist.in
Normal file
26
cmake/MacBundleInfo.plist.in
Normal 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>
|
||||||
Reference in New Issue
Block a user