freebsd_task:
  freebsd_instance:
    image_family: freebsd-14-2
    cpu: 4
    memory: 4G
  install_script:
    - pkg update
    - pkg install -y pkgconf cmake gmake capstone4 GraphicsMagick png
          devel/sdl20 devel/libedit
  script:
    - ./configure --enable-debug || { cat config.log; exit 1; }
    - gmake -j4
    - gmake test || { cat Testing/Temporary/LastTest.log; exit 1; }

xcode_task:
  osx_instance:
    image: ghcr.io/cirruslabs/macos-runner:sonoma
  env:
    SDLVERSION: 2.26.5
    PNGVERSION: 1.6.48
  download_cache:
    folder: dl_cache
    populate_script:
      - if [ ! -d dl_cache ]; then mkdir dl_cache ; fi
  install_script:
    # Download and install precompiled SDL2 Framework
    - if [ ! -f dl_cache/SDL2-$SDLVERSION.dmg ]; then
        wget -O dl_cache/SDL2-$SDLVERSION.dmg
          https://github.com/libsdl-org/SDL/releases/download/release-$SDLVERSION/SDL2-$SDLVERSION.dmg ;
      fi
    - hdiutil attach dl_cache/SDL2-$SDLVERSION.dmg
    - sudo cp -a /Volumes/SDL2/SDL2.framework /Library/Frameworks/
    # Download, compile and install libpng Framework
    - if [ ! -e dl_cache/png.framework ]; then
        wget -O dl_cache/libpng-$PNGVERSION.tar.xz
          "http://prdownloads.sourceforge.net/libpng/libpng-$PNGVERSION.tar.xz?download" ;
        tar -xJf dl_cache/libpng-$PNGVERSION.tar.xz ;
        cd libpng-$PNGVERSION ;
        cmake -DPNG_FRAMEWORK=ON -DPNG_HARDWARE_OPTIMIZATIONS=OFF
              -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING="10.13"
              -DCMAKE_OSX_ARCHITECTURES:STRING="arm64;x86_64" . ;
        cmake --build . --verbose --config Release -j$(sysctl -n hw.ncpu) ;
        codesign --force -s - png.framework ;
        cd .. ;
        mv libpng-$PNGVERSION/png.framework dl_cache/ ;
        rm -rf libpng-$PNGVERSION ;
      fi
    - sudo cp -a dl_cache/png.framework /Library/Frameworks/
    # Download and install precompiled portmidi Framework
    - if [ ! -e dl_cache/portmidi.framework ]; then
        cd dl_cache ;
        wget "https://hatari.tuxfamily.org/ci/portmidi.framework.zip" ;
        unzip portmidi.framework.zip ;
        mv license.txt portmidi-license.txt ;
        cd .. ;
      fi
    - sudo cp -a dl_cache/portmidi.framework /Library/Frameworks/
    # Download and install precompiled capsimage Framework
    - if [ ! -e dl_cache/capsimage_5.1_macos-x86_64-arm64 ]; then
        cd dl_cache ;
        wget "https://hatari.tuxfamily.org/ci/capsimage_5.1_macos-x86_64-arm64_selfsigned.zip" ;
        unzip capsimage_5.1_macos-x86_64-arm64_selfsigned.zip ;
        cd capsimage_5.1_macos-x86_64-arm64 ;
        mv LICENCE.txt DONATIONS.txt README.txt HISTORY.txt CAPSImage.framework ;
        cd ../.. ;
      fi
    - sudo cp -a dl_cache/capsimage_5.1_macos-x86_64-arm64/CAPSImage.framework /Library/Frameworks/
  script:
    - export PATH=/usr/local/bin:$PATH
    - mkdir build
    - cd build
    - cmake -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING="10.13"
            -DCMAKE_OSX_ARCHITECTURES:STRING="arm64;x86_64" ..
      || { cat config.log; exit 1; }
    - cmake --build . --verbose --config Release -j$(sysctl -n hw.ncpu) -t Hatari
    - cp -a ../dl_cache/portmidi.framework src/hatari.app/Contents/Frameworks/
    - cp -a ../dl_cache/capsimage_5.1_macos-x86_64-arm64/CAPSImage.framework src/hatari.app/Contents/Frameworks/
    - codesign --force -s - --entitlements ../src/gui-osx/hatari.app.xcent src/Hatari.app
    - cd ..
    - mkdir hatari-snapshot
    - echo $(git rev-parse HEAD) > hatari-snapshot/version.txt
    - date >> hatari-snapshot/version.txt
    - cp -a build/src/Hatari.app hatari-snapshot/
    - cp -a doc gpl.txt readme.txt hatari-snapshot/
    - cp dl_cache/portmidi-license.txt hatari-snapshot/
    - zip -r hatari-snapshot.zip hatari-snapshot
  hatari_artifacts:
    path: "hatari-snapshot.zip"

