Ver Fonte

New CMP0016 for deciding whether an unknown target in TLL() is an error.

When set to OLD, target_link_libraries() silently accepts if it is called
with only one argument and this one argument is not a target.
When set to NEW, this is an error. By default it is a warning now.

Alex
Alex Neundorf há 15 anos atrás
pai
commit
6acc71c09d
3 ficheiros alterados com 47 adições e 7 exclusões
  1. 8 0
      Source/cmPolicies.cxx
  2. 1 0
      Source/cmPolicies.h
  3. 38 7
      Source/cmTargetLinkLibrariesCommand.cxx

+ 8 - 0
Source/cmPolicies.cxx

@@ -438,6 +438,14 @@ cmPolicies::cmPolicies()
     "CMAKE_CURRENT_SOURCE_DIR.",
     "CMAKE_CURRENT_SOURCE_DIR.",
     2,8,1,0, cmPolicies::WARN);
     2,8,1,0, cmPolicies::WARN);
 
 
+    this->DefinePolicy(
+    CMP0016, "CMP0016",
+    "target_link_libraries() reports error if only argument is not a target.",
+    "In CMake 2.8.2 and lower the target_link_libraries() command silently "
+    "ignored if it was called with only one argument, and this argument "
+    "wasn't a valid target. "
+    "In CMake 2.8.3 and above it reports an error in this case.",
+    2,8,3,0, cmPolicies::WARN);
 }
 }
 
 
 cmPolicies::~cmPolicies()
 cmPolicies::~cmPolicies()

+ 1 - 0
Source/cmPolicies.h

@@ -51,6 +51,7 @@ public:
     CMP0013, // Duplicate binary directories not allowed
     CMP0013, // Duplicate binary directories not allowed
     CMP0014, // Input directories must have CMakeLists.txt
     CMP0014, // Input directories must have CMakeLists.txt
     CMP0015, // link_directories() treats paths relative to source dir
     CMP0015, // link_directories() treats paths relative to source dir
+    CMP0016, // target_link_libraries() fails if only argument is not a target
 
 
     // Always the last entry.  Useful mostly to avoid adding a comma
     // Always the last entry.  Useful mostly to avoid adding a comma
     // the last policy when adding a new one.
     // the last policy when adding a new one.

+ 38 - 7
Source/cmTargetLinkLibrariesCommand.cxx

@@ -35,20 +35,51 @@ bool cmTargetLinkLibrariesCommand
     ->GetGlobalGenerator()->FindTarget(0, args[0].c_str());
     ->GetGlobalGenerator()->FindTarget(0, args[0].c_str());
   if(!this->Target)
   if(!this->Target)
     {
     {
+    cmake::MessageType t = cmake::FATAL_ERROR;  // fail by default
     cmOStringStream e;
     cmOStringStream e;
     e << "Cannot specify link libraries for target \"" << args[0] << "\" "
     e << "Cannot specify link libraries for target \"" << args[0] << "\" "
       << "which is not built by this project.";
       << "which is not built by this project.";
-    // The bad target is the only argument, just warn, don't fail, because
-    // there is probably some code out there which would stop building
-    // otherwise:
+    // The bad target is the only argument. Check how policy CMP0016 is set,
+    // and accept, warn or fail respectively:
     if (args.size() < 2)
     if (args.size() < 2)
       {
       {
-      this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, e.str());
+      switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0016))
+        {
+        case cmPolicies::WARN:
+          t = cmake::AUTHOR_WARNING;
+          // Print the warning.
+          e << "\n"
+            << "CMake does not support this but it used to work accidentally "
+            << "and is being allowed for compatibility."
+            << "\n" << this->Makefile->GetPolicies()->
+                                        GetPolicyWarning(cmPolicies::CMP0016);
+           break;
+        case cmPolicies::OLD:          // OLD behavior does not warn.
+          t = cmake::MESSAGE;
+          break;
+        case cmPolicies::REQUIRED_IF_USED:
+        case cmPolicies::REQUIRED_ALWAYS:
+          e << "\n" << this->Makefile->GetPolicies()->
+                                  GetRequiredPolicyError(cmPolicies::CMP0016);
+          break;
+        case cmPolicies::NEW:  // NEW behavior prints the error.
+        default:
+          break;
+        }
       }
       }
-    else
+
+    // now actually print the message
+    switch(t)
       {
       {
-      this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
-      cmSystemTools::SetFatalErrorOccured();
+      case cmake::AUTHOR_WARNING:
+        this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, e.str());
+        break;
+      case cmake::FATAL_ERROR:
+        this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+        cmSystemTools::SetFatalErrorOccured();
+        break;
+      default:
+        break;
       }
       }
     return true;
     return true;
     }
     }