cmake: test CMake and issue error if using 3.22.1 / 3.22.2 from PyPI

Fixes: #43099

The CMake 3.22.1 / 3.22.2 PyPI version suffers a bug in the
`cmake_path(... PARENT_PATH)` implementation.

Therefore, when CMake version 3.22.1 / 3.22.2 is detected, test if the
CMake version is suffering from the bug, and in case the bug is present,
fail with an error regarding the issue.

The reason for failing, and not implementing work arounds is that Zephyr
already uses `cmake_path()` at two locations, and we cannot prevent
contributors from adding code which uses this function.

Secondly, Zephyr modules may also use `cmake_path()`, and thus be
affected by said bug.
It is impractical to implement work arounds at all possible locations
for something that is a CMake bug.

Therefore the safest solution is to test CMake itself, to check if the
version in use suffers said bug, and fail with a proper error message
if an affected CMake version is used.

See more here:
https://gitlab.kitware.com/cmake/cmake/-/issues/23187
https://github.com/scikit-build/cmake-python-distributions/issues/221

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
This commit is contained in:
Torsten Rasmussen 2022-02-24 12:21:11 +01:00 committed by Marti Bolivar
commit 8b199b0fbb

View file

@ -31,6 +31,21 @@ find_package(ZephyrBuildConfiguration
NO_CMAKE_SYSTEM_PACKAGE_REGISTRY NO_CMAKE_SYSTEM_PACKAGE_REGISTRY
) )
# Test and error-out if we are affected by the PyPI CMake 3.22.1 / 3.22.2 bug
if(${CMAKE_VERSION} VERSION_EQUAL 3.22.1 OR ${CMAKE_VERSION} VERSION_EQUAL 3.22.2)
# It seems only pip-installed builds are affected so we test to see if we are affected
cmake_path(GET ZEPHYR_BASE PARENT_PATH test_cmake_path)
if(ZEPHYR_BASE STREQUAL test_cmake_path)
message(FATAL_ERROR "The CMake version ${CMAKE_VERSION} installed suffers"
" the \n 'cmake_path(... PARENT_PATH)' bug, see: \n"
"https://gitlab.kitware.com/cmake/cmake/-/issues/23187\n"
"https://github.com/scikit-build/cmake-python-distributions/issues/221\n"
"Please install another CMake version or use a build of CMake that"
" does not come from PyPI."
)
endif()
endif()
# Prepare user cache # Prepare user cache
list(APPEND zephyr_cmake_modules python) list(APPEND zephyr_cmake_modules python)
list(APPEND zephyr_cmake_modules user_cache) list(APPEND zephyr_cmake_modules user_cache)