Browse Source

CMP0003: Remove support for OLD behavior

Brad King 1 year ago
parent
commit
9dd9321a18

+ 5 - 4
Help/policy/CMP0003.rst

@@ -1,6 +1,9 @@
 CMP0003
 -------
 
+.. |REMOVED_IN_CMAKE_VERSION| replace:: 4.0
+.. include:: REMOVED_PROLOGUE.txt
+
 Libraries linked via full path no longer produce linker search paths.
 
 This policy affects how libraries whose full paths are NOT known are
@@ -98,7 +101,5 @@ target.  This avoids flooding users with messages for every target
 when setting the policy once will probably fix all targets.
 
 .. |INTRODUCED_IN_CMAKE_VERSION| replace:: 2.6.0
-.. |WARNS_OR_DOES_NOT_WARN| replace:: warns
-.. include:: STANDARD_ADVICE.txt
-
-.. include:: DEPRECATED.txt
+.. |WARNED_OR_DID_NOT_WARN| replace:: warned
+.. include:: REMOVED_EPILOGUE.txt

+ 0 - 30
Source/cmComputeLinkDepends.cxx

@@ -671,11 +671,6 @@ cmComputeLinkDepends::cmComputeLinkDepends(const cmGeneratorTarget* target,
 
 cmComputeLinkDepends::~cmComputeLinkDepends() = default;
 
-void cmComputeLinkDepends::SetOldLinkDirMode(bool b)
-{
-  this->OldLinkDirMode = b;
-}
-
 std::vector<cmComputeLinkDepends::LinkEntry> const&
 cmComputeLinkDepends::Compute()
 {
@@ -884,11 +879,6 @@ void cmComputeLinkDepends::FollowLinkEntry(BFSEntry qe)
 
       // Handle dependent shared libraries.
       this->FollowSharedDeps(depender_index, iface);
-
-      // Support for CMP0003.
-      for (cmLinkItem const& oi : iface->WrongConfigLibraries) {
-        this->CheckWrongConfigItem(oi);
-      }
     }
   } else {
     // Follow the old-style dependency list.
@@ -999,9 +989,6 @@ void cmComputeLinkDepends::AddVarLinkEntries(
       // If the library is meant for this link type then use it.
       if (llt == GENERAL_LibraryType || llt == this->LinkType) {
         actual_libs.emplace_back(this->ResolveLinkItem(depender_index, d));
-      } else if (this->OldLinkDirMode) {
-        cmLinkItem item = this->ResolveLinkItem(depender_index, d);
-        this->CheckWrongConfigItem(item);
       }
 
       // Reset the link type until another explicit type is given.
@@ -1028,9 +1015,6 @@ void cmComputeLinkDepends::AddDirectLinkEntries()
       this->AddLinkEntries(cm::nullopt, runtimeEntries->second);
     }
   }
-  for (cmLinkItem const& wi : impl->WrongConfigLibraries) {
-    this->CheckWrongConfigItem(wi);
-  }
 }
 
 template <typename T>
@@ -1736,17 +1720,3 @@ void cmComputeLinkDepends::DisplayFinalEntries()
   }
   fprintf(stderr, "\n");
 }
-
-void cmComputeLinkDepends::CheckWrongConfigItem(cmLinkItem const& item)
-{
-  if (!this->OldLinkDirMode) {
-    return;
-  }
-
-  // For CMake 2.4 bug-compatibility we need to consider the output
-  // directories of targets linked in another configuration as link
-  // directories.
-  if (item.Target && !item.Target->IsImported()) {
-    this->OldWrongConfigItems.insert(item.Target);
-  }
-}

+ 0 - 9
Source/cmComputeLinkDepends.h

@@ -85,12 +85,6 @@ public:
   using EntryVector = std::vector<LinkEntry>;
   EntryVector const& Compute();
 
-  void SetOldLinkDirMode(bool b);
-  std::set<cmGeneratorTarget const*> const& GetOldWrongConfigItems() const
-  {
-    return this->OldWrongConfigItems;
-  }
-
 private:
   // Context information.
   cmGeneratorTarget const* Target = nullptr;
