find_package: add test coverage for CMAKE_FIND_PACKAGE_RESOLVE_SYMLINKS

This commit is contained in:
David Aguilar
2019-01-15 12:12:32 -08:00
committed by Brad King
parent a5e948a36f
commit b773e58099
6 changed files with 63 additions and 0 deletions

View File

@@ -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)

View File

@@ -0,0 +1 @@
set(SetFoundResolved_DIR "${CMAKE_CURRENT_LIST_DIR}")

View File

@@ -0,0 +1 @@
set(Resolved_DIR "${CMAKE_CURRENT_LIST_DIR}")

View File

@@ -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()

View 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\)

View 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")