# Copyright © SixtyFPS GmbH <info@slint.dev>
# SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-1.1 OR LicenseRef-Slint-commercial

name: Build the C++ binary package

on:
  workflow_dispatch:
  workflow_call:

env:
  MACOSX_DEPLOYMENT_TARGET: 11

jobs:
  cmake_package:
    env:
      DYLD_FRAMEWORK_PATH: /Users/runner/work/slint/Qt/6.5.1/clang_64/lib
      QT_QPA_PLATFORM: offscreen
      CARGO_INCREMENTAL: false
    strategy:
      matrix:
        os: [ubuntu-20.04, macOS-11, windows-2022]
    runs-on: ${{ matrix.os }}
    steps:
    - uses: actions/checkout@v3
    - uses: ./.github/actions/install-linux-dependencies
      with:
        old-ubuntu: true
    - name: Install Qt (Ubuntu)
      uses: jurplel/install-qt-action@v3
      if: matrix.os == 'ubuntu-20.04'
      with:
        version: 5.15.2
        cache: true
    - name: Install Qt (cached)
      if: matrix.os != 'ubuntu-20.04'
      uses: jurplel/install-qt-action@v3
      with:
        version: 6.5.1
        cache: true
    - uses: ./.github/actions/setup-rust
    - uses: baptiste0928/cargo-install@v2
      with:
        crate: cargo-about
    - name: Prepare licenses (with Qt)
      if: matrix.os == 'windows-2022' || matrix.os == 'macOS-11'
      run: bash -x ../../scripts/prepare_binary_package.sh ../.. --with-qt
      working-directory: api/cpp/
    - name: Prepare licenses (without Qt)
      if: matrix.os != 'windows-2022' && matrix.os != 'macOS-11'
      run: bash -x ../../scripts/prepare_binary_package.sh ../..
      working-directory: api/cpp/
    - uses: ilammy/msvc-dev-cmd@v1
    - name: Select MSVC (windows)
      run: |
        echo "CC=cl.exe" >> $GITHUB_ENV
        echo "CXX=cl.exe" >> $GITHUB_ENV
      if: matrix.os == 'windows-2022'
    - name: C++ Build
      uses: lukka/run-cmake@v3.4
      with:
        cmakeListsOrSettingsJson: CMakeListsTxtAdvanced
        cmakeListsTxtPath: CMakeLists.txt
        cmakeAppendedArgs: '-DCMAKE_BUILD_TYPE=RelWithDebInfo -DSLINT_PACKAGE_BUNDLE_QT=ON'
        buildDirectory: ${{ runner.workspace }}/cppbuild
        buildWithCMakeArgs: '--config Release'
    - name: cpack
      working-directory: ${{ runner.workspace }}/cppbuild
      run: cmake --build . --config Release --target package
    - name: "Upload C++ packages"
      uses: actions/upload-artifact@v3
      with:
          name: cpp_bin
          path: ${{ runner.workspace }}/cppbuild/Slint-cpp-*
