# SPDX-License-Identifier: BSD-3-Clause
# Copyright (c) Contributors to the OpenEXR Project.

# The CI workflow uses steps defined in ci_steps.yml, via the "uses:"
# directive. Linux, macOS, and Windows all share a common set of
# configure/build/validate steps.

name: CI

on:
  push:
    paths:
      - '**'
      - '!**.md'
      - '!.github/workflows/**'
      - '.github/workflows/ci_workflow.yml'
      - '.github/workflows/ci_steps.yml'
  pull_request:
    paths:
      - '**'
      - '!**.md'
      - '!.github/workflows/**'
      - '.github/workflows/ci_workflow.yml'
      - '.github/workflows/ci_steps.yml'

permissions:
  contents: read

# NOTE: All jobs have a "build" number that appears in the "jobs"
# listing on the GitHub actions page. This build number also
# identifies the reference install manifest in
# share/ci/install_manifest. The validate_install.py script compares
# the job's generated install_manifest.txt to the reference file to
# validate that the proper files have been installed.
#
# If you add jobs, you must add a corresponding
# share/ci/install_manifest file.

jobs:
  linux:
    name: 'Linux.${{ matrix.build}}: ${{ matrix.label }}'
    uses: ./.github/workflows/ci_steps.yml
    with:
      # Set values for the "inputs:" as defined in ci_steps.yml
      # Note the defaults provided here for the builds that don't specify
      # values.
      os: ubuntu-latest
      build: ${{ matrix.build }}
      cmake: ${{ matrix.cmake || '3.15.7' }}
      cxx-standard: ${{ matrix.cxx-standard || '14' }}
      cxx-compiler: ${{ matrix.cxx-compiler || 'g++' }}
      cc-compiler: ${{ matrix.cc-compiler || 'gcc' }}
      build-type: ${{ matrix.build-type || 'Release' }}
      python: ${{ matrix.python || 'ON' }}
      pybind11: ${{ matrix.pybind11 || 'ON' }}
      BUILD_SHARED_LIBS: ${{ matrix.BUILD_SHARED_LIBS || 'ON' }}
      IMATH_INSTALL_PKG_CONFIG: ${{ matrix.IMATH_INSTALL_PKG_CONFIG || 'ON' }}
      IMATH_INSTALL_SYM_LINK: ${{ matrix.IMATH_INSTALL_SYM_LINK || 'ON' }}
      BUILD_TESTING: ${{ matrix.BUILD_TESTING || 'ON' }}
      IMATH_TEST_PYTHON: ${{ matrix.IMATH_TEST_PYTHON || 'ON' }}
      IMATH_TEST_PYBIND11: ${{ matrix.IMATH_TEST_PYBIND11 || 'ON' }}
      namespace: ${{ matrix.namespace }}
      validate_install: ${{ matrix.validate_install || 'ON' }}
    strategy:
      matrix:
        include:

          - build: 1
            label: Release

          - build: 2
            label: Debug
            build-type: Debug

          - build: 3
            label: static
            BUILD_SHARED_LIBS: 'OFF'

          - build: 4
            label: pkgconfig=OFF, testing=OFF, python=OFF
            IMATH_INSTALL_PKG_CONFIG: 'OFF'
            IMATH_INSTALL_SYM_LINK: 'OFF'
            BUILD_TESTING: 'OFF'
            python: 'OFF'
            pybind11: 'OFF'
            cmake: 3.14.7
            cxx-standard: 14

          - build: 5
            label: custom namespace
            namespace: 'TEST_NAMESPACE'

          - build: 6
            label: clang
            cxx-compiler: clang++
            cc-compiler: clang

          - build: 7
            label: cmake 4
            cmake: 4.0.3

  macOS:
    name: 'macOS.${{ matrix.build}}: ${{ matrix.label }}'
    uses: ./.github/workflows/ci_steps.yml
    with:
      # Set values for the "inputs:" as defined in ci_steps.yml
      # Note the defaults provided here for the builds that don't specify
      # values.
      os: ${{ matrix.os || 'macos-15' }}
      build: ${{ matrix.build }}
      cxx-standard: ${{ matrix.cxx-standard || '14' }}
      build-type: ${{ matrix.build-type || 'Release' }}
      python: ${{ matrix.python || 'ON' }}
      pybind11: ${{ matrix.pybind11 || 'ON' }}
      BUILD_SHARED_LIBS: ${{ matrix.BUILD_SHARED_LIBS || 'ON' }}
      IMATH_INSTALL_PKG_CONFIG: ${{ matrix.IMATH_INSTALL_PKG_CONFIG || 'ON' }}
      IMATH_INSTALL_SYM_LINK: ${{ matrix.IMATH_INSTALL_SYM_LINK || 'ON' }}
      IMATH_BUILD_APPLE_FRAMEWORKS: ${{ matrix.IMATH_BUILD_APPLE_FRAMEWORKS || 'OFF' }}
      BUILD_TESTING: ${{ matrix.BUILD_TESTING || 'ON' }}
      IMATH_TEST_PYTHON: ${{ matrix.IMATH_TEST_PYTHON || 'ON' }}
      IMATH_TEST_PYBIND11: ${{ matrix.IMATH_TEST_PYBIND11 || 'ON' }}
      validate_install: ${{ matrix.validate_install || 'ON' }}
    strategy:
      matrix:
        include:

          - build: 1
            label: Release

          - build: 2
            label: Debug
            build-type: Debug

          - build: 3
            label: static
            BUILD_SHARED_LIBS: 'OFF'

          - build: 4
            label: pkgconfig=OFF, testing=OFF
            IMATH_INSTALL_PKG_CONFIG: 'OFF'
            IMATH_INSTALL_SYM_LINK: 'OFF'
            BUILD_TESTING: 'OFF'
            python: 'OFF'
            pybind11: 'OFF'
            cxx-standard: 14

          - build: 5
            label: macos-15-intel
            os: macos-15-intel

          - build: 6
            label: macos-14
            os: macos-14

          - build: 7
            label: Apple Frameworks
            IMATH_BUILD_APPLE_FRAMEWORKS: 'ON'
            BUILD_TESTING: 'OFF'
            python: 'OFF' # conan boost doesn't support iOS
            pybind11: 'OFF' # iOS doesn't support CPython

  windows:
    name: 'Windows.${{ matrix.build}}: ${{ matrix.label }}'
    uses: ./.github/workflows/ci_steps.yml
    with:
      # Set values for the "inputs:" as defined in ci_steps.yml
      # Note the defaults provided here for the builds that don't specify
      # values.
      os: ${{ matrix.os || 'windows-2022' }}
      build: ${{ matrix.build }}
      cxx-standard: ${{ matrix.cxx-standard || '14' }}
      cxx-compiler: ${{ matrix.cxx-compiler }}
      cc-compiler: ${{ matrix.cc-compiler }}
      build-type: ${{ matrix.build-type || 'Release' }}
      python: ${{ matrix.python || 'ON' }}
      pybind11: ${{ matrix.pybind11 || 'ON' }}
      BUILD_SHARED_LIBS: ${{ matrix.BUILD_SHARED_LIBS || 'ON' }}
      IMATH_INSTALL_PKG_CONFIG: ${{ matrix.IMATH_INSTALL_PKG_CONFIG || 'ON' }}
      IMATH_INSTALL_SYM_LINK: ${{ matrix.IMATH_INSTALL_SYM_LINK || 'ON' }}
      BUILD_TESTING: ${{ matrix.BUILD_TESTING || 'ON' }}
      IMATH_TEST_PYTHON: ${{ matrix.IMATH_TEST_PYTHON || 'ON' }}
      IMATH_TEST_PYBIND11: ${{ matrix.IMATH_TEST_PYBIND11 || 'ON' }}
      msystem: ${{ matrix.msystem }}
      validate_install: ${{ matrix.validate_install || 'ON' }}
    strategy:
      matrix:
        include:
          - build: 1
            label: Release
            IMATH_TEST_PYTHON: 'OFF' # TODO: "import imath" fails on Windows, please help find why!
            IMATH_TEST_PYBIND11: 'OFF' # TODO: "import pybindimath" fails on Windows, please help find why!

          - build: 2
            label: Debug
            build-type: Debug
            python: 'OFF' # TODO: conan won't build debug boost.python on Windows, please help find why!
            IMATH_TEST_PYBIND11: 'OFF' # TODO: "import pybindimath" fails on Windows, please help find why!

          - build: 3
            label: static
            BUILD_SHARED_LIBS: 'OFF'
            IMATH_TEST_PYTHON: 'OFF' # TODO: "import imath" fails on Windows, please help find why!
            IMATH_TEST_PYBIND11: 'OFF' # TODO: "import pybindimath" fails on Windows, please help find why!

          - build: 4
            # test with everything turned off
            label: pkgconfig=OFF, testing=OFF
            IMATH_INSTALL_PKG_CONFIG: 'OFF'
            IMATH_INSTALL_SYM_LINK: 'OFF'
            BUILD_TESTING: 'OFF'
            python: 'OFF'
            pybind11: 'OFF'
            cxx-standard: 14

          - build: 5
            label: vfx2023
            os: windows-2022
            IMATH_TEST_PYTHON: 'OFF' # TODO: "import imath" fails on Windows, please help find why!
            IMATH_TEST_PYBIND11: 'OFF' # TODO: "import pybindimath" fails on Windows, please help find why!

          - build: 6
            label: msys2-mingw32
            msystem: MINGW32
            BUILD_TESTING: 'OFF' # TODO: Imath.testMatrix fails, please help find why!
            python: 'OFF' # TODO: conan won't build boost.python w/msys2, please help find why!
            IMATH_TEST_PYBIND11: 'OFF' # TODO: "import pybindimath" fails on Windows, please help find why!

          - build: 7
            label: msys2-mingw32, static
            msystem: MINGW32
            BUILD_SHARED_LIBS: 'OFF'
            BUILD_TESTING: 'OFF' # TODO: Imath.testMatrix fails, please help find why!
            python: 'OFF' # TODO: conan won't build boost.python w/msys2, please help find why!
            IMATH_TEST_PYBIND11: 'OFF' # TODO: "import pybindimath" fails on Windows, please help find why!

          - build: 8
            label: msys2-ucrt64
            msystem: UCRT64
            python: 'OFF' # TODO: conan won't build boost.python w/msys2, please help find why!
            IMATH_TEST_PYBIND11: 'OFF' # TODO: "import pybindimath" fails on Windows, please help find why!

          - build: 9
            label: msys2-ucrt64, static
            msystem: UCRT64
            BUILD_SHARED_LIBS: 'OFF'
            python: 'OFF' # TODO: conan won't build boost.python w/msys2, please help find why!
            IMATH_TEST_PYBIND11: 'OFF' # TODO: "import pybindimath" fails on Windows, please help find why!
            
          - build: 11
            label: clang
            cxx-compiler: clang++
            cc-compiler: clang
            python: 'OFF'
            IMATH_TEST_PYBIND11: 'OFF' # TODO: "import pybindimath" fails on Windows, please help find why!
