name: hdf4 dev CMake MinGW CI

# Controls when the action will run. Triggers the workflow on a call
on:
  workflow_call:
    inputs:
      build_mode:
        description: "release vs. debug build"
        required: true
        type: string
      shared:
        description: "shared true/false"
        required: true
        type: string
      netcdf:
        description: "netcdf true/false"
        required: true
        type: string

permissions:
  contents: read

jobs:
  # A workflow that builds the library and runs all the tests
  CMake_build_and_test:
    name: "Ubuntu mingw-${{ inputs.build_mode }}-NC=${{ inputs.netcdf }}"
    # Don't run the action if the commit message says to skip CI
    if: "!contains(github.event.head_commit.message, 'skip-ci')"
    # The type of runner that the job will run on
    runs-on: ubuntu-latest

    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:

      #
      # SETUP
      #
      - name: Install CMake Dependencies (Linux)
        run: |
           sudo apt update
           sudo apt-get install -y ninja-build libtirpc-dev graphviz

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

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

      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      - name: Get Sources
        uses: actions/checkout@v4.1.1

      #
      # CMAKE CONFIGURE
      #
      - name: CMake Configure
        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=config/toolchain/mingw64.cmake \
            -DBUILD_SHARED_LIBS:BOOL=${{ inputs.shared }} \
            -DHDF4_BUILD_EXAMPLES:BOOL=ON \
            -DBUILD_JPEG_WITH_PIC:BOOL=ON \
            -DHDF4_ENABLE_NETCDF:BOOL=${{ inputs.netcdf }} \
            -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
        shell: bash

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

      #
      # RUN TESTS
      #
      - name: CMake Run Tests
        run: ctest . --parallel 2 -C ${{ inputs.build_mode }} -V
        working-directory: ${{ runner.workspace }}/build
        if: false

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

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