mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-01 19:30:13 -06:00
find_package: add test coverage for CMAKE_FIND_PACKAGE_RESOLVE_SYMLINKS
This commit is contained in:
@@ -188,6 +188,37 @@ find_package(ArchC 3.1 EXACT NAMES zot)
|
||||
find_package(ArchD 4.0 EXACT NAMES zot)
|
||||
unset(CMAKE_LIBRARY_ARCHITECTURE)
|
||||
|
||||
# Test find_package() with CMAKE_FIND_PACKAGE_RESOLVE_SYMLINKS enabled
|
||||
if(UNIX)
|
||||
# Create ./symlink pointing back here.
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink
|
||||
. "${CMAKE_CURRENT_SOURCE_DIR}/symlink")
|
||||
# Make find_package search through the symlink
|
||||
set(CMAKE_PREFIX_PATH "${CMAKE_CURRENT_SOURCE_DIR}/symlink")
|
||||
|
||||
# First, test the default behavior where symlinks are preserved.
|
||||
set(SetFoundResolved_DIR "")
|
||||
find_package(SetFoundResolved)
|
||||
# The result must preserve the /symlink/ path.
|
||||
set(SetFoundResolved_EXPECTED "${CMAKE_CURRENT_SOURCE_DIR}/symlink/cmake")
|
||||
if(NOT "${SetFoundResolved_DIR}" STREQUAL "${SetFoundResolved_EXPECTED}")
|
||||
message(SEND_ERROR "SetFoundResolved_DIR set by find_package() is set to \"${SetFoundResolved_DIR}\" (expected \"${SetFoundResolved_EXPECTED}\")")
|
||||
endif()
|
||||
|
||||
# Resolve symlinks when finding the package.
|
||||
set(CMAKE_FIND_PACKAGE_RESOLVE_SYMLINKS TRUE)
|
||||
set(SetFoundResolved_DIR "")
|
||||
find_package(SetFoundResolved)
|
||||
# ./symlink points back here so it should be gone when resolved.
|
||||
set(SetFoundResolved_EXPECTED "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
|
||||
if(NOT "${SetFoundResolved_DIR}" STREQUAL "${SetFoundResolved_EXPECTED}")
|
||||
message(SEND_ERROR "SetFoundResolved_DIR set by find_package() is set to \"${SetFoundResolved_DIR}\" (expected \"${SetFoundResolved_EXPECTED}\")")
|
||||
endif()
|
||||
# Cleanup.
|
||||
unset(CMAKE_FIND_PACKAGE_RESOLVE_SYMLINKS)
|
||||
file(REMOVE "${CMAKE_CURRENT_SOURCE_DIR}/symlink")
|
||||
endif()
|
||||
|
||||
# Test <PackageName>_DIR environment variable.
|
||||
# We erase the main prefix path to ensure the env var is used.
|
||||
set(CMAKE_PREFIX_PATH)
|
||||
|
||||
1
Tests/FindPackageTest/cmake/SetFoundResolvedConfig.cmake
Normal file
1
Tests/FindPackageTest/cmake/SetFoundResolvedConfig.cmake
Normal file
@@ -0,0 +1 @@
|
||||
set(SetFoundResolved_DIR "${CMAKE_CURRENT_LIST_DIR}")
|
||||
@@ -0,0 +1 @@
|
||||
set(Resolved_DIR "${CMAKE_CURRENT_LIST_DIR}")
|
||||
@@ -26,3 +26,6 @@ run_cmake(WrongVersionConfig)
|
||||
run_cmake(CMP0084-OLD)
|
||||
run_cmake(CMP0084-WARN)
|
||||
run_cmake(CMP0084-NEW)
|
||||
if(UNIX)
|
||||
run_cmake(SetFoundResolved)
|
||||
endif()
|
||||
|
||||
10
Tests/RunCMake/find_package/SetFoundResolved-stderr.txt
Normal file
10
Tests/RunCMake/find_package/SetFoundResolved-stderr.txt
Normal file
@@ -0,0 +1,10 @@
|
||||
CMake Warning at SetFoundResolved.cmake:10 \(message\):
|
||||
.*/Tests/RunCMake/find_package/symlink
|
||||
Call Stack \(most recent call first\):
|
||||
CMakeLists.txt:3 \(include\)
|
||||
|
||||
|
||||
CMake Warning at SetFoundResolved.cmake:15 \(message\):
|
||||
.*/Tests/RunCMake/find_package/PackageRoot
|
||||
Call Stack \(most recent call first\):
|
||||
CMakeLists.txt:3 \(include\)
|
||||
17
Tests/RunCMake/find_package/SetFoundResolved.cmake
Normal file
17
Tests/RunCMake/find_package/SetFoundResolved.cmake
Normal file
@@ -0,0 +1,17 @@
|
||||
# Create ./symlink pointing back here.
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink
|
||||
PackageRoot "${CMAKE_CURRENT_SOURCE_DIR}/symlink")
|
||||
|
||||
# Make find_package search through the symlink.
|
||||
set(CMAKE_PREFIX_PATH "${CMAKE_CURRENT_SOURCE_DIR}/symlink")
|
||||
|
||||
# Test preservation of symlinks.
|
||||
find_package(Resolved)
|
||||
message(WARNING "${Resolved_DIR}")
|
||||
|
||||
# Test resolving symlinks.
|
||||
set(CMAKE_FIND_PACKAGE_RESOLVE_SYMLINKS ON)
|
||||
find_package(Resolved)
|
||||
message(WARNING "${Resolved_DIR}")
|
||||
|
||||
file(REMOVE "${CMAKE_CURRENT_SOURCE_DIR}/symlink")
|
||||
Reference in New Issue
Block a user