add macOS .app bundle and dmg packaging

This commit is contained in:
Sergey Asadov 2026-11-13 14:55:00 +03:00
parent 698fd32071
commit f241e4c355
9 changed files with 180 additions and 16 deletions

View file

@ -34,17 +34,11 @@ jobs:
run: |
cmake -DOPENAL_INCLUDE_DIR=$(brew --prefix openal-soft)/include \
-DOPENAL_LIBRARY=$(brew --prefix openal-soft)/lib/libopenal.dylib \
-S . -B build -DCMAKE_BUILD_TYPE=RelWithDebInfo -DVOXELENGINE_BUILD_TESTS=ON -DVOXELENGINE_BUILD_APPDIR=1 -DVC_BUILD_NAME="${{ inputs.build_name }}" -DVC_VERSION_PATCH="${{ inputs.version_patch }}"
-S . -B build -DCMAKE_BUILD_TYPE=RelWithDebInfo -DVOXELENGINE_BUILD_TESTS=ON -DVOXELENGINE_BUILD_MACOS_BUNDLE=ON -DVC_BUILD_NAME="${{ inputs.build_name }}" -DVC_VERSION_PATCH="${{ inputs.version_patch }}"
- name: Build
run: |
cmake --build build -t install
- name: Make fix_dylibs.sh executable
run: chmod +x dev/fix_dylibs.sh
- name: Fix dylibs
run: ./dev/fix_dylibs.sh VoxelCore Release build
cmake --build build
- name: Run tests
run: ctest --output-on-failure --test-dir build
@ -52,16 +46,25 @@ jobs:
- name: Run engine tests
timeout-minutes: 5
run: |
chmod +x build/VoxelCore
chmod +x AppDir/usr/bin/vctest
AppDir/usr/bin/vctest -e build/VoxelCore -d dev/tests -u build --output-always --debugger "lldb -batch -o 'run' -o 'thread backtrace all' -o 'quit' -- "
build/vctest/vctest -e build/VoxelCore -d dev/tests -u build --output-always --debugger "lldb -batch -o 'run' -o 'thread backtrace all' -o 'quit' -- "
- name: Create DMG
run: |
mkdir VoxelCoreDmgContent
cp -r build/res VoxelCoreDmgContent/
cp -r build/VoxelCore VoxelCoreDmgContent/
cp -r build/libs VoxelCoreDmgContent/libs
hdiutil create VoxelCoreMacApp.dmg -volname "VoxelCore" -srcfolder VoxelCoreDmgContent -ov -format UDZO
cd build
cpack
mv VoxelCore.dmg ../VoxelCoreMacApp.dmg
- name: Check bundle
run: |
app=build/_CPack_Packages/Darwin/DragNDrop/VoxelCore/VoxelCore.app
test -x "$app/Contents/MacOS/VoxelCore"
test -d "$app/Contents/Resources/res"
if find "$app/Contents" -type f -perm +111 -exec otool -L {} \; 2>/dev/null \
| grep -E '^[[:space:]]+(/opt/homebrew|/usr/local)/'; then
echo "bundle depends on libraries outside of it"
exit 1
fi
codesign --verify --deep --strict "$app"
- name: Upload artifacts
uses: actions/upload-artifact@v4

View file

@ -9,6 +9,7 @@ execute_process(COMMAND ${CMAKE_COMMAND} --version)
option(VOXELENGINE_BUILD_APPDIR "Pack linux build" OFF)
option(VOXELENGINE_BUILD_TESTS "Build tests" OFF)
option(VOXELENGINE_BUILD_MACOS_BUNDLE "Pack macOS .app bundle" OFF)
add_compile_definitions(VC_BUILD_NAME="${VC_BUILD_NAME}")
@ -41,6 +42,10 @@ if(VOXELENGINE_BUILD_APPDIR)
include(${CMAKE_CURRENT_SOURCE_DIR}/dev/cmake/BuildAppdir.cmake)
endif()
if(VOXELENGINE_BUILD_MACOS_BUNDLE)
include(${CMAKE_CURRENT_SOURCE_DIR}/dev/cmake/BuildMacBundle.cmake)
endif()
target_link_libraries(VoxelCore PRIVATE VoxelCoreSrc
$<$<PLATFORM_ID:Windows>:winmm>)

View file

