name: hdf4 CMake aocc

# Triggers the workflow on a call from another workflow
on:
  workflow_call:
    inputs:
      build_mode:
        description: "release vs. debug build"
        required: true
        type: string

permissions:
  contents: read

jobs:
  aocc_build_and_test:
    name: "aocc ${{ inputs.build_mode }}"
    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 cmake ninja-build doxygen graphviz
          sudo apt install libssl3 libssl-dev libcurl4 libcurl4-openssl-dev
          sudo apt install -y zlib1g-dev libaec-dev libjpeg-dev
          sudo apt install -y wget curl bzip2 flex bison libzip-dev openssl build-essential

      - name: Install AOCC 4.2.0
        shell: bash
        run: |
          wget https://download.amd.com/developer/eula/aocc/aocc-4-2/aocc-compiler-4.2.0.tar
          tar -xvf aocc-compiler-4.2.0.tar
          cd aocc-compiler-4.2.0
          bash install.sh
          source /home/runner/work/hdf4/hdf4/setenv_AOCC.sh
          which clang
          which flang
          clang -v

      - name: CMake Configure
        shell: bash
        run: |
          export LD_LIBRARY_PATH=/home/runner/work/hdf5/hdf5/aocc-compiler-4.2.0/lib:/home/runner/work/hdf5/hdf5/openmpi-4.1.6-install/lib:/usr/local/lib
          export LD_RUN_PATH=/home/runner/work/hdf5/hdf5/aocc-compiler-4.2.0/lib:/home/runner/work/hdf5/hdf5/openmpi-4.1.6-install/lib:/usr/local/lib
          export PATH=/usr/local/bin:$PATH
          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 }} \
            -DJPEG_USE_LOCALCONTENT=OFF \
            -DLIBAEC_USE_LOCALCONTENT=OFF \
            -DZLIB_USE_LOCALCONTENT=OFF \
            -DHDF4_BUILD_FORTRAN:BOOL=ON \
            -DHDF4_BUILD_JAVA:BOOL=OFF \
            $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
        working-directory: ${{ runner.workspace }}/build
