From 86ee748396fe122958ae3ed34a7150ed26620391 Mon Sep 17 00:00:00 2001 From: PalindromicBreadLoaf Date: Tue, 22 Jul 2025 08:44:39 -0400 Subject: [PATCH] Implement github CI for the project --- .github/workflows/ci.yml | 76 ++++++++++++++++++++++++++++++++++++++++ CMakeLists.txt | 20 ++++++++--- 2 files changed, 92 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..34b4e36 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,76 @@ +name: CI + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + build: + name: Build ${{ matrix.os }} - ${{ matrix.build_type }} + runs-on: ${{ matrix.os }} + + strategy: + matrix: + os: [ubuntu-latest, windows-latest, macos-latest] + build_type: [Debug, Release] + + steps: + - name: Checkout source + uses: actions/checkout@v4 + + - name: Set up cache + uses: actions/cache@v4 + with: + path: | + build/_deps + ~/.cache + ~/AppData/Local/vcpkg/archives + key: ${{ runner.os }}-cmake-${{ matrix.build_type }}-${{ hashFiles('**/CMakeLists.txt') }} + restore-keys: | + ${{ runner.os }}-cmake-${{ matrix.build_type }} + + - name: Install dependencies (Linux) + if: matrix.os == 'ubuntu-latest' + run: | + sudo apt update + sudo apt install -y cmake build-essential libsdl2-dev + + - name: Install dependencies (macOS) + if: matrix.os == 'macos-latest' + run: | + brew install cmake sdl2 + + - name: Install dependencies (Windows) + if: matrix.os == 'windows-latest' + run: | + choco install cmake --installargs 'ADD_CMAKE_TO_PATH=System' --yes + vcpkg install sdl2 + shell: bash + + - name: Configure CMake + run: | + cmake -S . -B build -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} + env: + CMAKE_TOOLCHAIN_FILE: ${{ matrix.os == 'windows-latest' && 'C:/vcpkg/scripts/buildsystems/vcpkg.cmake' || '' }} + + - name: Build + run: cmake --build build --config ${{ matrix.build_type }} + + - name: Package + run: | + cd build + cpack + + - name: Upload Artifacts + uses: actions/upload-artifact@v4 + with: + name: breadedSNES-${{ matrix.os }}-${{ matrix.build_type }} + path: | + build/*.zip + build/*.dmg + build/*.tar.gz + build/*.tgz + build/*.exe + build/*.7z diff --git a/CMakeLists.txt b/CMakeLists.txt index c955081..b2f3998 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,6 +7,11 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -O0") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3") +if(DEFINED ENV{VCPKG_ROOT} AND NOT DEFINED CMAKE_TOOLCHAIN_FILE) + set(CMAKE_TOOLCHAIN_FILE "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" + CACHE STRING "") +endif() + # Platform-specific settings if(WIN32) add_definitions(-DWIN32_LEAN_AND_MEAN) @@ -19,7 +24,7 @@ elseif(UNIX) endif() # Find SDL2 -if(WIN32) +if(WIN32 AND NOT DEFINED ENV{VCPKG_ROOT}) # Windows things set(SDL2_DIR "C:/SDL2" CACHE PATH "/path/to/sdl2") # Do this later when I have access to a Windows machine find_package(SDL2 REQUIRED CONFIG) @@ -41,11 +46,14 @@ elseif(APPLE) find_package(SDL2 REQUIRED CONFIG) message(STATUS "Found SDL2 at: ${SDL2_DIR}") -else() - find_package(PkgConfig REQUIRED) - pkg_check_modules(SDL2 REQUIRED sdl2) +elseif(UNIX) + if(NOT SDL2_FOUND) + find_package(PkgConfig REQUIRED) + pkg_check_modules(SDL2 REQUIRED sdl2) + endif() endif() + add_executable(breadedSNES src/main.cpp src/cpu.cpp @@ -60,6 +68,10 @@ add_executable(breadedSNES src/ppu.h ) +if(SDL2_FOUND) + include_directories(${SDL2_INCLUDE_DIRS}) +endif() + target_include_directories(breadedSNES PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include ${SDL2_INCLUDE_DIRS}