windowsopencvcmakegitlab-cigitlab-ci-runner

GitLab runner fails to build OpenCV unable to find contrib modules but locally same CMakeLists.txt manages to do that


I have set up a runner (shell executor) on a Windows server with a lot more power than my own computer. The runner has been successfully registered with an on-premise hosted latest GitLab instance. Both computers have CUDA 12.2 and cuDNN 8.9.5.30 for CUDA 12.2 in place (the cuDNN are copied in the directory of CUDA) incl. PATH and CUDA_PATH set accordingly.

My project consists of multiple dependencies which I don't want to build locally and would like to use CMake and/or Git to download and use. So I have split it into 2 repos - one for my application and one for the dependencies. My ultimate goal is to add automated download of artifacts from the repo with the dependencies in the CMake project of my main application.

One of the dependencies is OpenCV with GPU support. The structure of the Dependencies repo is following:

*
|
+-- REAMDE.md
|
+-- .gitmodules
|
+-- .gitignore
|
+-- .gitlab-ci.yml
|
+-- deps
     |
     +-- [submodule] opencv
     |
     +-- [submodule] opencv_contrib
     |
     +-- [submodules] other depenencies
     |
     +-- CMakeLists.txt

The .gitsubmodules looks like

[submodule "deps/opencv"]
    path = deps/opencv
    url = https://github.com/opencv/opencv.git
    branch="4.x"
[submodule "deps/opencv_contrib"]
    path = deps/opencv_contrib
    url = https://github.com/opencv/opencv_contrib.git
    branch="4.x"

The CMakeLists.txt is

cmake_minimum_required(VERSION 3.22)
project(Dependencies)

# Disable examples, tests and docs
set(BUILD_EXAMPLES OFF)
set(BUILD_TESTS OFF)
set(BUILD_DOCS OFF)
# Disable GUI
set(WITH_QT OFF)
set(WITH_GTK OFF)
set(WITH_WIN32UI OFF)
# Disable video
set(WITH_MSMF OFF)
set(WITH_FFMPEG OFF)
set(WITH_DSHOW OFF)
# Language support
set(BUILD_JAVA OFF)
set(BUILD_opencv_python2 OFF)
set(BUILD_opencv_python3 OFF)

if(BuildOpenCV_CPU_BASE)
    add_subdirectory(opencv)
elseif(BuildOpenCV_GPU)
    set(OPENCV_ENABLE_NONFREE OFF)
    set(WITH_CUDA ON)   # Currently using 11.8
    set(WITH_CUDNN ON)
    set(OPENCV_DNN_CUDA ON)
    set(CUDA_ARCH_BIN=6.1)
    set(WITH_NVCUVID OFF)
    set(WITH_NVCUVENC OFF)
    set(OPENCV_EXTRA_MODULES_PATH
        "${CMAKE_SOURCE_DIR}/opencv_contrib/modules/cudaarithm"
        "${CMAKE_SOURCE_DIR}/opencv_contrib/modules/cudabgsegm"
        "${CMAKE_SOURCE_DIR}/opencv_contrib/modules/cudacodec"
        "${CMAKE_SOURCE_DIR}/opencv_contrib/modules/cudafeatures2d"
        "${CMAKE_SOURCE_DIR}/opencv_contrib/modules/cudafilters"
        "${CMAKE_SOURCE_DIR}/opencv_contrib/modules/cudaimgproc"
        "${CMAKE_SOURCE_DIR}/opencv_contrib/modules/cudalegacy"
        "${CMAKE_SOURCE_DIR}/opencv_contrib/modules/cudaobjdetect"
        #"${CMAKE_SOURCE_DIR}/opencv_contrib/modules/cudaoptflow"
        "${CMAKE_SOURCE_DIR}/opencv_contrib/modules/cudastereo"
        "${CMAKE_SOURCE_DIR}/opencv_contrib/modules/cudawarping"
        "${CMAKE_SOURCE_DIR}/opencv_contrib/modules/cudev"
    )
    add_subdirectory(opencv)
