Add check to CMakeList for check versions and path order on windows (#9390)

* chore: limit cmake version to 3.31 for win32

* chore: fix check for variable path order

* chore: fix check for pipeline

* chore: remove warn on CI enviroment

* chore: change cmake limit version from 3.32 to 4.0
This commit is contained in:
GiacomoGuaresi 2025-04-18 13:42:46 +02:00 committed by GitHub
parent addade1216
commit 7d2a12aa3c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,5 +1,50 @@
cmake_minimum_required(VERSION 3.13)
# Verify that your CMake version is exactly 3.31.x series or lower on windows
if(${CMAKE_VERSION} VERSION_LESS "3.13" OR ${CMAKE_VERSION} VERSION_GREATER_EQUAL "4.0")
message(FATAL_ERROR "Only CMake versions between 3.13.x and 3.31.x is supported. Detected version: ${CMAKE_VERSION}")
endif()
if (WIN32)
# Detect known CI environments
set(IS_CI FALSE)
if(DEFINED ENV{CI})
set(IS_CI TRUE)
elseif(DEFINED ENV{GITHUB_ACTIONS})
set(IS_CI TRUE)
elseif(DEFINED ENV{GITLAB_CI})
set(IS_CI TRUE)
elseif(DEFINED ENV{TF_BUILD})
set(IS_CI TRUE)
elseif(DEFINED ENV{BUILD_NUMBER}) # Jenkins
set(IS_CI TRUE)
endif()
# Detect common misconfiguration (Strawberry Perl in PATH before CMake)
# We use ENV to check the PATH order
string(REPLACE "\\" "/" ENV_PATH "$ENV{PATH}")
string(FIND "${ENV_PATH}" "Strawberry/c/bin" STRAWBERRY_POS)
string(FIND "${ENV_PATH}" "Program Files/CMake/bin" CMAKE_POS)
if (STRAWBERRY_POS GREATER -1 AND CMAKE_POS GREATER -1 AND STRAWBERRY_POS LESS CMAKE_POS)
set(_warning_text "
#############################################################
Detected Strawberry Perl's 'c/bin' appearing before CMake in PATH.
This is known to cause CMake to misbehave (e.g., missing modules).
Please adjust your PATH so that:
C:\\Program Files\\CMake\\bin
appears before:
C:\\Strawberry\\c\\bin
You can do this in Environment Variables settings.
#############################################################
")
if(NOT IS_CI)
message(FATAL_ERROR "${_warning_text}")
endif()
endif()
endif ()
if (APPLE)
# if CMAKE_OSX_DEPLOYMENT_TARGET is not set, set it to 11.3
if (NOT CMAKE_OSX_DEPLOYMENT_TARGET)