Add macOS support (#63)

This commit is contained in:
Alexander Batalov 2022-07-05 15:45:36 +03:00 committed by GitHub
parent 8e1291b1d1
commit 80e27a8c98
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 180 additions and 88 deletions

1
.gitattributes vendored
View File

@ -5,6 +5,7 @@
*.h text eol=lf
*.md text eol=lf
*.json text eol=lf
*.plist text eol=lf
*.yml text eol=lf
.clang-format text eol=lf
.editorconfig text eol=lf

View File

@ -214,3 +214,29 @@ jobs:
name: fallout2-ce-${{ matrix.cfg.artifact-os }}
path: "${{ matrix.cfg.artifact-os }}/x${{ matrix.cfg.arch }}"
retention-days: 7
macos:
runs-on: macos-latest
steps:
- name: Clone
uses: actions/checkout@v3
- name: Dependencies
run: |
brew install sdl2
- name: Configure
run: |
cmake -B build/macos -DCMAKE_BUILD_TYPE=RelWithDebInfo
- name: Build
run: |
cmake --build build/macos -j $(sysctl -n hw.physicalcpu) --target package
- name: Upload
uses: actions/upload-artifact@v3
with:
name: fallout2-ce-macos
path: build/macos/_CPack_Packages/Darwin/DragNDrop/fallout2-ce/fallout2-ce.dmg
retention-days: 7

View File

@ -10,7 +10,7 @@ set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED YES)
set(CMAKE_CXX_EXTENSIONS NO)
add_executable(${EXECUTABLE_NAME} WIN32
add_executable(${EXECUTABLE_NAME} WIN32 MACOSX_BUNDLE
"src/actions.cc"
"src/actions.h"
"src/animation.cc"
@ -262,6 +262,14 @@ if(WIN32)
)
endif()
if(APPLE)
set_target_properties(${EXECUTABLE_NAME} PROPERTIES MACOSX_BUNDLE_INFO_PLIST "${CMAKE_SOURCE_DIR}/os/macos/Info.plist")
set(MACOSX_BUNDLE_GUI_IDENTIFIER "com.alexbatalov.fallout2-ce")
set(MACOSX_BUNDLE_BUNDLE_NAME "${EXECUTABLE_NAME}")
set(MACOSX_BUNDLE_DISPLAY_NAME "Fallout 2")
set(CMAKE_OSX_DEPLOYMENT_TARGET "12.0")
endif()
add_subdirectory("third_party/fpattern")
target_link_libraries(${EXECUTABLE_NAME} ${FPATTERN_LIBRARY})
target_include_directories(${EXECUTABLE_NAME} PRIVATE ${FPATTERN_INCLUDE_DIR})
@ -279,3 +287,18 @@ target_include_directories(${EXECUTABLE_NAME} PRIVATE ${ZLIB_INCLUDE_DIRS})
target_link_libraries(${EXECUTABLE_NAME} ${SDL2_LIBRARIES})
target_include_directories(${EXECUTABLE_NAME} PRIVATE ${SDL2_INCLUDE_DIRS})
if(APPLE)
install(TARGETS ${EXECUTABLE_NAME} DESTINATION .)
install(CODE "
include(BundleUtilities)
fixup_bundle(${CMAKE_BINARY_DIR}/${MACOSX_BUNDLE_BUNDLE_NAME}.app \"\" \"\")
"
COMPONENT Runtime)
set(CPACK_GENERATOR "DragNDrop")
set(CPACK_DMG_DISABLE_APPLICATIONS_SYMLINK ON)
set(CPACK_PACKAGE_FILE_NAME "fallout2-ce")
include(CPack)
endif()

36
os/macos/Info.plist Normal file
View File

@ -0,0 +1,36 @@
<?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>CFBundleDisplayName</key>
<string>${MACOSX_BUNDLE_DISPLAY_NAME}</string>
<key>CFBundleExecutable</key>
<string>${MACOSX_BUNDLE_EXECUTABLE_NAME}</string>
<key>CFBundleGetInfoString</key>
<string>${MACOSX_BUNDLE_INFO_STRING}</string>
<key>CFBundleIconFile</key>
<string>${MACOSX_BUNDLE_ICON_FILE}</string>
<key>CFBundleIdentifier</key>
<string>${MACOSX_BUNDLE_GUI_IDENTIFIER}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>${MACOSX_BUNDLE_BUNDLE_NAME}</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>${MACOSX_BUNDLE_SHORT_VERSION_STRING}</string>
<key>CFBundleVersion</key>
<string>${MACOSX_BUNDLE_BUNDLE_VERSION}</string>
<key>NSHumanReadableCopyright</key>
<string>${MACOSX_BUNDLE_COPYRIGHT}</string>
<key>NSHighResolutionCapable</key>
<string>True</string>
<key>LSMinimumSystemVersion</key>
<string>12</string>
<key>SDL_FILESYSTEM_BASE_DIR_TYPE</key>
<string>parent</string>
</dict>
</plist>

View File

@ -84,6 +84,12 @@ bool gProgramIsActive = false;
int main(int argc, char* argv[])
{
#if __APPLE__
char* basePath = SDL_GetBasePath();
chdir(basePath);
SDL_free(basePath);
#endif
SDL_ShowCursor(SDL_DISABLE);
gProgramIsActive = true;
return falloutMain(argc, argv);