1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-14 02:08:27 +08:00
Files
CMake/Tests/RunCMake/find_package/PackageRootRelative.cmake
Robert Maynard 87a661a916 find_package: Fix regression on <PackageName>_ROOT relative to CWD
In commit 9d44a77454 (find_*: Explicitly normalize found paths as they
exist on disk, 2024-10-17, v4.0.0-rc1~597^2~1), we removed path
normalization from the internal `cmSearchPath::AddPathInternal` helper.
Most call sites were updated to normalize input paths first, but search
paths derived from `<PackageName>_ROOT` CMake variables are no longer
normalized.  Instead we normalize the path to the file found after
searching.

When `find_package` "config" mode considers a candidate CMake package
configuration file, normalize its path before loading the adjacent
package version file so that the latter is loaded by absolute path.
Otherwise `cmMakefile::ReadDependentFile` interprets a relative path
with respect to the current source directory rather than the current
working directory.

Fixes: #27279
2025-10-02 15:30:13 -04:00

8 lines
348 B
CMake

cmake_policy(SET CMP0074 NEW)
set(Relative_ROOT root)
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/root/RelativeConfig.cmake" "")
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/root/RelativeConfigVersion.cmake" "set(PACKAGE_VERSION 1)")
find_package(Relative)
message(STATUS "Relative_ROOT='${Relative_ROOT}'")
message(STATUS "Relative_DIR='${Relative_DIR}'")