!yamlscript/v0:

:use common: :all
::
  workflow-setup:: test_install

env:
  PROJ_PFX_TARGET: ryml-
  PROJ_PFX_CMAKE: RYML_
  CMAKE_FLAGS:
  NUM_JOBS_BUILD: # 4

jobs:
  install_tests:
    if: |
      (!contains(github.event.head_commit.message, 'skip all')) ||
      (!contains(github.event.head_commit.message, 'skip test_install')) ||
      contains(github.event.head_commit.message, 'only test_install')
    name: ${{matrix.name}}/${{matrix.bt}}
    continue-on-error: true
    runs-on: ${{matrix.os}}

    strategy:
      fail-fast: false
      matrix:
        include:

          - {name: find_package/linux,        sdir: test/test_install,      os: ubuntu-24.04,   cxx: g++-16,     gen: -DCMAKE_CXX_COMPILER=g++-16,               tgt: all,       bt: Debug,   vars: -Dryml_DIR=$GITHUB_WORKSPACE/$PDIR/lib/cmake/ryml -DRYML_TEST_INSTALL_PACKAGE_MODE=ON}
          - {name: find_package/linux/libcxx, sdir: test/test_install,      os: ubuntu-24.04,   cxx: clang++-18, gen: -DCMAKE_CXX_COMPILER=clang++-18,           tgt: all,       bt: Debug,   vars: -Dryml_DIR=$GITHUB_WORKSPACE/$PDIR/lib/cmake/ryml -DRYML_TEST_INSTALL_PACKAGE_MODE=ON, commonvars: -DRYML_USE_LIBCXX=ON}
          - {name: find_package/macos,        sdir: test/test_install,      os: macos-15-intel, cxx: xcode,      gen: -G Xcode -DCMAKE_OSX_ARCHITECTURES=x86_64, tgt: ALL_BUILD, bt: Debug,   vars: -Dryml_DIR=$GITHUB_WORKSPACE/$PDIR/lib/cmake/ryml -DRYML_TEST_INSTALL_PACKAGE_MODE=ON}
          - {name: find_package/win,          sdir: test/test_install,      os: windows-latest, cxx: vs2026,     gen: -G 'Visual Studio 18 2026' -A x64,         tgt: ALL_BUILD, bt: Debug,   vars: -Dryml_DIR=$GITHUB_WORKSPACE/$PDIR/cmake -DRYML_TEST_INSTALL_PACKAGE_MODE=ON}

          - {name: find_library/linux,        sdir: test/test_install,      os: ubuntu-24.04,   cxx: g++-16,     gen: -DCMAKE_CXX_COMPILER=g++-16,               tgt: all,       bt: Debug,   vars: -DCMAKE_PREFIX_PATH=$GITHUB_WORKSPACE/$PDIR -DRYML_TEST_INSTALL_PACKAGE_MODE=OFF}
          - {name: find_library/linux/libcxx, sdir: test/test_install,      os: ubuntu-24.04,   cxx: clang++-18, gen: -DCMAKE_CXX_COMPILER=clang++-18,           tgt: all,       bt: Debug,   vars: -DCMAKE_PREFIX_PATH=$GITHUB_WORKSPACE/$PDIR -DRYML_TEST_INSTALL_PACKAGE_MODE=OFF, commonvars: -DRYML_USE_LIBCXX=ON}
          - {name: find_library/macos,        sdir: test/test_install,      os: macos-15-intel, cxx: xcode,      gen: -G Xcode -DCMAKE_OSX_ARCHITECTURES=x86_64, tgt: ALL_BUILD, bt: Debug,   vars: -DCMAKE_PREFIX_PATH=$GITHUB_WORKSPACE/$PDIR -DRYML_TEST_INSTALL_PACKAGE_MODE=OFF}
          - {name: find_library/win,          sdir: test/test_install,      os: windows-latest, cxx: vs2026,     gen: -G 'Visual Studio 18 2026' -A x64,         tgt: ALL_BUILD, bt: Debug,   vars: -DCMAKE_PREFIX_PATH=$GITHUB_WORKSPACE/$PDIR -DRYML_TEST_INSTALL_PACKAGE_MODE=OFF}

          - {name: singleheader/linux,        sdir: test/test_singleheader, os: ubuntu-24.04,   cxx: g++-16,     gen: -DCMAKE_CXX_COMPILER=g++-16,               tgt: all,       bt: Debug}
          - {name: singleheader/linux/libcxx, sdir: test/test_singleheader, os: ubuntu-24.04,   cxx: clang++-18, gen: -DCMAKE_CXX_COMPILER=clang++-18,           tgt: all,       bt: Debug, commonvars: -DRYML_USE_LIBCXX=ON}
          - {name: singleheader/macos,        sdir: test/test_singleheader, os: macos-15-intel, cxx: xcode,      gen: -G Xcode -DCMAKE_OSX_ARCHITECTURES=x86_64, tgt: ALL_BUILD, bt: Debug}
          - {name: singleheader/win,          sdir: test/test_singleheader, os: windows-latest, cxx: vs2026,     gen: -G 'Visual Studio 18 2026' -A x64,         tgt: ALL_BUILD, bt: Debug}

    env:
      CXX_: ${{matrix.cxx}}
      BT:   ${{matrix.bt}}
      OS:   ${{matrix.os}}
      BDIR: build/${{matrix.name}}-${{matrix.bt}}
      IDIR: install/${{matrix.name}}-${{matrix.bt}}
      PDIR: prefix/${{matrix.name}}-${{matrix.bt}}

    steps:
    - name: checkout
      uses: actions/checkout@v4
      with: {submodules: recursive}
    - name: install requirements
      run: source .github/reqs.sh && c4_install_test_requirements $OS
    - name: show info
      run: source .github/setenv.sh && c4_show_info
    - :: install-python-action
    - name: preinstall
      run: |
        if [ "${{matrix.sdir}}" == "test/test_install" ] ; then
          mkdir -p $BDIR-staging
          cmake -S . -B $BDIR-staging \
              -DCMAKE_INSTALL_PREFIX=$PDIR \
              -DCMAKE_BUILD_TYPE=${{matrix.bt}} \
              -DRYML_EXTRA_ALL=ON \
              ${{matrix.gen}} \
              ${{matrix.commonvars}}
          cmake --build $BDIR-staging --config ${{matrix.bt}} --target ${{matrix.tgt}} -j
          cmake --build $BDIR-staging --config ${{matrix.bt}} --target install
        fi
    - name: configure
      run: |
        mkdir -p $BDIR
        mkdir -p $IDIR
        cmake -S ${{matrix.sdir}} -B $BDIR \
          -DRYML_BUILD_TESTS=ON \
          -DRYML_VALGRIND=OFF \
          -DCMAKE_BUILD_TYPE=${{matrix.bt}} \
          -DCMAKE_INSTALL_PREFIX=$IDIR \
          ${{matrix.gen}} \
          ${{matrix.vars}} \
          ${{matrix.commonvars}}
    - name: build
      run: |
        cmake --build $BDIR --config ${{matrix.bt}} --target ryml-test-build -j
    - name: run
      run: |
        cmake --build $BDIR --config ${{matrix.bt}} --target ryml-test-run
