Browse Source

CMP0028: Report backtrace to link item rather than target creation

Now that we have proper backtraces for both `LINK_LIBRARIES` and
`INTERFACE_LINK_LIBRARIES` entries, we can report them in error
messages.
Brad King 3 years ago
parent
commit
a97c92e46e

+ 5 - 1
Source/cmGeneratorTarget.cxx

@@ -2722,8 +2722,12 @@ public:
             << "\" but the target was not found.  Perhaps a find_package() "
                "call is missing for an IMPORTED target, or an ALIAS target is "
                "missing?";
+          cmListFileBacktrace backtrace = item.Backtrace;
+          if (backtrace.Empty()) {
+            backtrace = this->Target->GetBacktrace();
+          }
           this->Target->GetLocalGenerator()->GetCMakeInstance()->IssueMessage(
-            messageType, e.str(), this->Target->GetBacktrace());
+            messageType, e.str(), backtrace);
         }
       }
       return;

+ 2 - 2
Tests/RunCMake/CMP0028/CMP0028-NEW-iface-stderr.txt

@@ -1,6 +1,6 @@
-CMake Error at CMP0028-NEW-iface.cmake:6 \(add_library\):
+CMake Error at CMP0028-NEW-iface\.cmake:5 \(target_link_libraries\):
   Target "foo" links to target "External::Library" but the target was not
   found.  Perhaps a find_package\(\) call is missing for an IMPORTED target, or
   an ALIAS target is missing\?
 Call Stack \(most recent call first\):
-  CMakeLists.txt:3 \(include\)
+  CMakeLists\.txt:[0-9]+ \(include\)

+ 2 - 2
Tests/RunCMake/CMP0028/CMP0028-NEW-stderr.txt

@@ -1,6 +1,6 @@
-CMake Error at CMP0028-NEW.cmake:4 \(add_library\):
+CMake Error at CMP0028-NEW\.cmake:5 \(target_link_libraries\):
   Target "foo" links to target "External::Library" but the target was not
   found.  Perhaps a find_package\(\) call is missing for an IMPORTED target, or
   an ALIAS target is missing\?
 Call Stack \(most recent call first\):
-  CMakeLists.txt:3 \(include\)
+  CMakeLists\.txt:[0-9]+ \(include\)

+ 2 - 2
Tests/RunCMake/CMP0028/CMP0028-WARN-iface-stderr.txt

@@ -1,4 +1,4 @@
-CMake Warning \(dev\) at CMP0028-WARN-iface.cmake:4 \(add_library\):
+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.
@@ -7,5 +7,5 @@ CMake Warning \(dev\) at CMP0028-WARN-iface.cmake:4 \(add_library\):
   found.  Perhaps a find_package\(\) call is missing for an IMPORTED target, or
   an ALIAS target is missing\?
 Call Stack \(most recent call first\):
-  CMakeLists.txt:3 \(include\)
+  CMakeLists\.txt:[0-9]+ \(include\)
 This warning is for project developers.  Use -Wno-dev to suppress it.

+ 2 - 2
Tests/RunCMake/CMP0028/CMP0028-WARN-stderr.txt

@@ -1,4 +1,4 @@
-CMake Warning \(dev\) at CMP0028-WARN.cmake:2 \(add_library\):
+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.
@@ -7,5 +7,5 @@ CMake Warning \(dev\) at CMP0028-WARN.cmake:2 \(add_library\):
   found.  Perhaps a find_package\(\) call is missing for an IMPORTED target, or
   an ALIAS target is missing\?
 Call Stack \(most recent call first\):
-  CMakeLists.txt:3 \(include\)
+  CMakeLists\.txt:[0-9]+ \(include\)
 This warning is for project developers.  Use -Wno-dev to suppress it.

+ 1 - 1
Tests/RunCMake/target_link_libraries/CMP0079-link-NEW-bogus-stderr.txt

@@ -1,4 +1,4 @@
-^CMake Error at CMP0079-link-NEW-bogus.cmake:[0-9]+ \(add_executable\):
+^CMake Error at CMP0079-link-NEW-bogus\.cmake:6 \(set_property\):
   Target "top" links to target "::@\(0xdeadbeef\)" but the target was not
   found.  Perhaps a find_package\(\) call is missing for an IMPORTED target, or
   an ALIAS target is missing\?

+ 4 - 4
Tests/RunCMake/target_link_libraries/ConfigCase-stderr.txt

@@ -1,13 +1,13 @@
-^CMake Error at ConfigCase.cmake:[0-9]+ \(add_library\):
+^CMake Error at ConfigCase\.cmake:6 \(target_link_libraries\):
   Target "impl" links to target "config::impl-Debug" but the target was not
   found.  Perhaps a find_package\(\) call is missing for an IMPORTED target, or
   an ALIAS target is missing\?
 Call Stack \(most recent call first\):
-  CMakeLists.txt:[0-9]+ \(include\)
+  CMakeLists\.txt:[0-9]+ \(include\)
 +
-CMake Error at ConfigCase.cmake:[0-9]+ \(add_library\):
+CMake Error at ConfigCase\.cmake:4 \(target_link_libraries\):
   Target "impl" links to target "config::iface-Debug" but the target was not
   found.  Perhaps a find_package\(\) call is missing for an IMPORTED target, or
   an ALIAS target is missing\?
 Call Stack \(most recent call first\):
-  CMakeLists.txt:[0-9]+ \(include\)
+  CMakeLists\.txt:[0-9]+ \(include\)