@@ -212,12 +206,9 @@ private:
 
   // Record of the original link line.
   std::vector<size_t> OriginalEntries;
-  std::set<cmGeneratorTarget const*> OldWrongConfigItems;
-  void CheckWrongConfigItem(cmLinkItem const& item);
 
   // Record of explicitly linked object files.
   std::vector<size_t> ObjectEntries;
 
   size_t ComponentOrderId;
-  bool OldLinkDirMode = false;
 };

+ 6 - 176
Source/cmComputeLinkInformation.cxx

@@ -422,25 +422,6 @@ cmComputeLinkInformation::cmComputeLinkInformation(
     this->OrderDependentRPath->AddLanguageDirectories(this->RuntimeLinkDirs);
   }
 
-  // Decide whether to enable compatible library search path mode.
-  // There exists code that effectively does
-  //
-  //    /path/to/libA.so -lB
-  //
-  // where -lB is meant to link to /path/to/libB.so.  This is broken
-  // because it specified -lB without specifying a link directory (-L)
-  // in which to search for B.  This worked in CMake 2.4 and below
-  // because -L/path/to would be added by the -L/-l split for A.  In
-  // order to support such projects we need to add the directories
-  // containing libraries linked with a full path to the -L path.
-  this->OldLinkDirMode =
-    this->Target->GetPolicyStatusCMP0003() != cmPolicies::NEW;
-  if (this->OldLinkDirMode) {
-    // Construct a mask to not bother with this behavior for link
-    // directories already specified by the user.
-    this->OldLinkDirMask.insert(directories.begin(), directories.end());
-  }
-
   this->CMP0060Warn = this->Makefile->PolicyOptionalWarningEnabled(
     "CMAKE_POLICY_WARNING_CMP0060");
 }
@@ -587,7 +568,6 @@ bool cmComputeLinkInformation::Compute()
   // Compute the ordered link line items.
   cmComputeLinkDepends cld(this->Target, this->Config, this->LinkLanguage,
                            strategy);
-  cld.SetOldLinkDirMode(this->OldLinkDirMode);
   cmComputeLinkDepends::EntryVector const& linkEntries = cld.Compute();
   FeatureDescriptor const* currentFeature = nullptr;
 
@@ -667,27 +647,6 @@ bool cmComputeLinkInformation::Compute()
     this->SetCurrentLinkType(this->StartLinkType);
   }
 
-  // Finish listing compatibility paths.
-  if (this->OldLinkDirMode) {
-    // For CMake 2.4 bug-compatibility we need to consider the output
-    // directories of targets linked in another configuration as link
-    // directories.
-    std::set<cmGeneratorTarget const*> const& wrongItems =
-      cld.GetOldWrongConfigItems();
-    for (cmGeneratorTarget const* tgt : wrongItems) {
-      cmStateEnums::ArtifactType artifact = tgt->HasImportLibrary(this->Config)
-        ? cmStateEnums::ImportLibraryArtifact
-        : cmStateEnums::RuntimeBinaryArtifact;
-      this->OldLinkDirItems.push_back(
-        tgt->GetFullPath(this->Config, artifact, true));
-    }
-  }
-
-  // Finish setting up linker search directories.
-  if (!this->FinishLinkerSearchDirectories()) {
-    return false;
-  }
-
   // Add implicit language runtime libraries and directories.
   this->AddImplicitLinkInfo();
 
@@ -1301,7 +1260,7 @@ void cmComputeLinkInformation::AddItem(LinkEntry const& entry)
       }
     } else if (entry.Kind != cmComputeLinkDepends::LinkEntry::Object) {
       // This is a library or option specified by the user.
-      this->AddUserItem(entry, true);
+      this->AddUserItem(entry);
     }
   }
 }
@@ -1674,14 +1633,6 @@ void cmComputeLinkInformation::AddTargetItem(LinkEntry const& entry)
     return;
   }
 