macos14_task:
  osx_instance:
    image: ghcr.io/cirruslabs/macos-runner:sonoma
  install_script:
    - brew update
    - brew install sdl2 libpng make tidy-html5 imagemagick capstone
  script:
    - export PATH=/usr/local/bin:$PATH
    - ./configure --disable-osx-bundle --enable-debug
      || { cat config.log; exit 1; }
    - gmake -j$(sysctl -n hw.ncpu)
    - gmake test || { cat Testing/Temporary/LastTest.log; exit 1; }

cygwin_task:
  windows_container:
    image: cirrusci/windowsservercore:2019
    os_version: 2019
    cpu: 4
    memory: 4G
  env:
    BE: cygwin-gcc
  install_script:
    - choco install -y --no-progress cygwin
    - C:\tools\cygwin\cygwinsetup.exe -q -P
        make,cmake,gcc-core,pkg-config,zlib-devel,libSDL2-devel,libpng-devel
  script:
    - C:\tools\cygwin\bin\bash.exe -lc "cd '%cd%' ;
       CFLAGS='-Werror -Wno-error=char-subscripts' cmake -G 'Unix Makefiles' ."
    - C:\tools\cygwin\bin\bash.exe -lc "cd '%cd%' ; make -j4"
  test_script:
    - C:\tools\cygwin\bin\bash.exe -lc "cd '%cd%' ; ctest -j4"

msys2_task:
  windows_container:
    image: cirrusci/windowsservercore:2019
    cpu: 4
    memory: 4G
  env:
    MSYS: winsymlinks:nativestrict
    MSYSTEM: MINGW64
    CHERE_INVOKING: 1
  choco_cache:
    folder: '%temp%\chocolatey'
  install_script:
    - choco install -y --no-progress msys2
    # Keep the log and temporary files out of the cache:
    - del %temp%\chocolatey\*.log
    - del %temp%\chocolatey\*log.txt
    - del %temp%\chocolatey\*.tmp
    # Install the required libraries:
    - C:\tools\msys64\usr\bin\bash -lc "pacman --noconfirm -S --needed
         make pkg-config diffutils
         mingw-w64-x86_64-cmake
         mingw-w64-x86_64-gcc
         mingw-w64-x86_64-SDL2
         mingw-w64-x86_64-libpng
         mingw-w64-x86_64-portmidi"
  script:
    - C:\tools\msys64\usr\bin\bash -lc "cmake -G 'MSYS Makefiles' ."
    - C:\tools\msys64\usr\bin\bash -lc "make -j4"
  test_script:
    - C:\tools\msys64\usr\bin\bash -lc "ctest"

visualstudio_task:
  windows_container:
    image: cirrusci/windowsservercore:2019
    cpu: 4
    memory: 4G
  choco_cache:
    folder: '%temp%\chocolatey'
  install_script:
    - choco install -y --no-progress cmake --install-arguments="ADD_CMAKE_TO_PATH=System"
    - choco install -y --no-progress visualstudio2019community
        visualstudio2019-workload-vctools
    # Keep the log and temporary files out of the cache:
    - del %temp%\chocolatey\*.log
    - del %temp%\chocolatey\*log.txt
    - del %temp%\chocolatey\*.tmp
    - del %temp%\chocolatey\windowssdk\*.log
    - del %temp%\chocolatey\VSLogs\*.svclog
    # Install the required libraries and headers:
    - curl -LO "https://github.com/libsdl-org/SDL/releases/download/release-2.32.2/SDL2-devel-2.32.2-VC.zip"
    - powershell -command "Expand-Archive -Force '%cd%\SDL2-devel-2.32.2-VC.zip' '%cd%'"
    - curl -O https://raw.githubusercontent.com/barrysteyn/scrypt-windows/master/win/include/unistd.h
    - curl -O https://raw.githubusercontent.com/tronkko/dirent/master/include/dirent.h
    - echo // > getopt.h
  script:
    - refreshenv
    - cmake -G "Visual Studio 16 2019" -A X64 -DCMAKE_BUILD_TYPE="Release"
            -DSDL2_DIR:PATH=SDL2-2.32.2\cmake .
    - cmake --build . --verbose --target ALL_BUILD --config Release -j4
  test_script:
    - refreshenv
    - ctest -C Release
