Parcourir la source

Merge branch 'restore-imported-lib-alias-diagnostic' into release-3.11

Merge-request: !2058
Brad King il y a 7 ans
Parent
commit
4f0c5d3775

+ 9 - 0
Help/release/3.11.rst

@@ -283,3 +283,12 @@ Changes made since CMake 3.11.0 include the following.
   CMake 3.11.0.  This has been reverted due to changing behavior of
   checks for existing projects.  It may be restored in the future
   with a policy for compatibility.
+
+3.11.2
+------
+
+* Calling :command:`add_library` to create an alias of an imported
+  target that is not globally visible now causes an error again as
+  it did prior to 3.11.0.  This diagnostic was accidentally dropped
+  from CMake 3.11.0 and 3.11.1 by the change to allow globally visible
+  imported targets to be aliased.

+ 8 - 0
Source/cmAddLibraryCommand.cxx

@@ -228,6 +228,14 @@ bool cmAddLibraryCommand::InitialPass(std::vector<std::string> const& args,
       this->SetError(e.str());
       return false;
     }
+    if (aliasedTarget->IsImported() &&
+        !aliasedTarget->IsImportedGloballyVisible()) {
+      std::ostringstream e;
+      e << "cannot create ALIAS target \"" << libName << "\" because target \""
+        << aliasedName << "\" is imported but not globally visible.";
+      this->SetError(e.str());
+      return false;
+    }
     this->Makefile->AddAlias(libName, aliasedName);
     return true;
   }

+ 8 - 2
Tests/RunCMake/alias_targets/imported-target-stderr.txt

@@ -3,7 +3,13 @@
   \"test-exe\" is imported but not globally visible.
 Call Stack \(most recent call first\):
   CMakeLists.txt:[0-9]+ \(include\)
-
-
++
 'alias-test-exe' does not exist![?]
+*
+CMake Error at imported-target.cmake:[0-9]+ \(add_library\):
+  add_library cannot create ALIAS target "alias-test-lib" because target
+  "test-lib" is imported but not globally visible.
+Call Stack \(most recent call first\):
+  CMakeLists.txt:[0-9]+ \(include\)
++
 'alias-test-lib' does not exist![?]$