name: hdf4 CMake MinGW

on:
  workflow_call:
    inputs:
      build_mode:
        description: "release vs. debug build"
        required: true
        type: string
      shared:
        description: "shared true/false"
        required: true
        type: string

permissions:
  contents: read

jobs:
  mingw_build_and_test:
    name: "mingw-${{ inputs.build_mode }}"
    if: "!contains(github.event.head_commit.message, 'skip-ci')"
    runs-on: ubuntu-latest
    steps:
      - name: Get Sources
        uses: actions/checkout@v4.1.7

      - name: Install Dependencies
        shell: bash
        run: |
           sudo apt update
           sudo apt-get install -y ninja-build libtirpc-dev graphviz

      - name: Install MinGW
        uses: egor-tensin/setup-mingw@v2
        with:
          platform: x64

      - name: Install Doxygen
        uses: ssciwr/doxygen-install@v1
        with:
          version: "1.9.7"

      - name: CMake Configure
        shell: bash
        run: |
          mkdir "${{ runner.workspace }}/build"
          cd "${{ runner.workspace }}/build"
          cmake -C $GITHUB_WORKSPACE/config/cmake/cacheinit.cmake \
            -G Ninja \
            --log-level=VERBOSE \
            -DCMAKE_BUILD_TYPE=${{ inputs.build_mode }} \
            -DCMAKE_TOOLCHAIN_FILE=$GITHUB_WORKSPACE/config/toolchain/mingw64.cmake \
            -DBUILD_SHARED_LIBS:BOOL=${{ inputs.shared }} \
            -DHDF4_BUILD_EXAMPLES:BOOL=ON \
            -DBUILD_JPEG_WITH_PIC:BOOL=ON \
            -DHDF4_BUILD_FORTRAN:BOOL=OFF \
            -DHDF4_BUILD_JAVA:BOOL=OFF \
            -DHDF4_BUILD_DOC:BOOL=ON \
            -DJPEG_USE_LOCALCONTENT:BOOL=OFF \
            -DLIBAEC_USE_LOCALCONTENT:BOOL=OFF \
            -DZLIB_USE_LOCALCONTENT:BOOL=OFF \
            -DHDF4_PACK_EXAMPLES:BOOL=ON \
            -DHDF4_PACKAGE_EXTLIBS:BOOL=ON \
            $GITHUB_WORKSPACE

      - name: CMake Build
        shell: bash
        run: |
          cmake --build . --parallel 3 --config ${{ inputs.build_mode }}
        working-directory: ${{ runner.workspace }}/build

      - name: CMake Run Tests
        shell: bash
        run: |
          ctest . --parallel 2 -C ${{ inputs.build_mode }} -V
        if: false

      - name: CMake Package
        shell: bash
        run: |
          cpack -C ${{ inputs.build_mode }} -V
        working-directory: ${{ runner.workspace }}/build

      - name: List files in the space
        run: |
              ls -l ${{ runner.workspace }}/build