endif()

while my .gitlab-ci.yml is

stages:
  - build

build-4.x-gpu-release:
  stage: build
  tags:
    - srv
  variables:
    GIT_SUBMODULE_STRATEGY: recursive
    GIT_SUBMODULE_PATHS: deps/*
  artifacts:
    paths:
      - build\bin\Release\*.dll
  script:
    - echo "build-4.x-gpu-release"
    - cd deps
    - cmake -Bbuild -G "Visual Studio 16 2019" -DBuildOpenCV_GPU=ON
    - cmake.exe --build build --target ALL_BUILD --config Release

On my local computer, when I repeat the steps seen in the CI job's script, I am able to configure the project and even compile it. On the server my runner reports (in the GitLab WebUI) that OpenCV GPU requires enabled cudev module from the contrib modules

CMake Error at opencv/modules/core/CMakeLists.txt:158 (message):
  CUDA: OpenCV requires enabled 'cudev' module from 'opencv_contrib'
  repository: https://github.com/opencv/opencv_contrib
-- Configuring incomplete, errors occurred!

I have also tried specifying the source directory using the -S parameter of cmake so that I would perhaps prevent some confusion with changing the directory in my CI job.

I can see in the logs that both cuDNN and CUDA are detected correctly:

Found CUDNN: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.2/lib/x64/cudnn.lib (found suitable version "8.9.5", minimum required is "7.5")
-- CUDA detected: 12.2

I can also see (through an extra debug message that prints out OPENCV_EXTRA_MODULES_PATH inside my own CMakeLists.txt that all modules I have selected are detected properly, in particular cudev can be found at

D:/GITLAB/builds/6LxqbndAy/5/gitlab-srv/user/srv/dependencies/deps/opencv_contrib/modules/cudev

where D:/GITLAB/build is the directory where the Windows runner (shell executor) is running all CI jobs.

Note that I have multiple other jobs from the same stage (e.g. DirectXTex, spdlog and imgui) that build without any issues.

The full output of the CI job can be seen below:

Running with gitlab-runner 17.2.1 (9882d9c7)
  on SZA-GIN002 6LxqbndAy, system ID: s_8ceec5130a1f
Preparing the "shell" executor 00:00
Using Shell (powershell) executor...
Preparing environment 00:00
Running on SZA-GIN002...
Getting source from Git repository 00:22
Fetching changes with git depth set to 20...
Reinitialized existing Git repository in D:/GITLAB/builds/6LxqbndAy/5/gitlab-srv/user/srv/dependencies/.git/
Checking out 83c3b28c as detached HEAD (ref is main)...
Removing artifacts/
Removing deps/build/
git-lfs/2.11.0 (GitHub; windows amd64; go 1.14.2; git 48b28d97)
Updating/initializing submodules recursively with git depth set to 20...
Synchronizing submodule url for 'deps/opencv'
Synchronizing submodule url for 'deps/opencv_contrib'
Entering 'deps/DirectXTex'
Entering 'deps/opencv'
Entering 'deps/opencv_contrib'
Entering 'deps/DirectXTex'
HEAD is now at 2f84f54 Add cubemap support for OpenEXR (#483)
Entering 'deps/opencv'
HEAD is now at 1acf722 Merge pull request #25970 from savuor:rv/hal_pyrdown
Entering 'deps/opencv_contrib'
HEAD is now at 2413f86 Merge pull request #3600 from chacha21:remap_relative
Updated submodules
Synchronizing submodule url for 'deps/opencv'
Synchronizing submodule url for 'deps/opencv_contrib'
Entering 'deps/DirectXTex'
Entering 'deps/opencv'
Entering 'deps/opencv_contrib'
git-lfs/2.11.0 (GitHub; windows amd64; go 1.14.2; git 48b28d97)
Entering 'deps/DirectXTex'
Entering 'deps/opencv'
Entering 'deps/opencv_contrib'
Downloading artifacts 00:04
Version:      17.2.1
Git revision: 9882d9c7
Git branch:   17-2-stable
GO version:   go1.22.5
Built:        2024-07-25T17:34:51+0000
OS/Arch:      windows/amd64
Downloading artifacts for build-spdlog-debug (7005794)...
Runtime platform                                    arch=amd64 os=windows pid=61248 revision=9882d9c7 version=17.2.1
Downloading artifacts from coordinator... ok        host=gitlab-srv.example.com id=7005794 responseStatus=200 OK token=glcbt-64
Downloading artifacts for build-DirectXTex-debug (7005795)...
Runtime platform                                    arch=amd64 os=windows pid=103904 revision=9882d9c7 version=17.2.1
Downloading artifacts from coordinator... ok        host=gitlab-srv.example.com id=7005795 responseStatus=200 OK token=glcbt-64
Downloading artifacts for build-imgui-debug (7005796)...
Runtime platform                                    arch=amd64 os=windows pid=18808 revision=9882d9c7 version=17.2.1
Downloading artifacts from coordinator... ok        host=gitlab-srv.example.com id=7005796 responseStatus=200 OK token=glcbt-64
Executing "step_script" stage of the job script 02:41
$ echo "build-4.x-gpu-release"
build-4.x-gpu-release
$ cd deps
$ cmake -Bbuild -G "Visual Studio 16 2019" -DBuildOpenCV_GPU=ON
-- Selecting Windows SDK version 10.0.17763.0 to target Windows 10.0.14393.
-- The C compiler identification is MSVC 19.20.27525.0
-- The CXX compiler identification is MSVC 19.20.27525.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.20.27508/bin/Hostx64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.20.27508/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
Modules paths: D:/GITLAB/builds/6LxqbndAy/5/gitlab-srv/user/srv/dependencies/deps/opencv_contrib/modules/cudaarithm;D:/GITLAB/builds/6LxqbndAy/5/gitlab-srv/user/srv/dependencies/deps/opencv_contrib/modules/cudabgsegm;D:/GITLAB/builds/6LxqbndAy/5/gitlab-srv/user/srv/dependencies/deps/opencv_contrib/modules/cudacodec;D:/GITLAB/builds/6LxqbndAy/5/gitlab-srv/user/srv/dependencies/deps/opencv_contrib/modules/cudafeatures2d;D:/GITLAB/builds/6LxqbndAy/5/gitlab-srv/user/srv/dependencies/deps/opencv_contrib/modules/cudafilters;D:/GITLAB/builds/6LxqbndAy/5/gitlab-srv/user/srv/dependencies/deps/opencv_contrib/modules/cudaimgproc;D:/GITLAB/builds/6LxqbndAy/5/gitlab-srv/user/srv/dependencies/deps/opencv_contrib/modules/cudalegacy;D:/GITLAB/builds/6LxqbndAy/5/gitlab-srv/user/srv/dependencies/deps/opencv_contrib/modules/cudaobjdetect;D:/GITLAB/builds/6LxqbndAy/5/gitlab-srv/user/srv/dependencies/deps/opencv_contrib/modules/cudastereo;D:/GITLAB/builds/6LxqbndAy/5/gitlab-srv/user/srv/dependencies/deps/opencv_contrib/modules/cudawarping;D:/GITLAB/builds/6LxqbndAy/5/gitlab-srv/user/srv/dependencies/deps/opencv_contrib/modules/cudev
-- 'Release' build type is used by default. Use CMAKE_BUILD_TYPE to specify build type (Release or Debug)
-- ocv_init_download: Unable to recognize git server of OpenCV source code. Using github.com to download 3rdparty components.
-- Detected processor: AMD64
-- Could NOT find PythonInterp (missing: PYTHON_EXECUTABLE) (Required is at least version "3.2")
-- Performing Test HAVE_CXX_FP:PRECISE
-- Performing Test HAVE_CXX_FP:PRECISE - Success
-- Performing Test HAVE_C_FP:PRECISE
-- Performing Test HAVE_C_FP:PRECISE - Success
-- Performing Test HAVE_CPU_SSE3_SUPPORT (check file: opencv/cmake/checks/cpu_sse3.cpp)
-- Performing Test HAVE_CPU_SSE3_SUPPORT - Success
-- Performing Test HAVE_CPU_SSSE3_SUPPORT (check file: opencv/cmake/checks/cpu_ssse3.cpp)
-- Performing Test HAVE_CPU_SSSE3_SUPPORT - Success
-- Performing Test HAVE_CPU_SSE4_1_SUPPORT (check file: opencv/cmake/checks/cpu_sse41.cpp)
-- Performing Test HAVE_CPU_SSE4_1_SUPPORT - Success
-- Performing Test HAVE_CPU_POPCNT_SUPPORT (check file: opencv/cmake/checks/cpu_popcnt.cpp)
-- Performing Test HAVE_CPU_POPCNT_SUPPORT - Success
-- Performing Test HAVE_CPU_SSE4_2_SUPPORT (check file: opencv/cmake/checks/cpu_sse42.cpp)
-- Performing Test HAVE_CPU_SSE4_2_SUPPORT - Success
-- Performing Test HAVE_CXX_ARCH:AVX (check file: opencv/cmake/checks/cpu_avx.cpp)
-- Performing Test HAVE_CXX_ARCH:AVX - Success
-- Performing Test HAVE_CXX_ARCH:AVX2 (check file: opencv/cmake/checks/cpu_avx2.cpp)
-- Performing Test HAVE_CXX_ARCH:AVX2 - Success
-- Performing Test HAVE_CXX_ARCH:AVX512 (check file: opencv/cmake/checks/cpu_avx512.cpp)
-- Performing Test HAVE_CXX_ARCH:AVX512 - Failed
-- AVX_512F is not supported by C++ compiler
-- AVX512_COMMON is not supported by C++ compiler
-- AVX512_SKX is not supported by C++ compiler
-- Dispatch optimization AVX512_SKX is not available, skipped
-- Performing Test HAVE_CPU_BASELINE_FLAGS
-- Performing Test HAVE_CPU_BASELINE_FLAGS - Success
-- Performing Test HAVE_CPU_DISPATCH_FLAGS_SSE4_1
-- Performing Test HAVE_CPU_DISPATCH_FLAGS_SSE4_1 - Success
-- Performing Test HAVE_CPU_DISPATCH_FLAGS_SSE4_2
-- Performing Test HAVE_CPU_DISPATCH_FLAGS_SSE4_2 - Success
-- Performing Test HAVE_CPU_DISPATCH_FLAGS_AVX
-- Performing Test HAVE_CPU_DISPATCH_FLAGS_AVX - Success
-- Performing Test HAVE_CPU_DISPATCH_FLAGS_FP16
-- Performing Test HAVE_CPU_DISPATCH_FLAGS_FP16 - Success
-- Performing Test HAVE_CPU_DISPATCH_FLAGS_AVX2
-- Performing Test HAVE_CPU_DISPATCH_FLAGS_AVX2 - Success
-- Performing Test HAVE_CXX_W15240
-- Performing Test HAVE_CXX_W15240 - Success
-- Performing Test HAVE_C_W15240
-- Performing Test HAVE_C_W15240 - Success
-- Looking for malloc.h
-- Looking for malloc.h - found
-- Looking for _aligned_malloc
-- Looking for _aligned_malloc - found
-- Looking for fseeko
-- Looking for fseeko - not found
-- Looking for sys/types.h
-- Looking for sys/types.h - found
-- Looking for stdint.h
-- Looking for stdint.h - found
-- Looking for stddef.h
-- Looking for stddef.h - found
-- Check size of off64_t
-- Check size of off64_t - failed
-- libjpeg-turbo: VERSION = 3.0.3, BUILD = opencv-4.10.0-dev-libjpeg-turbo
-- Check size of size_t
-- Check size of size_t - done
-- Check size of unsigned long
-- Check size of unsigned long - done
-- Looking for include file intrin.h
-- Looking for include file intrin.h - found
-- Looking for a ASM_NASM compiler
-- Looking for a ASM_NASM compiler - NOTFOUND
-- SIMD extensions disabled: could not find NASM compiler.  Performance will suffer.
-- Looking for assert.h
-- Looking for assert.h - found
-- Looking for fcntl.h
-- Looking for fcntl.h - found
-- Looking for inttypes.h
-- Looking for inttypes.h - found
-- Looking for io.h
-- Looking for io.h - found
-- Looking for limits.h
-- Looking for limits.h - found
-- Looking for memory.h
-- Looking for memory.h - found
-- Looking for search.h
-- Looking for search.h - found
-- Looking for string.h
-- Looking for string.h - found
-- Performing Test C_HAS_inline
-- Performing Test C_HAS_inline - Success
-- Check size of signed short
-- Check size of signed short - done
-- Check size of unsigned short
-- Check size of unsigned short - done
-- Check size of signed int
-- Check size of signed int - done
-- Check size of unsigned int
-- Check size of unsigned int - done
-- Check size of signed long
-- Check size of signed long - done
-- Check size of unsigned long
-- Check size of unsigned long - done
-- Check size of signed long long
-- Check size of signed long long - done
-- Check size of unsigned long long
-- Check size of unsigned long long - done
-- Check size of unsigned char *
-- Check size of unsigned char * - done
-- Check size of size_t
-- Check size of size_t - done
-- Check size of ptrdiff_t
-- Check size of ptrdiff_t - done
-- Looking for memmove
-- Looking for memmove - not found
-- Looking for setmode
-- Looking for setmode - found
-- Looking for strcasecmp
-- Looking for strcasecmp - not found
-- Looking for strchr
-- Looking for strchr - found
-- Looking for strrchr
-- Looking for strrchr - found
-- Looking for strstr
-- Looking for strstr - found
-- Looking for strtol
-- Looking for strtol - found
-- Looking for strtol
-- Looking for strtol - found
-- Looking for strtoull
-- Looking for strtoull - found
-- Looking for lfind
-- Looking for lfind - found
-- Could NOT find OpenJPEG (minimal suitable version: 2.0, recommended version >= 2.3.1). OpenJPEG will be built from sources
-- OpenJPEG: VERSION = 2.5.0, BUILD = opencv-4.10.0-dev-openjp2-2.5.0
-- Looking for stdlib.h
-- Looking for stdlib.h - found
-- Looking for stdio.h
-- Looking for stdio.h - found
-- Looking for math.h
-- Looking for math.h - found
-- Looking for float.h
-- Looking for float.h - found
-- Looking for time.h
-- Looking for time.h - found
-- Looking for stdarg.h
-- Looking for stdarg.h - found
-- Looking for ctype.h
-- Looking for ctype.h - found
-- Looking for stdint.h
-- Looking for stdint.h - found
-- Looking for inttypes.h
-- Looking for inttypes.h - found
-- Looking for strings.h
-- Looking for strings.h - not found
-- Looking for sys/stat.h
-- Looking for sys/stat.h - found
-- Looking for unistd.h
-- Looking for unistd.h - not found
-- Looking for include file malloc.h
-- Looking for include file malloc.h - found
-- Looking for _aligned_malloc
-- Looking for _aligned_malloc - found
-- Looking for posix_memalign
-- Looking for posix_memalign - not found
-- Looking for memalign
-- Looking for memalign - not found
-- OpenJPEG libraries will be built from sources: libopenjp2 (version "2.5.0")
-- IPPICV: Downloading ippicv_2021.12.0_win_intel64_20240425_general.zip from https://raw.githubusercontent.com/opencv/opencv_3rdparty/7f55c0c26be418d494615afca15218566775c725/ippicv/ippicv_2021.12.0_win_intel64_20240425_general.zip
-- found Intel IPP (ICV version): 2021.12.0 [2021.12.0]
-- at: D:/GITLAB/builds/6LxqbndAy/5/gitlab-srv/user/srv/dependencies/deps/build/opencv/3rdparty/ippicv/ippicv_win/icv
-- found Intel IPP Integration Wrappers sources: 2021.12.0
-- at: D:/GITLAB/builds/6LxqbndAy/5/gitlab-srv/user/srv/dependencies/deps/build/opencv/3rdparty/ippicv/ippicv_win/iw
-- Found CUDNN: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.2/lib/x64/cudnn.lib (found suitable version "8.9.5", minimum required is "7.5")
-- CUDA detected: 12.2
-- CUDA: NVCC target flags -gencode;arch=compute_50,code=sm_50;-gencode;arch=compute_52,code=sm_52;-gencode;arch=compute_60,code=sm_60;-gencode;arch=compute_61,code=sm_61;-gencode;arch=compute_70,code=sm_70;-gencode;arch=compute_75,code=sm_75;-gencode;arch=compute_80,code=sm_80;-gencode;arch=compute_86,code=sm_86;-gencode;arch=compute_89,code=sm_89;-gencode;arch=compute_90,code=sm_90;-D_FORCE_INLINES;-gencode;arch=compute_90,code=compute_90
-- CUDA: MSVS generator is detected. Disabling CMake re-run checks (CMAKE_SUPPRESS_REGENERATION=ON). You need to run CMake manually if updates are required.
-- Could not find OpenBLAS include. Turning OpenBLAS_FOUND off
-- Could not find OpenBLAS lib. Turning OpenBLAS_FOUND off
-- Looking for sgemm_
-- Looking for sgemm_ - not found
-- Found Threads: TRUE
-- Could NOT find BLAS (missing: BLAS_LIBRARIES) 
-- Could NOT find LAPACK (missing: LAPACK_LIBRARIES) 
    Reason given by package: LAPACK could not be found because dependency BLAS could not be found.
-- No support for DirectML (d3d12, dxcore, directml libs are required)
-- VTK is not found. Please set -DVTK_DIR in CMake to VTK build directory, or to VTK install subdirectory with VTKConfig.cmake file
-- ADE: Downloading v0.1.2d.zip from https://github.com/opencv/ade/archive/v0.1.2d.zip
-- Looking for mfapi.h
-- Looking for mfapi.h - found
-- Looking for vidcap.h
-- Looking for vidcap.h - found
-- Allocator metrics storage type: 'long long'
CMake Error at opencv/modules/core/CMakeLists.txt:158 (message):
  CUDA: OpenCV requires enabled 'cudev' module from 'opencv_contrib'
  repository: https://github.com/opencv/opencv_contrib
-- Configuring incomplete, errors occurred!

Solution

  • After several tries I decided out of nowhere to change the order of the modules listed in OPENCV_EXTRA_MODULES_PATH.

    I put <OPENCV_CONTRIB_ROOT_DIR>/modules/cudev at the beginning of OPENCV_EXTRA_MODULES_PATH:

    set(OPENCV_EXTRA_MODULES_PATH
            "${DEPS_ROOT_DIR}/opencv_contrib/modules/cudev"
            "${DEPS_ROOT_DIR}/opencv_contrib/modules/cudaarithm"
            "${DEPS_ROOT_DIR}/opencv_contrib/modules/cudabgsegm"
            "${DEPS_ROOT_DIR}/opencv_contrib/modules/cudacodec"
            "${DEPS_ROOT_DIR}/opencv_contrib/modules/cudafeatures2d"
            "${DEPS_ROOT_DIR}/opencv_contrib/modules/cudafilters"
            "${DEPS_ROOT_DIR}/opencv_contrib/modules/cudaimgproc"
            "${DEPS_ROOT_DIR}/opencv_contrib/modules/cudalegacy"
            "${DEPS_ROOT_DIR}/opencv_contrib/modules/cudaobjdetect"
            #"${DEPS_ROOT_DIR}/opencv_contrib/modules/cudaoptflow"
            "${DEPS_ROOT_DIR}/opencv_contrib/modules/cudastereo"
            "${DEPS_ROOT_DIR}/opencv_contrib/modules/cudawarping"
        )
    

    and it worked...locally. When I committed my changes and triggered the remote CI pipeline though I still got the same error. Thanks to the comment by Christoph Rackwitz in the comment section below this answer stating that order should not matter I decided to dig deeper.

    After removing my build directory and ran the configuration step to recreate it the same error appeared locally too.

    The way I solved it was to run the configuration step twice. Why that works I don't know.

    This cause the CI job to fail. In order to prevent that I split it into two - one for the configuration step and one for the build one. I then save the STDERR message from the configuration in a variable (refer to this post) that I can output without the STDERR being caught by the CI executor.

    !!!IMPORTANT!!! When CMake configuration step fails, this will lead to an failure of the whole CI job due to the emitted STDERR. In order to prevent that I am invoking cmake.exe using Start-Process in order to store the process' exit code. This code can then be checked and if not 0, the configuration step is re-run. Initially I tried re-routing the output of the CMake call's STDERR into a variable but this lead to an infinite loop (until CI job times out) since the CI executor expects an "exit" event (0 or error). Due to my lack of knowledge I was unable to make it work with try..catch since it does not really catch STDERR the way I thought it does.

    .config:
      variables:
        DepName: ""
        DepsRoot: ""
        DepCmakeArg: -DBuildDEFAULT=ON
      script:
        - !reference [.rename-main-commit-ref, script]
        - |
          # Split the string into a list of arguments
          $DepCmakeArg = @($DepCmakeArg.Split(" "))
          $process = Start-Process cmake.exe -windowstyle Hidden -ArgumentList "-Bbuild -G ""Visual Studio 16 2019"" -S. -A x64 -DCMAKE_BUILD_TYPE=""$($CI_COMMIT_REF_NAME)"" -DCMAKE_CONFIGURATION_TYPES=""$($CI_COMMIT_REF_NAME)"" $DepCmakeArg" -PassThru -Wait
          if ($process.ExitCode -ne 0) {
             # Currently only required for OpenCV
             echo "Initial attempt for configuration step with CMake has failed. Attempting one last time"
             cmake -Bbuild -G "Visual Studio 16 2019" -S. -A x64 -DCMAKE_BUILD_TYPE="$CI_COMMIT_REF_NAME" -DCMAKE_CONFIGURATION_TYPES="$($CI_COMMIT_REF_NAME)" $DepCmakeArg
           }
    
    .build:
      script:
        - !reference [.rename-main-commit-ref, script]
        - |
          cmake --build build --target ALL_BUILD --config "$CI_COMMIT_REF_NAME"
    .build-opencv-gpu:
      stage: build
      variables:
        DepName: opencv
        # Specifying CMAKE_INSTALL_PREFIX makes sure that the generated artifacts are referencing relatively the installation dir
        # In case of OpenCV if not used and even if the files are properly copied, the ".cmake" config files inside the installed
        # lib dir will reference <opencv-install-dir>/<arch>/<compiler>
        DepCmakeArg: -DBuildOpenCV_GPU=ON -DCMAKE_INSTALL_PREFIX="./install/"
        ArtifactRoot: !reference [.artifact-setup, variables, ArtifactRoot]
        ArtifactNoCreateDirs: true
        GIT_SUBMODULE_STRATEGY: recursive
        GIT_SUBMODULE_PATHS: deps/opencv deps/opencv_contrib
      artifacts:
        paths:
          - ${CI_PROJECT_DIR}/artifacts
      script:
        - cd deps
        - echo "Configuring and building dependency"
        # For some reason when the contribution modules are enabled we need to run the configuration step twice
        - !reference [.config, script]
        - !reference [.config, script]
        - !reference [.build, script]
        - ...