name: netCDF cmake dev

on:
  workflow_dispatch:
  push:
  pull_request:
    branches: [ master ]
    paths-ignore:
    - '.github/CODEOWNERS'
    - 'doc/**'
    - 'release_docs/**'
    - 'COPYING'
    - '**.md'

permissions:
  contents: read

# Using concurrency to cancel any in-progress job or run
concurrency:
  group: ${{ github.workflow }}-${{ github.head_ref && github.ref || github.run_id }}
  cancel-in-progress: true

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - name: Install System dependencies
      run: |
        sudo apt-get update
        sudo apt-get install ninja-build
        sudo apt install libssl3 libssl-dev libcurl4
        sudo apt install -y libaec-dev zlib1g-dev libcurl4-openssl-dev libjpeg-dev wget curl
        sudo apt install -y bzip2 m4 flex bison cmake libzip-dev doxygen openssl libtool libtool-bin

    - name: Checkout HDF4
      uses: actions/checkout@v4.1.7

    - name: CMake Configure HDF4
      run: |
          mkdir "${{ runner.workspace }}/build"
          cd "${{ runner.workspace }}/build"
          cmake -C $GITHUB_WORKSPACE/config/cmake/cacheinit.cmake \
            -G Ninja \
            -DCMAKE_BUILD_TYPE=Release \
            -DHDF4_BUILD_FORTRAN:BOOL=OFF \
            -DHDF4_BUILD_JAVA:BOOL=OFF \
            -DHDF4_BUILD_EXAMPLES:BOOL=OFF \
            -DBUILD_JPEG_WITH_PIC:BOOL=ON \
            -DJPEG_USE_LOCALCONTENT:BOOL=OFF \
            -DLIBAEC_USE_LOCALCONTENT:BOOL=OFF \
            -DZLIB_USE_LOCALCONTENT:BOOL=OFF \
            -DBUILD_TESTING:BOOL=OFF \
            -DBUILD_STATIC_LIBS:BOOL=OFF \
            -DCMAKE_INSTALL_PREFIX:PATH=/usr/local \
            $GITHUB_WORKSPACE
      shell: bash

    - name: CMake Build HDF4
      run: cmake --build . --parallel 3 --config Release
      working-directory: ${{ runner.workspace }}/build

    - name: Install HDF4
      run: |
        sudo cmake --install . --config Release --prefix="/usr/local"
      working-directory: ${{ runner.workspace }}/build

    - name: Checkout HDF5
      uses: actions/checkout@v4.1.7
      with:
        repository: HDFGroup/hdf5
        path: hdf5
        ref: hdf5_1.14.5

    - name: CMake Configure HDF5
      run: |
          mkdir "${{ runner.workspace }}/build5"
          cd "${{ runner.workspace }}/build5"
          cmake -C $GITHUB_WORKSPACE/hdf5/config/cmake/cacheinit.cmake \
            -G Ninja \
            -DCMAKE_BUILD_TYPE=Release \
            -DHDF4_BUILD_FORTRAN:BOOL=OFF \
            -DHDF4_BUILD_JAVA:BOOL=OFF \
            -DHDF4_BUILD_EXAMPLES:BOOL=OFF \
            -DLIBAEC_USE_LOCALCONTENT:BOOL=OFF \
            -DZLIB_USE_LOCALCONTENT:BOOL=OFF \
            -DBUILD_TESTING:BOOL=OFF \
            -DBUILD_STATIC_LIBS:BOOL=OFF \
            -DCMAKE_INSTALL_PREFIX:PATH=/usr/local \
            $GITHUB_WORKSPACE/hdf5
      shell: bash

    - name: CMake Build HDF5
      run: cmake --build . --parallel 3 --config Release
      working-directory: ${{ runner.workspace }}/build5

    - name: Install HDF5
      run: |
        sudo cmake --install . --config Release --prefix="/usr/local"
      working-directory: ${{ runner.workspace }}/build5

    - name: Checkout netCDF
      uses: actions/checkout@v4.1.7
      with:
        repository: unidata/netcdf-c
        path: netcdf-c

    - name: Test netCDF
      run: |
        mkdir "netcdf-c/build"
        cd "netcdf-c/build"
        cmake .. -DUILD_SHARED_LIBS=ON -DNETCDF_ENABLE_HDF4=ON -DNETCDF_ENABLE_HDF4=ON
        make
        make test
      continue-on-error: true
