shun-iwasawa 9f7051
name: MacOS Build
shun-iwasawa 9f7051
shun-iwasawa 9f7051
on: [push, pull_request]
shun-iwasawa 9f7051
shun-iwasawa 9f7051
jobs:
shun-iwasawa 9f7051
  macOS:
shun-iwasawa 9f7051
    runs-on: macos-latest
shun-iwasawa 9f7051
    steps:
shun-iwasawa 9f7051
    - uses: actions/checkout@v2
shun-iwasawa 9f7051
shun-iwasawa f2a30f
    - name: Remove symlinks
shun-iwasawa f2a30f
      run: |
shun-iwasawa f2a30f
        # remove existing symlinks before installing python@3.10 and 3.11
shun-iwasawa f2a30f
        rm /usr/local/bin/2to3
shun-iwasawa f2a30f
        rm /usr/local/bin/idle3
shun-iwasawa f2a30f
        rm /usr/local/bin/pydoc3
shun-iwasawa f2a30f
        rm /usr/local/bin/python3
shun-iwasawa f2a30f
        rm /usr/local/bin/python3-config
shun-iwasawa f2a30f
        rm /usr/local/bin/2to3-3.11
shun-iwasawa f2a30f
        rm /usr/local/bin/idle3.11
shun-iwasawa f2a30f
        rm /usr/local/bin/pydoc3.11
shun-iwasawa f2a30f
        rm /usr/local/bin/python3.11
shun-iwasawa f2a30f
        rm /usr/local/bin/python3.11-config
shun-iwasawa f2a30f
shun-iwasawa 9f7051
    - name: Install libraries
shun-iwasawa 9f7051
      run: |
shun-iwasawa 9f7051
        checkPkgAndInstall()
shun-iwasawa 9f7051
        {
shun-iwasawa 9f7051
          while [ $# -ne 0 ]
shun-iwasawa 9f7051
          do
shun-iwasawa 9f7051
            if brew ls --versions $1 ; then
shun-iwasawa 9f7051
              brew upgrade $1
shun-iwasawa 9f7051
            else
shun-iwasawa 9f7051
              brew install $1
shun-iwasawa 9f7051
            fi
shun-iwasawa 9f7051
            shift
shun-iwasawa 9f7051
          done
shun-iwasawa f2a30f
        }        
shun-iwasawa 9f7051
        brew update
shun-iwasawa 9e6e83
        checkPkgAndInstall pkg-config glew lz4 libjpeg libpng lzo qt@5 boost libusb libmypaint ccache jpeg-turbo ninja
shun-iwasawa 31accf
        checkPkgAndInstall opencv
shun-iwasawa 31accf
        
shun-iwasawa 9f7051
    - uses: actions/cache@v1
shun-iwasawa 9f7051
      with:
shun-iwasawa 9f7051
        path: /Users/runner/.ccache
shun-iwasawa 9f7051
        key: ${{ runner.os }}-${{ github.sha }}
shun-iwasawa 9f7051
        restore-keys: ${{ runner.os }}-
shun-iwasawa 9f7051
shun-iwasawa 9f7051
    - name: Build libtiff
shun-iwasawa 9f7051
      run: |
shun-iwasawa 9f7051
        export PATH="/usr/local/opt/ccache/libexec:$PATH"
shun-iwasawa 9f7051
        cd thirdparty/tiff-4.0.3
shun-iwasawa 9f7051
        CFLAGS='-fPIC' CXXFLAGS='-fPIC' ./configure --disable-lzma
shun-iwasawa 9f7051
        make -j $(nproc)
shun-iwasawa 9f7051
shun-iwasawa 9f7051
    - name: Build
shun-iwasawa 9f7051
      run: |
shun-iwasawa 31accf
        export PKG_CONFIG_PATH="/usr/local/opt/jpeg-turbo/lib/pkgconfig:$PKG_CONFIG_PATH"
shun-iwasawa 9f7051
        cd toonz
shun-iwasawa 9f7051
        mkdir build
shun-iwasawa 9f7051
        cd build
shun-iwasawa 9e6e83
        cmake ../sources -G Ninja -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DQT_PATH='/usr/local/opt/qt@5/lib' -DWITH_TRANSLATION=OFF
shun-iwasawa 9f7051
        ninja -w dupbuild=warn
shun-iwasawa 222d5a
    
shun-iwasawa 222d5a
    - name: Introduce Libraries and Stuff
shun-iwasawa 9f7051
      run: |
shun-iwasawa 9f7051
        cd toonz/build/toonz
shun-iwasawa 9f7051
        cp -pr ../../../stuff OpenToonz.app/portablestuff
shun-iwasawa 222d5a
        /usr/local/opt/qt@5/bin/macdeployqt OpenToonz.app -verbose=1 -always-overwrite \
shun-iwasawa 9f7051
        -executable=OpenToonz.app/Contents/MacOS/lzocompress \
shun-iwasawa 9f7051
        -executable=OpenToonz.app/Contents/MacOS/lzodecompress \
shun-iwasawa 9f7051
        -executable=OpenToonz.app/Contents/MacOS/tcleanup \
shun-iwasawa 9f7051
        -executable=OpenToonz.app/Contents/MacOS/tcomposer \
shun-iwasawa 9f7051
        -executable=OpenToonz.app/Contents/MacOS/tconverter \
shun-iwasawa 9f7051
        -executable=OpenToonz.app/Contents/MacOS/tfarmcontroller \
shun-iwasawa 9f7051
        -executable=OpenToonz.app/Contents/MacOS/tfarmserver
shun-iwasawa 222d5a
    
shun-iwasawa 222d5a
    - name: Modify Library Paths
shun-iwasawa 222d5a
      run: |
shun-iwasawa 222d5a
        cd toonz/build/toonz/OpenToonz.app/Contents/Frameworks
shun-iwasawa 222d5a
        for TARGETLIB in `ls ./ | grep dylib`
shun-iwasawa 222d5a
        do
shun-iwasawa 222d5a
          echo $TARGETLIB
shun-iwasawa 222d5a
          for FROMPATH in `otool -L "$TARGETLIB" | grep ".dylib" | grep -v "$TARGETLIB" | grep -v "@executable_path/../Frameworks" | sed -e"s/ (.*$//"`
shun-iwasawa 222d5a
          do
shun-iwasawa 222d5a
            echo "  $FROMPATH"
shun-iwasawa 222d5a
            LIBNAME=`basename $FROMPATH`
shun-iwasawa 222d5a
            if [[ -e ./$LIBNAME ]]; then
shun-iwasawa 222d5a
              echo "updating library path of $LIBNAME in $TARGETLIB"
shun-iwasawa 222d5a
              install_name_tool -change "$FROMPATH" "@executable_path/../Frameworks/$LIBNAME" $TARGETLIB
shun-iwasawa 222d5a
            fi
shun-iwasawa 222d5a
          done
shun-iwasawa 222d5a
        done
shun-iwasawa 9f7051
shun-iwasawa 222d5a
    - name: Create Artifact
shun-iwasawa 222d5a
      run: |
shun-iwasawa 222d5a
        cd toonz/build/toonz
shun-iwasawa 222d5a
        /usr/local/opt/qt@5/bin/macdeployqt OpenToonz.app -dmg -verbose=1
shun-iwasawa 222d5a
    
shun-iwasawa 9f7051
    - uses: actions/upload-artifact@v1
shun-iwasawa 9f7051
      with:
shun-iwasawa 9f7051
        name: Opentoonz-${{ runner.os }}-${{ github.sha }}
shun-iwasawa 9f7051
        path: toonz/build/toonz/OpenToonz.dmg