Skip to content

Commit

Permalink
Build on MacOS
Browse files Browse the repository at this point in the history
  • Loading branch information
yujincheng08 committed Sep 6, 2024
1 parent cf7963d commit 1c19213
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 0 deletions.
64 changes: 64 additions & 0 deletions .github/workflows/build_darwin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: build MacOS
on:
push: {tags: ['v*']} # Push events to matching v*, i.e. v1.0, v20.15.10
pull_request:

permissions:
contents: write

jobs:
build_darwin_aarch64:
runs-on: macos-14
steps:
- uses: actions/checkout@v3

- name: Install dependencies
run: |
brew install sdl2 sdl2_ttf sdl2_image sdl2_mixer lua bzip2
- name: Build
run: |
cd script
bash ./local_darwin.sh
- name: prepare release
if: github.event_name == 'push'
run: |
cd build_darwin
mv onsyuri onsyuri_${{ github.ref_name }}_aarch64_darwin
- name: create release
uses: ncipollo/release-action@v1
if: github.event_name == 'push'
with:
artifacts: "./build_darwin/onsyuri_${{ github.ref_name }}_aarch64_darwin"
allowUpdates: "true"
token: ${{ secrets.GITHUB_TOKEN }}

build_darwin_x86-64:
runs-on: macos-13
steps:
- uses: actions/checkout@v3

- name: Install dependencies
run: |
brew install sdl2 sdl2_ttf sdl2_image sdl2_mixer lua bzip2
- name: Build
run: |
cd script
bash ./local_darwin.sh
- name: prepare release
if: github.event_name == 'push'
run: |
cd build_darwin
mv onsyuri onsyuri_${{ github.ref_name }}_x86-64_darwin
- name: create release
uses: ncipollo/release-action@v1
if: github.event_name == 'push'
with:
artifacts: "./build_darwin/onsyuri_${{ github.ref_name }}_x86-64_darwin"
allowUpdates: "true"
token: ${{ secrets.GITHUB_TOKEN }}
41 changes: 41 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,45 @@ function(config_linux TARGET_NAME)

endfunction()

function(config_darwin TARGET_NAME)
add_executable(${TARGET_NAME} ${ONSYURI_CODE})
message("Darwin enviroment for ${TARGET_NAME}, type ${CMAKE_BUILD_TYPE}, compiler ${CMAKE_C_COMPILER}")
target_compile_definitions(${TARGET_NAME} PRIVATE
${ONSYURI_DEFINES}
MACOSX
USE_PARALLEL
USE_GLES
USE_FILELOG
)
target_compile_options(${TARGET_NAME} PRIVATE
-Wno-deprecated-declarations
-Wno-invalid-source-encoding
)

include(FindPkgConfig)
pkg_check_modules(SDL2 REQUIRED sdl2)
pkg_check_modules(SDL2_TTF REQUIRED SDL2_ttf)
pkg_check_modules(SDL2_IMAGE REQUIRED SDL2_image)
pkg_check_modules(SDL2_MIXER REQUIRED SDL2_mixer)
pkg_check_modules(LUA REQUIRED lua)

target_include_directories(${TARGET_NAME} PRIVATE
${LUA_INCLUDE_DIRS}
${SDL2_INCLUDE_DIRS}
${SDL2_TTF_INCLUDE_DIRS}
${SDL2_IMAGE_INCLUDE_DIRS}
${SDL2_MIXER_INCLUDE_DIRS}
)
target_link_libraries(${TARGET_NAME} PRIVATE
bz2
${LUA_LINK_LIBRARIES}
${SDL2_LINK_LIBRARIES}
${SDL2_TTF_LINK_LIBRARIES}
${SDL2_IMAGE_LINK_LIBRARIES}
${SDL2_MIXER_LINK_LIBRARIES}
)
endfunction()

function(config_windows_mingw TARGET_NAME)
add_executable(${TARGET_NAME} WIN32
${ONSYURI_CODE}
Expand Down Expand Up @@ -405,6 +444,8 @@ function(config_platform TARGET_NAME)
)
elseif(CMAKE_SYSTEM_NAME MATCHES "Android")
config_android(${TARGET_NAME})
elseif(CMAKE_SYSTEM_NAME MATCHES "Darwin")
config_darwin(${TARGET_NAME})
else()
message("${CMAKE_SYSTEM_NAME} enviroment for ${TARGET_NAME} not supported!")
endif()
Expand Down
21 changes: 21 additions & 0 deletions script/local_darwin.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# bash -c "export BUILD_TYPE=Debug && export USE_STATIC_PORTS=yes && export SKIP_PORTS=yes && ./local_linux64.sh"
PLATFORM=darwin
BUILD_PATH=./../build_${PLATFORM}
CMAKELISTS_PATH=$(pwd)/..
CORE_NUM=$(nproc)
TARGETS=$@

# config env
CC=gcc
CXX=g++
if [ -z "$BUILD_TYPE" ]; then BUILD_TYPE=MinSizeRel; fi
if [ -z "$TARGETS" ]; then TARGETS=all; fi

# config and build project
# USE_STATIC_PORTS=yes
# SKIP_PORTS=yes
echo "BUILD_TYPE=$BUILD_TYPE"
cmake -B $BUILD_PATH -S $CMAKELISTS_PATH \
-G "Unix Makefiles" -DCMAKE_BUILD_TYPE=$BUILD_TYPE \

make -C $BUILD_PATH $TARGETS -j$CORE_NUM

0 comments on commit 1c19213

Please sign in to comment.