diff options
author | David Aguilar <davvid@gmail.com> | 2019-01-15 20:12:32 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2019-01-16 14:59:46 (GMT) |
commit | b773e58099b2fc8ebdf8319172fb018d0139396d (patch) | |
tree | 1805666c4f186e22becc8ac40284828cfc2cd6ca /Tests/FindPackageTest | |
parent | a5e948a36f5d1c1cf6a0ea34b04bbc4b6058e7d9 (diff) | |
download | CMake-b773e58099b2fc8ebdf8319172fb018d0139396d.zip CMake-b773e58099b2fc8ebdf8319172fb018d0139396d.tar.gz CMake-b773e58099b2fc8ebdf8319172fb018d0139396d.tar.bz2 |
find_package: add test coverage for CMAKE_FIND_PACKAGE_RESOLVE_SYMLINKS
Diffstat (limited to 'Tests/FindPackageTest')
-rw-r--r-- | Tests/FindPackageTest/CMakeLists.txt | 31 | ||||
-rw-r--r-- | Tests/FindPackageTest/cmake/SetFoundResolvedConfig.cmake | 1 |
2 files changed, 32 insertions, 0 deletions
diff --git a/Tests/FindPackageTest/CMakeLists.txt b/Tests/FindPackageTest/CMakeLists.txt index 6a80df5..f8b36c5 100644 --- a/Tests/FindPackageTest/CMakeLists.txt +++ b/Tests/FindPackageTest/CMakeLists.txt @@ -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) diff --git a/Tests/FindPackageTest/cmake/SetFoundResolvedConfig.cmake b/Tests/FindPackageTest/cmake/SetFoundResolvedConfig.cmake new file mode 100644 index 0000000..b2cf87c --- /dev/null +++ b/Tests/FindPackageTest/cmake/SetFoundResolvedConfig.cmake @@ -0,0 +1 @@ +set(SetFoundResolved_DIR "${CMAKE_CURRENT_LIST_DIR}") |