diff options
Diffstat (limited to 'Tests/RunCMake/LinkItemValidation')
25 files changed, 233 insertions, 0 deletions
diff --git a/Tests/RunCMake/LinkItemValidation/CMP0028-NEW-iface-result.txt b/Tests/RunCMake/LinkItemValidation/CMP0028-NEW-iface-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/LinkItemValidation/CMP0028-NEW-iface-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/LinkItemValidation/CMP0028-NEW-iface-stderr.txt b/Tests/RunCMake/LinkItemValidation/CMP0028-NEW-iface-stderr.txt new file mode 100644 index 0000000..111d1f0 --- /dev/null +++ b/Tests/RunCMake/LinkItemValidation/CMP0028-NEW-iface-stderr.txt @@ -0,0 +1,12 @@ +CMake Error at CMP0028-NEW-iface\.cmake:5 \(target_link_libraries\): + The link interface of target "iface" contains: + + External::Library + + but the target was not found. Possible reasons include: +( + \*[^ +]+)* + +Call Stack \(most recent call first\): + CMakeLists\.txt:[0-9]+ \(include\) diff --git a/Tests/RunCMake/LinkItemValidation/CMP0028-NEW-iface.cmake b/Tests/RunCMake/LinkItemValidation/CMP0028-NEW-iface.cmake new file mode 100644 index 0000000..1a71433 --- /dev/null +++ b/Tests/RunCMake/LinkItemValidation/CMP0028-NEW-iface.cmake @@ -0,0 +1,7 @@ + +cmake_policy(SET CMP0028 NEW) + +add_library(iface INTERFACE) +target_link_libraries(iface INTERFACE External::Library) +add_library(foo empty.cpp) +target_link_libraries(foo iface) diff --git a/Tests/RunCMake/LinkItemValidation/CMP0028-NEW-result.txt b/Tests/RunCMake/LinkItemValidation/CMP0028-NEW-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/LinkItemValidation/CMP0028-NEW-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/LinkItemValidation/CMP0028-NEW-stderr.txt b/Tests/RunCMake/LinkItemValidation/CMP0028-NEW-stderr.txt new file mode 100644 index 0000000..17b25de --- /dev/null +++ b/Tests/RunCMake/LinkItemValidation/CMP0028-NEW-stderr.txt @@ -0,0 +1,12 @@ +CMake Error at CMP0028-NEW\.cmake:5 \(target_link_libraries\): + Target "foo" links to: + + External::Library + + but the target was not found. Possible reasons include: +( + \*[^ +]+)* + +Call Stack \(most recent call first\): + CMakeLists\.txt:[0-9]+ \(include\) diff --git a/Tests/RunCMake/LinkItemValidation/CMP0028-NEW.cmake b/Tests/RunCMake/LinkItemValidation/CMP0028-NEW.cmake new file mode 100644 index 0000000..a0a6ae8 --- /dev/null +++ b/Tests/RunCMake/LinkItemValidation/CMP0028-NEW.cmake @@ -0,0 +1,5 @@ + +cmake_policy(SET CMP0028 NEW) + +add_library(foo empty.cpp) +target_link_libraries(foo PRIVATE External::Library) diff --git a/Tests/RunCMake/LinkItemValidation/CMP0028-OLD-iface-result.txt b/Tests/RunCMake/LinkItemValidation/CMP0028-OLD-iface-result.txt new file mode 100644 index 0000000..573541a --- /dev/null +++ b/Tests/RunCMake/LinkItemValidation/CMP0028-OLD-iface-result.txt @@ -0,0 +1 @@ +0 diff --git a/Tests/RunCMake/LinkItemValidation/CMP0028-OLD-iface-stderr.txt b/Tests/RunCMake/LinkItemValidation/CMP0028-OLD-iface-stderr.txt new file mode 100644 index 0000000..b7a0755 --- /dev/null +++ b/Tests/RunCMake/LinkItemValidation/CMP0028-OLD-iface-stderr.txt @@ -0,0 +1,10 @@ +^CMake Deprecation Warning at CMP0028-OLD-iface.cmake:[0-9]+ \(cmake_policy\): + The OLD behavior for policy CMP0028 will be removed from a future version + of CMake. + + The cmake-policies\(7\) manual explains that the OLD behaviors of all + policies are deprecated and that a policy should be set to OLD only under + specific short-term circumstances. Projects should be ported to the NEW + behavior and not rely on setting a policy to OLD. +Call Stack \(most recent call first\): + CMakeLists.txt:[0-9]+ \(include\)$ diff --git a/Tests/RunCMake/LinkItemValidation/CMP0028-OLD-iface.cmake b/Tests/RunCMake/LinkItemValidation/CMP0028-OLD-iface.cmake new file mode 100644 index 0000000..d7bd60e --- /dev/null +++ b/Tests/RunCMake/LinkItemValidation/CMP0028-OLD-iface.cmake @@ -0,0 +1,7 @@ + +cmake_policy(SET CMP0028 OLD) + +add_library(iface INTERFACE) +target_link_libraries(iface INTERFACE External::Library) +add_library(foo empty.cpp) +target_link_libraries(foo iface) diff --git a/Tests/RunCMake/LinkItemValidation/CMP0028-OLD-result.txt b/Tests/RunCMake/LinkItemValidation/CMP0028-OLD-result.txt new file mode 100644 index 0000000..573541a --- /dev/null +++ b/Tests/RunCMake/LinkItemValidation/CMP0028-OLD-result.txt @@ -0,0 +1 @@ +0 diff --git a/Tests/RunCMake/LinkItemValidation/CMP0028-OLD-stderr.txt b/Tests/RunCMake/LinkItemValidation/CMP0028-OLD-stderr.txt new file mode 100644 index 0000000..586a876 --- /dev/null +++ b/Tests/RunCMake/LinkItemValidation/CMP0028-OLD-stderr.txt @@ -0,0 +1,10 @@ +^CMake Deprecation Warning at CMP0028-OLD.cmake:[0-9]+ \(cmake_policy\): + The OLD behavior for policy CMP0028 will be removed from a future version + of CMake. + + The cmake-policies\(7\) manual explains that the OLD behaviors of all + policies are deprecated and that a policy should be set to OLD only under + specific short-term circumstances. Projects should be ported to the NEW + behavior and not rely on setting a policy to OLD. +Call Stack \(most recent call first\): + CMakeLists.txt:[0-9]+ \(include\)$ diff --git a/Tests/RunCMake/LinkItemValidation/CMP0028-OLD.cmake b/Tests/RunCMake/LinkItemValidation/CMP0028-OLD.cmake new file mode 100644 index 0000000..d4a870b --- /dev/null +++ b/Tests/RunCMake/LinkItemValidation/CMP0028-OLD.cmake @@ -0,0 +1,5 @@ + +cmake_policy(SET CMP0028 OLD) + +add_library(foo empty.cpp) +target_link_libraries(foo PRIVATE External::Library) diff --git a/Tests/RunCMake/LinkItemValidation/CMP0028-WARN-iface-result.txt b/Tests/RunCMake/LinkItemValidation/CMP0028-WARN-iface-result.txt new file mode 100644 index 0000000..573541a --- /dev/null +++ b/Tests/RunCMake/LinkItemValidation/CMP0028-WARN-iface-result.txt @@ -0,0 +1 @@ +0 diff --git a/Tests/RunCMake/LinkItemValidation/CMP0028-WARN-iface-stderr.txt b/Tests/RunCMake/LinkItemValidation/CMP0028-WARN-iface-stderr.txt new file mode 100644 index 0000000..bb6a16e --- /dev/null +++ b/Tests/RunCMake/LinkItemValidation/CMP0028-WARN-iface-stderr.txt @@ -0,0 +1,17 @@ +CMake Warning \(dev\) at CMP0028-WARN-iface\.cmake:3 \(target_link_libraries\): + Policy CMP0028 is not set: Double colon in target name means ALIAS or + IMPORTED target. Run "cmake --help-policy CMP0028" for policy details. + Use the cmake_policy command to set the policy and suppress this warning. + + The link interface of target "iface" contains: + + External::Library + + but the target was not found. Possible reasons include: +( + \*[^ +]+)* + +Call Stack \(most recent call first\): + CMakeLists\.txt:[0-9]+ \(include\) +This warning is for project developers. Use -Wno-dev to suppress it. diff --git a/Tests/RunCMake/LinkItemValidation/CMP0028-WARN-iface.cmake b/Tests/RunCMake/LinkItemValidation/CMP0028-WARN-iface.cmake new file mode 100644 index 0000000..9270023 --- /dev/null +++ b/Tests/RunCMake/LinkItemValidation/CMP0028-WARN-iface.cmake @@ -0,0 +1,5 @@ + +add_library(iface INTERFACE) +target_link_libraries(iface INTERFACE External::Library) +add_library(foo empty.cpp) +target_link_libraries(foo iface) diff --git a/Tests/RunCMake/LinkItemValidation/CMP0028-WARN-result.txt b/Tests/RunCMake/LinkItemValidation/CMP0028-WARN-result.txt new file mode 100644 index 0000000..573541a --- /dev/null +++ b/Tests/RunCMake/LinkItemValidation/CMP0028-WARN-result.txt @@ -0,0 +1 @@ +0 diff --git a/Tests/RunCMake/LinkItemValidation/CMP0028-WARN-stderr.txt b/Tests/RunCMake/LinkItemValidation/CMP0028-WARN-stderr.txt new file mode 100644 index 0000000..c0cb5b0 --- /dev/null +++ b/Tests/RunCMake/LinkItemValidation/CMP0028-WARN-stderr.txt @@ -0,0 +1,17 @@ +CMake Warning \(dev\) at CMP0028-WARN\.cmake:3 \(target_link_libraries\): + Policy CMP0028 is not set: Double colon in target name means ALIAS or + IMPORTED target. Run "cmake --help-policy CMP0028" for policy details. + Use the cmake_policy command to set the policy and suppress this warning. + + Target "foo" links to: + + External::Library + + but the target was not found. Possible reasons include: +( + \*[^ +]+)* + +Call Stack \(most recent call first\): + CMakeLists\.txt:[0-9]+ \(include\) +This warning is for project developers. Use -Wno-dev to suppress it. diff --git a/Tests/RunCMake/LinkItemValidation/CMP0028-WARN.cmake b/Tests/RunCMake/LinkItemValidation/CMP0028-WARN.cmake new file mode 100644 index 0000000..70a6cc6 --- /dev/null +++ b/Tests/RunCMake/LinkItemValidation/CMP0028-WARN.cmake @@ -0,0 +1,3 @@ + +add_library(foo empty.cpp) +target_link_libraries(foo PRIVATE External::Library) diff --git a/Tests/RunCMake/LinkItemValidation/CMakeLists.txt b/Tests/RunCMake/LinkItemValidation/CMakeLists.txt new file mode 100644 index 0000000..185cd91 --- /dev/null +++ b/Tests/RunCMake/LinkItemValidation/CMakeLists.txt @@ -0,0 +1,6 @@ +cmake_minimum_required(VERSION 2.8.12) +if(NOT RunCMake_TEST MATCHES "^CMP0028") + cmake_minimum_required(VERSION 3.22) +endif() +project(${RunCMake_TEST} CXX) +include(${RunCMake_TEST}.cmake NO_POLICY_SCOPE) # policy used at end of dir diff --git a/Tests/RunCMake/LinkItemValidation/OnlyTargets-result.txt b/Tests/RunCMake/LinkItemValidation/OnlyTargets-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/LinkItemValidation/OnlyTargets-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/LinkItemValidation/OnlyTargets-stderr.txt b/Tests/RunCMake/LinkItemValidation/OnlyTargets-stderr.txt new file mode 100644 index 0000000..bbb0170 --- /dev/null +++ b/Tests/RunCMake/LinkItemValidation/OnlyTargets-stderr.txt @@ -0,0 +1,40 @@ +^CMake Error at OnlyTargets\.cmake:11 \(target_link_libraries\): + Target "exe" has LINK_LIBRARIES_ONLY_TARGETS enabled, but it links to: + + non_target_in_exe + + which is not a target\. Possible reasons include: +( + \*[^ +]+)* + +Call Stack \(most recent call first\): + CMakeLists\.txt:[0-9]+ \(include\) ++ +CMake Error at OnlyTargets\.cmake:21 \(target_link_libraries\): + Target "iface" has LINK_LIBRARIES_ONLY_TARGETS enabled, but its link + interface contains: + + non_target_in_iface + + which is not a target\. Possible reasons include: +( + \*[^ +]+)* + +Call Stack \(most recent call first\): + CMakeLists\.txt:[0-9]+ \(include\) ++ +CMake Error at OnlyTargets\.cmake:30 \(target_link_libraries\): + Target "iface_imported_checked" has LINK_LIBRARIES_ONLY_TARGETS enabled, + but its link interface contains: + + non_target_in_iface_imported_checked + + which is not a target\. Possible reasons include: +( + \*[^ +]+)* + +Call Stack \(most recent call first\): + CMakeLists\.txt:[0-9]+ \(include\) diff --git a/Tests/RunCMake/LinkItemValidation/OnlyTargets.cmake b/Tests/RunCMake/LinkItemValidation/OnlyTargets.cmake new file mode 100644 index 0000000..9417318 --- /dev/null +++ b/Tests/RunCMake/LinkItemValidation/OnlyTargets.cmake @@ -0,0 +1,56 @@ +enable_language(C) + +set(CMAKE_LINK_LIBRARIES_ONLY_TARGETS 1) + +# Use imported interface library to name toolchain-provided libraries. +add_library(toolchain::m INTERFACE IMPORTED) +set_property(TARGET toolchain::m PROPERTY IMPORTED_LIBNAME "m") + +# Linking directly warns. +add_executable(exe main.c) +target_link_libraries(exe PRIVATE + -lflag_in_exe # accepted + /abs/path/in_exe # accepted + rel/path/in_exe # accepted + toolchain::m # accepted + non_target_in_exe # rejected + ) + +# Link interfaces warn. +add_library(iface INTERFACE) +target_link_libraries(iface INTERFACE + -lflag_in_iface # accepted + /abs/path/in_iface # accepted + rel/path/in_iface # accepted + non_target_in_iface # rejected + ) + +# Imported target link interfaces warn if explicitly enabled. +add_library(iface_imported_checked INTERFACE IMPORTED) +target_link_libraries(iface_imported_checked INTERFACE + -lflag_iface_imported_checked # accepted + /abs/path/in_iface_imported_checked # accepted + rel/path/in_iface_imported_checked # accepted + non_target_in_iface_imported_checked # rejected + ) +set_property(TARGET iface_imported_checked PROPERTY LINK_LIBRARIES_ONLY_TARGETS 1) + +# Linking directly does not warn if explicitly disabled. +add_executable(exe_not_checked main.c) +target_link_libraries(exe_not_checked PRIVATE + non_target_in_exe_not_checked + ) +set_property(TARGET exe_not_checked PROPERTY LINK_LIBRARIES_ONLY_TARGETS 0) + +# Link interfaces do not warn if explicitly disabled. +add_library(iface_not_checked INTERFACE) +target_link_libraries(iface_not_checked INTERFACE + non_target_in_iface_not_checked + ) +set_property(TARGET iface_not_checked PROPERTY LINK_LIBRARIES_ONLY_TARGETS 0) + +# Imported target link interfaces do not warn if not explicitly enabled. +add_library(iface_imported_default INTERFACE IMPORTED) +target_link_libraries(iface_imported_default INTERFACE + non_target_in_iface_imported_default + ) diff --git a/Tests/RunCMake/LinkItemValidation/RunCMakeTest.cmake b/Tests/RunCMake/LinkItemValidation/RunCMakeTest.cmake new file mode 100644 index 0000000..c423f6a --- /dev/null +++ b/Tests/RunCMake/LinkItemValidation/RunCMakeTest.cmake @@ -0,0 +1,10 @@ +include(RunCMake) + +run_cmake(CMP0028-NEW) +run_cmake(CMP0028-OLD) +run_cmake(CMP0028-WARN) +run_cmake(CMP0028-NEW-iface) +run_cmake(CMP0028-OLD-iface) +run_cmake(CMP0028-WARN-iface) + +run_cmake(OnlyTargets) diff --git a/Tests/RunCMake/LinkItemValidation/empty.cpp b/Tests/RunCMake/LinkItemValidation/empty.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Tests/RunCMake/LinkItemValidation/empty.cpp diff --git a/Tests/RunCMake/LinkItemValidation/main.c b/Tests/RunCMake/LinkItemValidation/main.c new file mode 100644 index 0000000..8488f4e --- /dev/null +++ b/Tests/RunCMake/LinkItemValidation/main.c @@ -0,0 +1,4 @@ +int main(void) +{ + return 0; +} |