diff options
author | Craig Scott <craig.scott@crascit.com> | 2024-09-17 22:45:01 (GMT) |
---|---|---|
committer | Craig Scott <craig.scott@crascit.com> | 2024-09-19 10:31:47 (GMT) |
commit | 6a1fac14505619dfea26ca6a3020eb0b6b409557 (patch) | |
tree | 52fddb6d738997dfef88c4172f15d9e1206ee031 /Tests/RunCMake | |
parent | 2184fcfb006691a6ecf79762b4ce3c6b93266ab6 (diff) | |
download | CMake-6a1fac14505619dfea26ca6a3020eb0b6b409557.zip CMake-6a1fac14505619dfea26ca6a3020eb0b6b409557.tar.gz CMake-6a1fac14505619dfea26ca6a3020eb0b6b409557.tar.bz2 |
install: Normalize DESTINATION paths
The file generated by install(EXPORT) computes _IMPORT_PREFIX
in a way that assumes a normalized path. If the DESTINATION
contains any ../ components, the computed _IMPORT_PREFIX
would be wrong. Force the DESTINATION path to be normalized,
subject to the new CMP0176 policy.
Also normalize all other DESTINATION paths for consistency,
except for INCLUDES DESTINATION, which is not strictly a
destination but rather a search path to add.
Fixes: #26252
Diffstat (limited to 'Tests/RunCMake')
-rw-r--r-- | Tests/RunCMake/install/CMP0177-NEW-all-check.cmake | 36 | ||||
-rw-r--r-- | Tests/RunCMake/install/CMP0177-NEW-verify.cmake | 2 | ||||
-rw-r--r-- | Tests/RunCMake/install/CMP0177-NEW.cmake | 2 | ||||
-rw-r--r-- | Tests/RunCMake/install/CMP0177-OLD-verify-result.txt | 1 | ||||
-rw-r--r-- | Tests/RunCMake/install/CMP0177-OLD-verify-stderr.txt | 13 | ||||
-rw-r--r-- | Tests/RunCMake/install/CMP0177-OLD-verify.cmake | 2 | ||||
-rw-r--r-- | Tests/RunCMake/install/CMP0177-OLD.cmake | 2 | ||||
-rw-r--r-- | Tests/RunCMake/install/CMP0177-WARN-stderr.txt | 35 | ||||
-rw-r--r-- | Tests/RunCMake/install/CMP0177-WARN-verify-result.txt | 1 | ||||
-rw-r--r-- | Tests/RunCMake/install/CMP0177-WARN-verify-stderr.txt | 13 | ||||
-rw-r--r-- | Tests/RunCMake/install/CMP0177-WARN-verify.cmake | 2 | ||||
-rw-r--r-- | Tests/RunCMake/install/CMP0177-WARN.cmake | 1 | ||||
-rw-r--r-- | Tests/RunCMake/install/CMP0177.cmake | 29 | ||||
-rw-r--r-- | Tests/RunCMake/install/RunCMakeTest.cmake | 6 |
14 files changed, 145 insertions, 0 deletions
diff --git a/Tests/RunCMake/install/CMP0177-NEW-all-check.cmake b/Tests/RunCMake/install/CMP0177-NEW-all-check.cmake new file mode 100644 index 0000000..3524b6d --- /dev/null +++ b/Tests/RunCMake/install/CMP0177-NEW-all-check.cmake @@ -0,0 +1,36 @@ +set(installBase ${RunCMake_TEST_BINARY_DIR}/root-all) + +foreach(i RANGE 1 5) + set(subdir shouldNotRemain${i}) + if(IS_DIRECTORY ${installBase}/${subdir}) + set(RunCMake_TEST_FAILED "Check failed.") + string(APPEND RunCMake_TEST_FAILURE_MESSAGE + "\nUnexpectedly created install path that should have disappeared with " + "normalization:\n" + " ${installBase}/${subdir}" + ) + endif() +endforeach() + +file(GLOB perConfigFiles ${installBase}/lib/cmake/pkg/pkg-config-*.cmake) +foreach(file IN LISTS perConfigFiles ITEMS ${installBase}/lib/cmake/pkg/pkg-config.cmake) + file(STRINGS ${file} matches REGEX shouldNotRemain) + if(NOT matches STREQUAL "") + set(RunCMake_TEST_FAILED "Check failed.") + string(APPEND RunCMake_TEST_FAILURE_MESSAGE + "\nNon-normalized path found in ${file}:" + ) + foreach(match IN LISTS matches) + string(APPEND RunCMake_TEST_FAILURE_MESSAGE "\n ${match}") + endforeach() + endif() +endforeach() + +if(NOT EXISTS "${installBase}/dirs/dir/empty.txt") + set(RunCMake_TEST_FAILED "Check failed.") + string(APPEND RunCMake_TEST_FAILURE_MESSAGE + "\nNon-normalized DIRECTORY destination not handled correctly. " + "Expected to find the following file, but it was missing:\n" + " ${installBase}/dirs/dir/empty.txt" + ) +endif() diff --git a/Tests/RunCMake/install/CMP0177-NEW-verify.cmake b/Tests/RunCMake/install/CMP0177-NEW-verify.cmake new file mode 100644 index 0000000..7b8b2dc --- /dev/null +++ b/Tests/RunCMake/install/CMP0177-NEW-verify.cmake @@ -0,0 +1,2 @@ +enable_language(C) +find_package(pkg REQUIRED) diff --git a/Tests/RunCMake/install/CMP0177-NEW.cmake b/Tests/RunCMake/install/CMP0177-NEW.cmake new file mode 100644 index 0000000..698d9ce --- /dev/null +++ b/Tests/RunCMake/install/CMP0177-NEW.cmake @@ -0,0 +1,2 @@ +cmake_policy(SET CMP0177 NEW) +include(${CMAKE_CURRENT_LIST_DIR}/CMP0177.cmake) diff --git a/Tests/RunCMake/install/CMP0177-OLD-verify-result.txt b/Tests/RunCMake/install/CMP0177-OLD-verify-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/install/CMP0177-OLD-verify-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/install/CMP0177-OLD-verify-stderr.txt b/Tests/RunCMake/install/CMP0177-OLD-verify-stderr.txt new file mode 100644 index 0000000..366660b --- /dev/null +++ b/Tests/RunCMake/install/CMP0177-OLD-verify-stderr.txt @@ -0,0 +1,13 @@ +CMake Error at [^ +]*CMP0177-OLD-build/root-all/lib/cmake/pkg/pkg-config\.cmake:[0-9]+ \(message\): + The imported target "foo1" references the file ++ ".*/shouldNotRemain1/\.\./lib/(libfoo1\.a|foo1\.l(ib)?)" ++ but this file does not exist\. Possible reasons include: ++ \* The file was deleted, renamed, or moved to another location\. ++ \* An install or uninstall procedure did not complete successfully\. ++ \* The installation package was faulty and contained ++ ".*/Tests/RunCMake/install/CMP0177-OLD-build/root-all/lib/cmake/pkg/pkg-config\.cmake" ++ but not all the files it references\. ++Call Stack \(most recent call first\): + CMP0177-OLD-verify\.cmake:2 \(find_package\) + CMakeLists\.txt:3 \(include\) diff --git a/Tests/RunCMake/install/CMP0177-OLD-verify.cmake b/Tests/RunCMake/install/CMP0177-OLD-verify.cmake new file mode 100644 index 0000000..7b8b2dc --- /dev/null +++ b/Tests/RunCMake/install/CMP0177-OLD-verify.cmake @@ -0,0 +1,2 @@ +enable_language(C) +find_package(pkg REQUIRED) diff --git a/Tests/RunCMake/install/CMP0177-OLD.cmake b/Tests/RunCMake/install/CMP0177-OLD.cmake new file mode 100644 index 0000000..6389983 --- /dev/null +++ b/Tests/RunCMake/install/CMP0177-OLD.cmake @@ -0,0 +1,2 @@ +cmake_policy(SET CMP0177 OLD) +include(${CMAKE_CURRENT_LIST_DIR}/CMP0177.cmake) diff --git a/Tests/RunCMake/install/CMP0177-WARN-stderr.txt b/Tests/RunCMake/install/CMP0177-WARN-stderr.txt new file mode 100644 index 0000000..a7d8b2e --- /dev/null +++ b/Tests/RunCMake/install/CMP0177-WARN-stderr.txt @@ -0,0 +1,35 @@ +CMake Warning \(dev\) at CMP0177\.cmake:[0-9]+ \(install\): + Policy CMP0177 is not set: install\(\) DESTINATION paths are normalized\. Run + "cmake --help-policy CMP0177" for policy details\. Use the cmake_policy + command to set the policy and suppress this warning\. +Call Stack \(most recent call first\): + CMP0177-WARN\.cmake:1 \(include\) + CMakeLists\.txt:3 \(include\) +This warning is for project developers\. Use -Wno-dev to suppress it\. + +CMake Warning \(dev\) at CMP0177\.cmake:[0-9]+ \(install\): + Policy CMP0177 is not set: install\(\) DESTINATION paths are normalized\. Run + "cmake --help-policy CMP0177" for policy details\. Use the cmake_policy + command to set the policy and suppress this warning\. +Call Stack \(most recent call first\): + CMP0177-WARN\.cmake:1 \(include\) + CMakeLists\.txt:3 \(include\) +This warning is for project developers\. Use -Wno-dev to suppress it\. + +CMake Warning \(dev\) at CMP0177\.cmake:[0-9]+ \(install\): + Policy CMP0177 is not set: install\(\) DESTINATION paths are normalized\. Run + "cmake --help-policy CMP0177" for policy details\. Use the cmake_policy + command to set the policy and suppress this warning\. +Call Stack \(most recent call first\): + CMP0177-WARN\.cmake:1 \(include\) + CMakeLists\.txt:3 \(include\) +This warning is for project developers\. Use -Wno-dev to suppress it\. + +CMake Warning \(dev\) at CMP0177\.cmake:[0-9]+ \(install\): + Policy CMP0177 is not set: install\(\) DESTINATION paths are normalized\. Run + "cmake --help-policy CMP0177" for policy details\. Use the cmake_policy + command to set the policy and suppress this warning\. +Call Stack \(most recent call first\): + CMP0177-WARN\.cmake:1 \(include\) + CMakeLists\.txt:3 \(include\) +This warning is for project developers\. Use -Wno-dev to suppress it\. diff --git a/Tests/RunCMake/install/CMP0177-WARN-verify-result.txt b/Tests/RunCMake/install/CMP0177-WARN-verify-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/install/CMP0177-WARN-verify-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/install/CMP0177-WARN-verify-stderr.txt b/Tests/RunCMake/install/CMP0177-WARN-verify-stderr.txt new file mode 100644 index 0000000..0eca815 --- /dev/null +++ b/Tests/RunCMake/install/CMP0177-WARN-verify-stderr.txt @@ -0,0 +1,13 @@ +CMake Error at [^ +]*CMP0177-WARN-build/root-all/lib/cmake/pkg/pkg-config\.cmake:[0-9]+ \(message\): + The imported target "foo1" references the file ++ ".*/shouldNotRemain1/\.\./lib/(libfoo1\.a|foo1\.l(ib)?)" ++ but this file does not exist\. Possible reasons include: ++ \* The file was deleted, renamed, or moved to another location\. ++ \* An install or uninstall procedure did not complete successfully\. ++ \* The installation package was faulty and contained ++ ".*/Tests/RunCMake/install/CMP0177-WARN-build/root-all/lib/cmake/pkg/pkg-config\.cmake" ++ but not all the files it references\. ++Call Stack \(most recent call first\): + CMP0177-WARN-verify\.cmake:2 \(find_package\) + CMakeLists\.txt:3 \(include\) diff --git a/Tests/RunCMake/install/CMP0177-WARN-verify.cmake b/Tests/RunCMake/install/CMP0177-WARN-verify.cmake new file mode 100644 index 0000000..7b8b2dc --- /dev/null +++ b/Tests/RunCMake/install/CMP0177-WARN-verify.cmake @@ -0,0 +1,2 @@ +enable_language(C) +find_package(pkg REQUIRED) diff --git a/Tests/RunCMake/install/CMP0177-WARN.cmake b/Tests/RunCMake/install/CMP0177-WARN.cmake new file mode 100644 index 0000000..5bad118 --- /dev/null +++ b/Tests/RunCMake/install/CMP0177-WARN.cmake @@ -0,0 +1 @@ +include(${CMAKE_CURRENT_LIST_DIR}/CMP0177.cmake) diff --git a/Tests/RunCMake/install/CMP0177.cmake b/Tests/RunCMake/install/CMP0177.cmake new file mode 100644 index 0000000..1763676 --- /dev/null +++ b/Tests/RunCMake/install/CMP0177.cmake @@ -0,0 +1,29 @@ +enable_language(C) + +add_library(foo1 STATIC obj1.c) +add_library(foo2 STATIC obj2.c) + +set_target_properties(foo2 PROPERTIES HIDDEN_DOUBLE_DOT "..") + +# All the shouldNotRemainX path components below should be normalized out when +# CMP0177 is set to NEW, and retained for OLD and WARN. + +install(TARGETS foo1 + EXPORT pkg + ARCHIVE DESTINATION shouldNotRemain1/../lib +) +install(TARGETS foo2 + EXPORT pkg + ARCHIVE DESTINATION shouldNotRemain2/$<TARGET_PROPERTY:foo2,HIDDEN_DOUBLE_DOT>/lib +) +install(EXPORT pkg + DESTINATION shouldNotRemain3/deeper/../.././lib/cmake/pkg + FILE pkg-config.cmake +) +install(FILES obj1.c + DESTINATION shouldNotRemain4/anotherSubdir/../../files +) +install(DIRECTORY dir + # Trailing slash here is significant + DESTINATION shouldNotRemain5/../dirs/more/../ +) diff --git a/Tests/RunCMake/install/RunCMakeTest.cmake b/Tests/RunCMake/install/RunCMakeTest.cmake index 844c4b9..39c3373 100644 --- a/Tests/RunCMake/install/RunCMakeTest.cmake +++ b/Tests/RunCMake/install/RunCMakeTest.cmake @@ -94,6 +94,12 @@ run_cmake(CMP0062-WARN) run_cmake(CMP0087-OLD) run_cmake(CMP0087-NEW) run_cmake(CMP0087-WARN) +foreach(policy IN ITEMS NEW OLD WARN) + run_install_test(CMP0177-${policy}) + run_cmake_with_options(CMP0177-${policy}-verify + -DCMAKE_PREFIX_PATH=${RunCMake_BINARY_DIR}/CMP0177-${policy}-build/root-all + ) +endforeach() run_cmake(TARGETS-ImportedGlobal) run_cmake(TARGETS-NAMELINK_COMPONENT-bad-all) run_cmake(TARGETS-NAMELINK_COMPONENT-bad-exc) |