$OpenBSD: patch-Source_cmComputeLinkInformation_cxx,v 1.24 2020/01/11 08:01:09 rsadowski Exp $
Index: Source/cmComputeLinkInformation.cxx
--- Source/cmComputeLinkInformation.cxx.orig
+++ Source/cmComputeLinkInformation.cxx
@@ -369,8 +369,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);
@@ -485,6 +486,8 @@ 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 ||
@@ -511,10 +514,17 @@ bool cmComputeLinkInformation::Compute()
     if (linkEntry.IsSharedDep) {
       this->AddSharedDepItem(linkEntry.Item, linkEntry.Target);
     } else {
+      std::string litem_tolower = linkEntry.Item;
+      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("-Wl,-z,wxneeded", false);
+
   // Restore the target link type so the correct system runtime
   // libraries are found.
   const char* lss = this->Target->GetProperty("LINK_SEARCH_END_STATIC");
@@ -677,10 +687,16 @@ void cmComputeLinkInformation::AddItem(std::string con
         // This is a directory.
         this->AddDirectoryItem(item);
       } else {
-        // Use the full path given to the library file.
         this->Depends.push_back(item);
-        this->AddFullItem(item);
-        this->AddLibraryRuntimeInfo(item);
+        if (!this->OpenBSD) {
+          // Use the full path given to the library file.
+          this->AddFullItem(item);
+          this->AddLibraryRuntimeInfo(item);
+        } else {
+          std::string file = cmSystemTools::GetFilenameName(item);
+          this->AddUserItem(file, false);
+          this->OrderLinkerSearchPath->AddLinkLibrary(item);
+        }
       }
     } else {
       // This is a library or option specified by the user.
@@ -1012,11 +1028,18 @@ void cmComputeLinkInformation::AddTargetItem(std::stri
     this->SharedLibrariesLinked.insert(target);
   }
 
-  // Handle case of an imported shared library with no soname.
-  if (this->NoSONameUsesPath &&
-      target->IsImportedSharedLibWithoutSOName(this->Config)) {
-    this->AddSharedLibNoSOName(item);
-    return;
+  if (this->OpenBSD) {
+    if (target->GetType() == cmStateEnums::SHARED_LIBRARY) {
+      this->AddSharedLibNoSOName(item);
+      return;
+    }
+  } else {
+    // Handle case of an imported shared library with no soname.
+    if (this->NoSONameUsesPath &&
+        target->IsImportedSharedLibWithoutSOName(this->Config)) {
+      this->AddSharedLibNoSOName(item);
+      return;
+    }
   }
 
   // For compatibility with CMake 2.4 include the item's directory in
@@ -1575,6 +1598,27 @@ void cmComputeLinkInformation::LoadImplicitLinkInfo()
   if (const char* rpathDirs =
         (this->Makefile->GetDefinition("CMAKE_PLATFORM_RUNTIME_PATH"))) {
     cmExpandList(rpathDirs, this->RuntimeLinkDirs);
+  }
+}
+
+void cmComputeLinkInformation::LoadImplicitLinkInfoOpenBSD()
+{
+  std::vector<std::string> implicitDirVec;
+
+  // Get platform-wide implicit directories.
+  if (const char* implicitLinks = (this->Makefile->GetDefinition(
+        "CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES"))) {
+    cmExpandList(implicitLinks, implicitDirVec);
+  }
+
+  // Append library architecture to all implicit platform directories
+  // and add them to the set
+  if (const char* 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);
+    }
   }
 }
 
