trigger:
  paths:
    exclude:
    - doc
    - README.md
    - CHANGES.md
    - CONTRIBUTING.md

pr:
  paths:
    exclude:
    - doc
    - README.md
    - CHANGES.md
    - CONTRIBUTING.md

resources:
  containers:
    - container: winx86
      image: pointcloudlibrary/env:winx86
    - container: winx64
      image: pointcloudlibrary/env:winx64
    - container: env1804
      image: pointcloudlibrary/env:18.04
    - container: env2004
      image: pointcloudlibrary/env:20.04
    - container: env2204
      image: pointcloudlibrary/env:22.04

stages:
  - stage: formatting
    displayName: Formatting
    jobs:
      - template: formatting.yaml

  - stage: build_gcc
    displayName: Build GCC
    dependsOn: formatting
    jobs:
      - job: ubuntu
        displayName: Ubuntu
        pool:
          vmImage: 'Ubuntu 20.04'
        strategy:
          matrix:
            18.04 GCC:  # oldest LTS
              CONTAINER: env1804
              CC: gcc
              CXX: g++
              BUILD_GPU: ON
              CMAKE_ARGS: '-DPCL_WARNINGS_ARE_ERRORS=ON'
            22.04 GCC:  # latest Ubuntu
              CONTAINER: env2204
              CC: gcc
              CXX: g++
              BUILD_GPU: OFF # There are currently incompatibilities between GCC 11.2 and CUDA 11.5
        container: $[ variables['CONTAINER'] ]
        timeoutInMinutes: 0
        variables:
          BUILD_DIR: '$(Agent.BuildDirectory)/build'
          CMAKE_CXX_FLAGS: '-Wall -Wextra -Wnoexcept-type'
          DISPLAY: :99.0 # Checked for in CMake
        steps:
          - template: build/ubuntu.yaml

  - stage: build_clang
    displayName: Build Clang
    dependsOn: formatting
    jobs:
      - job: osx
        displayName: macOS
        pool:
          vmImage: '$(VMIMAGE)'
        strategy:
          matrix:
            Big Sur 11:
              VMIMAGE: 'macOS-11'
              OSX_VERSION: '11'
            Monterey 12:
              VMIMAGE: 'macOS-12'
              OSX_VERSION: '12'
        timeoutInMinutes: 0
        variables:
          BUILD_DIR: '$(Agent.WorkFolder)/build'
          GOOGLE_TEST_DIR: '$(Agent.WorkFolder)/googletest'
          CMAKE_CXX_FLAGS: '-Wall -Wextra -Wabi -Werror -Wno-error=deprecated-declarations'
        steps:
          - template: build/macos.yaml
      - job: ubuntu
        displayName: Ubuntu
        # Placement of Ubuntu Clang job after macOS ensures an extra parallel job doesn't need to be created.
        # Total time per run remains same since macOS is quicker so it finishes earlier, and remaining time is used by this job
        # Therefore, number of parallel jobs and total run time of entire pipeline remains unchanged even after addition of this job
        # The version of Ubuntu is chosen to cover more versions than covered by GCC based CI
        dependsOn: osx
        condition: succeededOrFailed()
        pool:
          vmImage: 'Ubuntu 20.04'
        strategy:
          matrix:
            20.04 Clang:
              CONTAINER: env2004
              CC: clang
              CXX: clang++
              BUILD_GPU: ON
              CMAKE_ARGS: ''
        container: $[ variables['CONTAINER'] ]
        timeoutInMinutes: 0
        variables:
          BUILD_DIR: '$(Agent.BuildDirectory)/build'
          CMAKE_CXX_FLAGS: '-Wall -Wextra'
          DISPLAY: :99.0 # Checked for in CMake
        steps:
          - template: build/ubuntu.yaml
      - job: ubuntu_indices
        displayName: Ubuntu Indices
        # Test 64 bit & unsigned indices
        dependsOn: osx
        condition: succeededOrFailed()
        pool:
          vmImage: 'Ubuntu 20.04'
        strategy:
          matrix:
            20.04 Clang:
              CONTAINER: env2004
              CC: clang
              CXX: clang++
              INDEX_SIGNED: OFF
              INDEX_SIZE: 64
              CMAKE_ARGS: ''
        container: $[ variables['CONTAINER'] ]
        timeoutInMinutes: 0
        variables:
          BUILD_DIR: '$(Agent.BuildDirectory)/build'
          CMAKE_CXX_FLAGS: '-Wall -Wextra'
        steps:
          - template: build/ubuntu_indices.yaml

  - stage: build_msvc
    displayName: Build MSVC
    dependsOn: formatting
    jobs:
      - job: Windows
        displayName: Windows Build
        pool:
          vmImage: 'windows-2019'
        strategy:
          matrix:
            x86:
              CONTAINER: winx86
              PLATFORM: 'x86'
              ARCHITECTURE: 'x86'
              GENERATOR: '"Visual Studio 16 2019" -A Win32'
            x64:
              CONTAINER: winx64
              PLATFORM: 'x64'
              ARCHITECTURE: 'x86_amd64'
              GENERATOR: '"Visual Studio 16 2019" -A x64'
        container: $[ variables['CONTAINER'] ]
        timeoutInMinutes: 0
        variables:
          BUILD_DIR: 'c:\build'
          CONFIGURATION: 'Release'
          VCPKG_ROOT: 'c:\vcpkg'
        steps:
          - template: build/windows.yaml
