$OpenBSD: patch-Source_cmComputeLinkInformation_cxx,v 1.26 2020/12/30 07:17:34 rsadowski Exp $
Index: Source/cmComputeLinkInformation.cxx
--- Source/cmComputeLinkInformation.cxx.orig
+++ Source/cmComputeLinkInformation.cxx
@@ -371,8 +371,9 @@ cmComputeLinkInformation::cmComputeLinkInformation(
   this->OrderRuntimeSearchPath->AddUserDirectories(directories);
 
   // Set up the implicit link directories.
-  this->LoadImplicitLinkInfo();
+  this->LoadImplicitLinkInfoOpenBSD();
   this->OrderLinkerSearchPath->SetImplicitDirectories(this->ImplicitLinkDirs);
+  this->LoadImplicitLinkInfo();
   this->OrderRuntimeSearchPath->SetImplicitDirectories(this->ImplicitLinkDirs);
   if (this->OrderDependentRPath) {
     this->OrderDependentRPath->SetImplicitDirectories(this->ImplicitLinkDirs);
@@ -482,6 +483,7 @@ cmComputeLinkInformation::GetSharedLibrariesLinked() c
 
 bool cmComputeLinkInformation::Compute()
 {
+  bool use_wxneeded = false;
   // Skip targets that do not link.
   if (!(this->Target->GetType() == cmStateEnums::EXECUTABLE ||
         this->Target->GetType() == cmStateEnums::SHARED_LIBRARY ||
@@ -508,10 +510,17 @@ bool cmComputeLinkInformation::Compute()
     if (linkEntry.IsSharedDep) {
       this->AddSharedDepItem(linkEntry.Item, linkEntry.Target);
     } else {
+      std::string litem_tolower = linkEntry.Item.Value;
+      transform(litem_tolower.begin(), litem_tolower.end(), litem_tolower.begin(), ::tolower);
+      if (litem_tolower.find("webkit") != std::string::npos || litem_tolower.find("webengine") != std::string::npos)
+         use_wxneeded = true;
       this->AddItem(linkEntry.Item, linkEntry.Target);
     }
   }
 
+  if (use_wxneeded == true)
+    this->AddUserItem(std::string("-Wl,-z,wxneeded"), false);
+
   // Restore the target link type so the correct system runtime
   // libraries are found.
   cmProp lss = this->Target->GetProperty("LINK_SEARCH_END_STATIC");
@@ -703,10 +712,16 @@ void cmComputeLinkInformation::AddItem(BT<std::string>
         // This is a directory.
         this->AddDirectoryItem(item.Value);
       } else {
-        // Use the full path given to the library file.
         this->Depends.push_back(item.Value);
-        this->AddFullItem(item);
-        this->AddLibraryRuntimeInfo(item.Value);
+        if (!this->OpenBSD) {
+          // Use the full path given to the library file.
+          this->AddFullItem(item);
+          this->AddLibraryRuntimeInfo(item.Value);
+        } else {
+          std::string file = cmSystemTools::GetFilenameName(item.Value);
+          this->AddUserItem(file, false);
+          this->OrderLinkerSearchPath->AddLinkLibrary(item.Value);
+        }
       }
     } else {
       // This is a library or option specified by the user.
@@ -1036,11 +1051,18 @@ void cmComputeLinkInformation::AddTargetItem(BT<std::s
     this->SharedLibrariesLinked.insert(target);
   }
 
+  if (this->OpenBSD) {
+    if (target->GetType() == cmStateEnums::SHARED_LIBRARY) {
+      this->AddSharedLibNoSOName(item.Value);
+      return;
+    }
+  } else {
   // Handle case of an imported shared library with no soname.
-  if (this->NoSONameUsesPath &&
-      target->IsImportedSharedLibWithoutSOName(this->Config)) {
-    this->AddSharedLibNoSOName(item.Value);
-    return;
+    if (this->NoSONameUsesPath &&
+        target->IsImportedSharedLibWithoutSOName(this->Config)) {
+      this->AddSharedLibNoSOName(item.Value);
+      return;
+    }
   }
 
   // For compatibility with CMake 2.4 include the item's directory in
@@ -1053,6 +1075,27 @@ void cmComputeLinkInformation::AddTargetItem(BT<std::s
 
   // Now add the full path to the library.
   this->Items.emplace_back(item, true, target);
+}
+
+void cmComputeLinkInformation::LoadImplicitLinkInfoOpenBSD()
+{
+  std::vector<std::string> implicitDirVec;
+
+  // Get platform-wide implicit directories.
+  if (cmProp implicitLinks =
+        this->Makefile->GetDefinition("CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES")) {
+    this->Makefile->GetDefExpandList(*implicitLinks, implicitDirVec);
+  }
+
+  // Append library architecture to all implicit platform directories
+  // and add them to the set
+  if (cmProp libraryArch =
+        this->Makefile->GetDefinition("CMAKE_LIBRARY_ARCHITECTURE")) {
+    for (std::vector<std::string>::const_iterator i = implicitDirVec.begin();
+         i != implicitDirVec.end(); ++i) {
+      this->ImplicitLinkDirs.insert(*i + "/" + *libraryArch);
+    }
+   }
 }
 
 void cmComputeLinkInformation::AddFullItem(BT<std::string> const& item)