@ -77,6 +77,19 @@ cmake --preset default-ninja-clang-macos
cmake --build --preset default-ninja-clang-macos
```
### Building `.app` and `.dmg`
> [!NOTE]
> User files are stored in `~/Library/Application Support/VoxelCore`.
```sh
cmake --preset default-ninja-clang-macos -DVOXELENGINE_BUILD_MACOS_BUNDLE=ON
cmake --build --preset default-ninja-clang-macos
cd build
cpack
```
This creates `build/VoxelCore.dmg` with a self-contained `VoxelCore.app`
(Homebrew libraries are copied into the bundle).
---
## Building in Windows

View file

@ -0,0 +1,72 @@
# VoxelCore.app packed to VoxelCore.dmg with cpack
set(VC_BUNDLE_CONTENTS VoxelCore.app/Contents)
file(READ ${CMAKE_CURRENT_SOURCE_DIR}/src/constants.hpp VC_CONSTANTS)
string(REGEX MATCH "ENGINE_VERSION_MAJOR = ([0-9]+)" _ "${VC_CONSTANTS}")
set(VC_VERSION_MAJOR ${CMAKE_MATCH_1})
string(REGEX MATCH "ENGINE_VERSION_MINOR = ([0-9]+)" _ "${VC_CONSTANTS}")
set(VC_VERSION_MINOR ${CMAKE_MATCH_1})
if(VC_VERSION_PATCH STREQUAL "")
set(VC_BUNDLE_VERSION ${VC_VERSION_MAJOR}.${VC_VERSION_MINOR}.0)
else()
set(VC_BUNDLE_VERSION
${VC_VERSION_MAJOR}.${VC_VERSION_MINOR}.${VC_VERSION_PATCH})
endif()
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/dev/macos/Info.plist.in
${CMAKE_CURRENT_BINARY_DIR}/Info.plist @ONLY
)
install(
PROGRAMS $<TARGET_FILE:VoxelCore>
DESTINATION ${VC_BUNDLE_CONTENTS}/MacOS
RENAME VoxelCore-bin
)
install(
PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/dev/macos/launcher.sh
DESTINATION ${VC_BUNDLE_CONTENTS}/MacOS
RENAME VoxelCore
)
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/Info.plist
DESTINATION ${VC_BUNDLE_CONTENTS}
)
install(
FILES ${CMAKE_CURRENT_SOURCE_DIR}/dev/macos/VoxelCore.icns
DESTINATION ${VC_BUNDLE_CONTENTS}/Resources
)
install(
DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/res
DESTINATION ${VC_BUNDLE_CONTENTS}/Resources
)
execute_process(
COMMAND brew --prefix
OUTPUT_VARIABLE VC_BREW_PREFIX
OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET
)
install(
CODE "set(VC_LIB_DIRS \"${VC_BREW_PREFIX}/lib\")"
)
install(
CODE [[
include(BundleUtilities)
set(app "$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/VoxelCore.app")
fixup_bundle("${app}" "${app}/Contents/MacOS/VoxelCore-bin"
"${VC_LIB_DIRS}")
execute_process(COMMAND codesign --force --deep --sign - "${app}"
COMMAND_ERROR_IS_FATAL ANY)
]])
set(CPACK_GENERATOR DragNDrop)
set(CPACK_PACKAGE_NAME VoxelCore)
set(CPACK_PACKAGE_VERSION ${VC_BUNDLE_VERSION})
set(CPACK_PACKAGE_FILE_NAME VoxelCore)
set(CPACK_DMG_VOLUME_NAME VoxelCore)
set(CPACK_DMG_BACKGROUND_IMAGE ${CMAKE_CURRENT_SOURCE_DIR}/dev/macos/dmg-background.tiff)
set(CPACK_DMG_DS_STORE_SETUP_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/dev/macos/dmg-setup.applescript)
include(CPack)

28
dev/macos/Info.plist.in Normal file
View file

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleName</key>
<string>VoxelCore</string>
<key>CFBundleDisplayName</key>
<string>VoxelCore</string>
<key>CFBundleIdentifier</key>
<string>io.github.mihailris.voxelcore</string>
<key>CFBundleExecutable</key>
<string>VoxelCore</string>
<key>CFBundleIconFile</key>
<string>VoxelCore</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>@VC_BUNDLE_VERSION@</string>
<key>CFBundleVersion</key>
<string>@VC_BUNDLE_VERSION@</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.games</string>
<key>NSHighResolutionCapable</key>
<true/>
<key>NSMicrophoneUsageDescription</key>
<string>VoxelCore uses the microphone for audio input when content requests it.</string>
</dict>
</plist>

BIN
dev/macos/VoxelCore.icns Normal file

Binary file not shown.

Binary file not shown.

View file

@ -0,0 +1,36 @@
on run argv
set volumeName to item 1 of argv
tell application "Finder"
set targetDisk to missing value
set candidates to every disk whose name is volumeName
repeat with i from 1 to count of candidates
set d to item i of candidates
set diskPath to POSIX path of (d as alias)
try
do shell script "test -w " & quoted form of diskPath
set targetDisk to d
exit repeat
end try
end repeat
if targetDisk is missing value then error "writable disk not found: " & volumeName
tell targetDisk
open
set win to container window
set current view of win to icon view
set toolbar visible of win to false
set statusbar visible of win to false
set the bounds of win to {200, 120, 800, 548}
set opts to the icon view options of win
set arrangement of opts to not arranged
set icon size of opts to 128
set text size of opts to 13
set background picture of opts to file ".background:background.tiff"
set position of item "VoxelCore.app" of win to {180, 200}
set position of item "Applications" of win to {420, 200}
update without registering applications
delay 2
close
end tell
end tell
end run

7
dev/macos/launcher.sh Executable file
View file

@ -0,0 +1,7 @@
#!/bin/sh
DIR="$(cd "$(dirname "$0")" && pwd)"
USER_DIR="$HOME/Library/Application Support/VoxelCore"
mkdir -p "$USER_DIR"
exec "$DIR/VoxelCore-bin" --res "$DIR/../Resources/res" --dir "$USER_DIR" "$@"