diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 60bf1c628..7a955fd4a 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -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 diff --git a/Brewfile b/Brewfile new file mode 100644 index 000000000..ca5830371 --- /dev/null +++ b/Brewfile @@ -0,0 +1,13 @@ +brew "cmake" +brew "ninja" +brew "pkgconf" +brew "glfw" +brew "glew" +brew "glm" +brew "libpng" +brew "libvorbis" +brew "luajit" +brew "openal-soft" +brew "freetype" +brew "openssl@3" +brew "googletest" diff --git a/CMakeLists.txt b/CMakeLists.txt index 4e44e8532..401d230eb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 $<$:winmm>) diff --git a/CMakePresets.json b/CMakePresets.json index 86a6fd075..2e47cbcec 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -72,8 +72,8 @@ "generator": "Ninja", "binaryDir": "${sourceDir}/build", "cacheVariables": { - "VOXELENGINE_BUILD_TESTS": "ON", - "VOXELENGINE_BUILD_APPDIR": "ON" + "CMAKE_BUILD_TYPE": "Release", + "VOXELENGINE_BUILD_TESTS": "ON" } } ], @@ -105,8 +105,7 @@ }, { "name": "default-ninja-clang-macos", - "configurePreset": "default-ninja-clang-macos", - "configuration": "Debug" + "configurePreset": "default-ninja-clang-macos" } ], "testPresets": [ diff --git a/README.md b/README.md index c2a1b0648..f9907144e 100644 --- a/README.md +++ b/README.md @@ -65,23 +65,31 @@ cmake --build . --parallel ### Install libraries ```sh -brew install glfw glew glm libpng libvorbis lua luajit libcurl openal-soft freetype +git clone --recursive https://github.com/MihailRis/VoxelCore.git +cd VoxelCore +brew bundle ``` -> [!TIP] -> If Homebrew fails to install `lua`, `luajit`, or `openal-soft`, download, compile, and install them manually. - ### Building engine with CMake ```sh -git clone --recursive https://github.com/MihailRis/VoxelCore.git -cd VoxelCore -mkdir build -cd build -cmake -DCMAKE_BUILD_TYPE=Release .. -cmake --build . --parallel +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 diff --git a/dev/cmake/BuildMacBundle.cmake b/dev/cmake/BuildMacBundle.cmake new file mode 100644 index 000000000..64bf95a1e --- /dev/null +++ b/dev/cmake/BuildMacBundle.cmake @@ -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 $ + 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) diff --git a/dev/macos/Info.plist.in b/dev/macos/Info.plist.in new file mode 100644 index 000000000..fb2914aa7 --- /dev/null +++ b/dev/macos/Info.plist.in @@ -0,0 +1,28 @@ + + + + + CFBundleName + VoxelCore + CFBundleDisplayName + VoxelCore + CFBundleIdentifier + io.github.mihailris.voxelcore + CFBundleExecutable + VoxelCore + CFBundleIconFile + VoxelCore + CFBundlePackageType + APPL + CFBundleShortVersionString + @VC_BUNDLE_VERSION@ + CFBundleVersion + @VC_BUNDLE_VERSION@ + LSApplicationCategoryType + public.app-category.games + NSHighResolutionCapable + + NSMicrophoneUsageDescription + VoxelCore uses the microphone for audio input when content requests it. + + diff --git a/dev/macos/VoxelCore.icns b/dev/macos/VoxelCore.icns new file mode 100644 index 000000000..192dcee97 Binary files /dev/null and b/dev/macos/VoxelCore.icns differ diff --git a/dev/macos/dmg-background.tiff b/dev/macos/dmg-background.tiff new file mode 100644 index 000000000..d433a0fa0 Binary files /dev/null and b/dev/macos/dmg-background.tiff differ diff --git a/dev/macos/dmg-setup.applescript b/dev/macos/dmg-setup.applescript new file mode 100644 index 000000000..35e6dbeb1 --- /dev/null +++ b/dev/macos/dmg-setup.applescript @@ -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 diff --git a/dev/macos/launcher.sh b/dev/macos/launcher.sh new file mode 100755 index 000000000..dc83808e9 --- /dev/null +++ b/dev/macos/launcher.sh @@ -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" "$@" diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 55480b05a..acfc68d23 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -13,6 +13,17 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Windows") # specific for vcpkg find_package(OpenAL CONFIG REQUIRED) else() + if(CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND NOT OPENAL_INCLUDE_DIR) + execute_process( + COMMAND brew --prefix openal-soft + OUTPUT_VARIABLE OPENAL_SOFT_DIR + OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET) + if(EXISTS "${OPENAL_SOFT_DIR}/include/AL/alext.h") + set(OPENAL_INCLUDE_DIR "${OPENAL_SOFT_DIR}/include" CACHE PATH "") + set(OPENAL_LIBRARY "${OPENAL_SOFT_DIR}/lib/libopenal.dylib" + CACHE FILEPATH "") + endif() + endif() find_package(OpenAL REQUIRED) if(NOT TARGET OpenAL::OpenAL) add_library(OpenAL::OpenAL UNKNOWN IMPORTED) @@ -25,6 +36,12 @@ endif() find_package(ZLIB REQUIRED) find_package(PNG REQUIRED) find_package(CURL REQUIRED) +if(CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND NOT OPENSSL_ROOT_DIR) + execute_process( + COMMAND brew --prefix openssl@3 + OUTPUT_VARIABLE OPENSSL_ROOT_DIR + OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET) +endif() find_package(OpenSSL 3.0 REQUIRED COMPONENTS Crypto) find_package(glfw3 REQUIRED) find_package(Freetype REQUIRED)