-  // For compatibility with CMake 2.4 include the item's directory in
-  // the linker search path.
-  if (this->OldLinkDirMode && !target->IsFrameworkOnApple() &&
-      !cm::contains(this->OldLinkDirMask,
-                    cmSystemTools::GetFilenamePath(item.Value))) {
-    this->OldLinkDirItems.push_back(item.Value);
-  }
-
   const bool isImportedFrameworkFolderOnApple =
     target->IsImportedFrameworkFolderOnApple(this->Config);
   if (target->IsFrameworkOnApple() || isImportedFrameworkFolderOnApple) {
@@ -1790,14 +1741,6 @@ void cmComputeLinkInformation::AddFullItem(LinkEntry const& entry)
     }
   }
 
-  // For compatibility with CMake 2.4 include the item's directory in
-  // the linker search path.
-  if (this->OldLinkDirMode &&
-      !cm::contains(this->OldLinkDirMask,
-                    cmSystemTools::GetFilenamePath(item.Value))) {
-    this->OldLinkDirItems.push_back(item.Value);
-  }
-
   // Now add the full path to the library.
   this->Items.emplace_back(
     item, ItemIsPath::Yes, nullptr, entry.ObjectSource,
@@ -1862,7 +1805,7 @@ bool cmComputeLinkInformation::CheckImplicitDirItem(LinkEntry const& entry)
   // library for the architecture at link time.
   LinkEntry fileEntry{ entry };
   fileEntry.Item = file;
-  this->AddUserItem(fileEntry, false);
+  this->AddUserItem(fileEntry);
 
   // Make sure the link directory ordering will find the library.
   this->OrderLinkerSearchPath->AddLinkLibrary(item.Value);
@@ -1870,8 +1813,7 @@ bool cmComputeLinkInformation::CheckImplicitDirItem(LinkEntry const& entry)
   return true;
 }
 
-void cmComputeLinkInformation::AddUserItem(LinkEntry const& entry,
-                                           bool pathNotKnown)
+void cmComputeLinkInformation::AddUserItem(LinkEntry const& entry)
 {
   // This is called to handle a link item that does not match a CMake
   // target and is not a full path.  We check here if it looks like a
@@ -1886,15 +1828,6 @@ void cmComputeLinkInformation::AddUserItem(LinkEntry const& entry,
 
   if (item.Value[0] == '-' || item.Value[0] == '$' || item.Value[0] == '`') {
     // Pass flags through untouched.
-    // if this is a -l option then we might need to warn about
-    // CMP0003 so put it in OldUserFlagItems, if it is not a -l
-    // or -Wl,-l (-framework -pthread), then allow it without a
-    // CMP0003 as -L will not affect those other linker flags
-    if (cmHasLiteralPrefix(item.Value, "-l") ||
-        cmHasLiteralPrefix(item.Value, "-Wl,-l")) {
-      // This is a linker option provided by the user.
-      this->OldUserFlagItems.push_back(item.Value);
-    }
 
     // Restore the target link type since this item does not specify
     // one.
@@ -1964,11 +1897,6 @@ void cmComputeLinkInformation::AddUserItem(LinkEntry const& entry,
     // Use just the library name so the linker will search.
     lib = this->ExtractAnyLibraryName.match(2);
   } else {
-    // This is a name specified by the user.
-    if (pathNotKnown) {
-      this->OldUserFlagItems.push_back(item.Value);
-    }
-
     // We must ask the linker to search for a library with this name.
     // Restore the target link type since this item does not specify
     // one.
@@ -2154,7 +2082,7 @@ void cmComputeLinkInformation::AddSharedLibNoSOName(LinkEntry const& entry)
   // path instead of just the name.
   LinkEntry fileEntry{ entry };
   fileEntry.Item = cmSystemTools::GetFilenameName(entry.Item.Value);
-  this->AddUserItem(fileEntry, false);
+  this->AddUserItem(fileEntry);
 
   // Make sure the link directory ordering will find the library.
   this->OrderLinkerSearchPath->AddLinkLibrary(entry.Item.Value);
@@ -2171,11 +2099,10 @@ void cmComputeLinkInformation::HandleBadFullItem(LinkEntry const& entry,
   }
 
   // Tell the linker to search for the item and provide the proper
-  // path for it.  Do not contribute to any CMP0003 warning (do not
-  // put in OldLinkDirItems or OldUserFlagItems).
+  // path for it.
   LinkEntry fileEntry{ entry };
   fileEntry.Item = file;
-  this->AddUserItem(fileEntry, false);
+  this->AddUserItem(fileEntry);
   this->OrderLinkerSearchPath->AddLinkLibrary(item);
 
   // Produce any needed message.
@@ -2206,103 +2133,6 @@ void cmComputeLinkInformation::HandleBadFullItem(LinkEntry const& entry,
   }
 }
 
-bool cmComputeLinkInformation::FinishLinkerSearchDirectories()
-{
-  // Support broken projects if necessary.
-  if (this->OldLinkDirItems.empty() || this->OldUserFlagItems.empty() ||
-      !this->OldLinkDirMode) {
-    return true;
-  }
-
-  // Enforce policy constraints.
-  switch (this->Target->GetPolicyStatusCMP0003()) {
-    case cmPolicies::WARN:
-      if (!this->CMakeInstance->GetState()->GetGlobalPropertyAsBool(
-            "CMP0003-WARNING-GIVEN")) {
-        this->CMakeInstance->GetState()->SetGlobalProperty(
-          "CMP0003-WARNING-GIVEN", "1");
-        std::ostringstream w;
-        this->PrintLinkPolicyDiagnosis(w);
-        this->CMakeInstance->IssueMessage(MessageType::AUTHOR_WARNING, w.str(),
-                                          this->Target->GetBacktrace());
-      }
-      CM_FALLTHROUGH;
-    case cmPolicies::OLD:
-      // OLD behavior is to add the paths containing libraries with
-      // known full paths as link directories.
-      break;
-    case cmPolicies::NEW:
-      // Should never happen due to assignment of OldLinkDirMode
-      return true;
-  }
-
-  // Add the link directories for full path items.
-  for (std::string const& i : this->OldLinkDirItems) {
-    this->OrderLinkerSearchPath->AddLinkLibrary(i);
-  }
-  return true;
-}
-
-void cmComputeLinkInformation::PrintLinkPolicyDiagnosis(std::ostream& os)
-{
-  // Tell the user what to do.
-  /* clang-format off */
-  os << "Policy CMP0003 should be set before this line.  "
-        "Add code such as\n"
-        "  if(COMMAND cmake_policy)\n"
-        "    cmake_policy(SET CMP0003 NEW)\n"
-        "  endif(COMMAND cmake_policy)\n"
-        "as early as possible but after the most recent call to "
-        "cmake_minimum_required or cmake_policy(VERSION).  ";
-  /* clang-format on */
-
-  // List the items that might need the old-style paths.
-  os << "This warning appears because target \"" << this->Target->GetName()
-     << "\" links to some libraries for which the linker must search:\n";
-  {
-    // Format the list of unknown items to be as short as possible while
-    // still fitting in the allowed width (a true solution would be the
-    // bin packing problem if we were allowed to change the order).
-    std::string::size_type max_size = 76;
-    std::string line;
-    const char* sep = "  ";
-    for (std::string const& i : this->OldUserFlagItems) {
-      // If the addition of another item will exceed the limit then
-      // output the current line and reset it.  Note that the separator
-      // is either " " or ", " which is always 2 characters.
-      if (!line.empty() && (line.size() + i.size() + 2) > max_size) {
-        os << line << '\n';
-        sep = "  ";
-        line.clear();
-      }
-      line += sep;
-      line += i;
-      // Convert to the other separator.
-      sep = ", ";
-    }
-    if (!line.empty()) {
-      os << line << '\n';
-    }
-  }
-
-  // List the paths old behavior is adding.
-  os << "and other libraries with known full path:\n";
-  std::set<std::string> emitted;
-  for (std::string const& i : this->OldLinkDirItems) {
-    if (emitted.insert(cmSystemTools::GetFilenamePath(i)).second) {
-      os << "  " << i << '\n';
-    }
-  }
-
-  // Explain.
-  os << "CMake is adding directories in the second list to the linker "
-        "search path in case they are needed to find libraries from the "
-        "first list (for backwards compatibility with CMake 2.4).  "
-        "Set policy CMP0003 to OLD or NEW to enable or disable this "
-        "behavior explicitly.  "
-        "Run \"cmake --help-policy CMP0003\" for more information.";
-}
-
 void cmComputeLinkInformation::LoadImplicitLinkInfo()
 {
   // Get platform-wide implicit directories.

+ 1 - 9
Source/cmComputeLinkInformation.h

@@ -4,7 +4,6 @@
 
 #include "cmConfigure.h" // IWYU pragma: keep
 
-#include <iosfwd>
 #include <map>
 #include <memory>
 #include <set>
@@ -210,7 +209,7 @@ private:
   void AddTargetItem(LinkEntry const& entry);
   void AddFullItem(LinkEntry const& entry);
   bool CheckImplicitDirItem(LinkEntry const& entry);
-  void AddUserItem(LinkEntry const& entry, bool pathNotKnown);
+  void AddUserItem(LinkEntry const& entry);
   void AddFrameworkItem(LinkEntry const& entry);
   void AddXcFrameworkItem(LinkEntry const& entry);
   void DropDirectoryItem(BT<std::string> const& item);
@@ -227,8 +226,6 @@ private:
 
   // Linker search path computation.
   std::unique_ptr<cmOrderDirectories> OrderLinkerSearchPath;
-  bool FinishLinkerSearchDirectories();
-  void PrintLinkPolicyDiagnosis(std::ostream&);
 
   void AddExternalObjectTargets();
 
@@ -243,17 +240,12 @@ private:
   // Additional paths configured by the runtime linker
   std::vector<std::string> RuntimeLinkDirs;
 
-  // Linker search path compatibility mode.
-  std::set<std::string> OldLinkDirMask;
-  std::vector<std::string> OldLinkDirItems;
-  std::vector<std::string> OldUserFlagItems;
   std::set<std::string> CMP0060WarnItems;
   // Dependent library path computation.
   std::unique_ptr<cmOrderDirectories> OrderDependentRPath;
   // Runtime path computation.
   std::unique_ptr<cmOrderDirectories> OrderRuntimeSearchPath;
 
-  bool OldLinkDirMode;
   bool IsOpenBSD;
   bool LinkDependsNoShared;
   bool RuntimeUseChrpath;

+ 0 - 1
Source/cmGeneratorTarget.h

@@ -1234,7 +1234,6 @@ private:
                                           bool secondPass) const;
   void ComputeLinkInterface(const std::string& config,
                             cmOptionalLinkInterface& iface,
-                            const cmGeneratorTarget* head,
                             bool secondPass) const;
   cmLinkImplementation const* GetLinkImplementation(const std::string& config,
                                                     UseTo usage,

+ 4 - 11
Source/cmGeneratorTarget_Link.cxx

@@ -676,7 +676,7 @@ cmLinkInterface const* cmGeneratorTarget::GetLinkInterface(
   if (!iface.AllDone) {
     iface.AllDone = true;
     if (iface.Exists) {
-      this->ComputeLinkInterface(config, iface, head, secondPass);
+      this->ComputeLinkInterface(config, iface, secondPass);
       this->ComputeLinkInterfaceRuntimeLibraries(config, iface);
     }
   }
@@ -684,9 +684,9 @@ cmLinkInterface const* cmGeneratorTarget::GetLinkInterface(
   return iface.Exists ? &iface : nullptr;
 }
 
-void cmGeneratorTarget::ComputeLinkInterface(
-  const std::string& config, cmOptionalLinkInterface& iface,
-  cmGeneratorTarget const* headTarget, bool secondPass) const
+void cmGeneratorTarget::ComputeLinkInterface(const std::string& config,
+                                             cmOptionalLinkInterface& iface,
+                                             bool secondPass) const
 {
   if (iface.Explicit) {
     if (this->GetType() == cmStateEnums::SHARED_LIBRARY ||
@@ -721,11 +721,7 @@ void cmGeneratorTarget::ComputeLinkInterface(
   } else if (this->GetPolicyStatusCMP0022() == cmPolicies::WARN ||
              this->GetPolicyStatusCMP0022() == cmPolicies::OLD) {
     // The link implementation is the default link interface.
-    cmLinkImplementationLibraries const* impl =
-      this->GetLinkImplementationLibrariesInternal(config, headTarget,
-                                                   UseTo::Link);
     iface.ImplementationIsInterface = true;
-    iface.WrongConfigLibraries = impl->WrongConfigLibraries;
   }
 
   if (this->LinkLanguagePropagatesToDependents()) {
@@ -1459,9 +1455,6 @@ void cmGeneratorTarget::ComputeLinkImplementationLibraries(
       if (name == this->GetName() || name.empty()) {
         continue;
       }
-      // Support OLD behavior for CMP0003.
-      impl.WrongConfigLibraries.push_back(
-        this->ResolveLinkItem(BT<std::string>(name), linkFeature));
     }
   }
 }

+ 0 - 8
Source/cmLinkItem.h

@@ -65,10 +65,6 @@ struct cmLinkImplementationLibraries
   // Object files linked directly in this configuration.
   std::vector<cmLinkItem> Objects;
 
-  // Libraries linked directly in other configurations.
-  // Needed only for OLD behavior of CMP0003.
-  std::vector<cmLinkItem> WrongConfigLibraries;
-
   // Whether the list depends on a genex referencing the configuration.
   bool HadContextSensitiveCondition = false;
 };
@@ -108,10 +104,6 @@ struct cmLinkInterface : public cmLinkInterfaceLibraries
   // or more static libraries.
   unsigned int Multiplicity = 0;
 
-  // Libraries listed for other configurations.
-  // Needed only for OLD behavior of CMP0003.
-  std::vector<cmLinkItem> WrongConfigLibraries;
-
   bool ImplementationIsInterface = false;
 
   // Whether the list depends on a link language genex.

+ 1 - 1
Source/cmPolicies.h

@@ -24,7 +24,7 @@ class cmMakefile;
   SELECT(                                                                     \
     POLICY, CMP0003,                                                          \
     "Libraries linked via full path no longer produce linker search paths.",  \
-    2, 6, 0, WARN)                                                            \
+    2, 6, 0, NEW)                                                             \
   SELECT(POLICY, CMP0004,                                                     \
          "Libraries linked may not have leading or trailing whitespace.", 2,  \
          6, 0, WARN)                                                          \

+ 0 - 10
Tests/Complex/CMakeLists.txt

@@ -19,16 +19,6 @@ function(message)
 endfunction()
 message("message")
 
-# Try setting a new policy.  The IF test is for coverage.
-if(POLICY CMP0003)
-  cmake_policy(SET CMP0003 NEW)
-
-  cmake_policy(GET CMP0003 P3)
-  if(NOT "${P3}" STREQUAL "NEW")
-    message(FATAL_ERROR "cmake_policy(GET) did not report NEW!")
-  endif()
-endif()
-
 # It is not recommended to set a policy to OLD, but this test
 # covers the OLD behavior of some policies.
 foreach(p

+ 0 - 10
Tests/ComplexOneConfig/CMakeLists.txt

@@ -12,16 +12,6 @@ string(APPEND CMAKE_CXX_FLAGS_RELWITHDEBINFO " -DCOMPLEX_NDEBUG")
 string(APPEND CMAKE_C_FLAGS_MINSIZEREL " -DCOMPLEX_NDEBUG")
 string(APPEND CMAKE_CXX_FLAGS_MINSIZEREL " -DCOMPLEX_NDEBUG")
 
-# Try setting a new policy.  The IF test is for coverage.
-if(POLICY CMP0003)
-  cmake_policy(SET CMP0003 NEW)
-
-  cmake_policy(GET CMP0003 P3)
-  if(NOT "${P3}" STREQUAL "NEW")
-    message(FATAL_ERROR "cmake_policy(GET) did not report NEW!")
-  endif()
-endif()
-
 # It is not recommended to set a policy to OLD, but this test
 # covers the OLD behavior of some policies.
 foreach(p