Browse Source

Merge topic 'aix-archive-shared-libraries' into release-3.31

dc8e4f8f0c AIX: Enable versioned shared objects with CMAKE_AIX_SHARED_LIBRARY_ARCHIVE
7fb05af311 cmGeneratorTarget: Simplify AIX shared library archive name computation
e12e5e0566 cmGeneratorTarget: Simplify ComputeVersionedName signature

Acked-by: Kitware Robot <[email protected]>
Acked-by: buildbot <[email protected]>
Merge-request: !9894
Brad King 1 năm trước cách đây
mục cha
commit
18d60772ef

+ 26 - 20
Source/cmGeneratorTarget.cxx

@@ -1309,7 +1309,8 @@ bool cmGeneratorTarget::HasSOName(const std::string& config) const
   // and then only when the platform supports an soname flag.
   return ((this->GetType() == cmStateEnums::SHARED_LIBRARY) &&
           !this->GetPropertyAsBool("NO_SONAME") &&
-          this->Makefile->GetSONameFlag(this->GetLinkerLanguage(config)));
+          (this->Makefile->GetSONameFlag(this->GetLinkerLanguage(config)) ||
+           this->IsArchivedAIXSharedLibrary()));
 }
 
 bool cmGeneratorTarget::NeedRelinkBeforeInstall(
@@ -3398,7 +3399,7 @@ cmGeneratorTarget::Names cmGeneratorTarget::GetLibraryNames(
   cmValue soversion = this->GetProperty("SOVERSION");
   if (!this->HasSOName(config) ||
       this->Makefile->IsOn("CMAKE_PLATFORM_NO_VERSIONED_SONAME") ||
-      this->IsFrameworkOnApple() || this->IsArchivedAIXSharedLibrary()) {
+      this->IsFrameworkOnApple()) {
     // Versioning is supported only for shared libraries and modules,
     // and then only when the platform supports an soname flag.
     version = nullptr;
@@ -3434,18 +3435,21 @@ cmGeneratorTarget::Names cmGeneratorTarget::GetLibraryNames(
   } else if (this->IsArchivedAIXSharedLibrary()) {
     targetNames.SharedObject =
       cmStrCat(components.prefix, targetNames.Base, ".so");
-    targetNames.Real =
-      cmStrCat(components.prefix, targetNames.Base, components.suffix);
+    if (soversion) {
+      targetNames.SharedObject += ".";
+      targetNames.SharedObject += *soversion;
+    }
+    targetNames.Real = targetNames.Output;
   } else {
     // The library's soname.
-    this->ComputeVersionedName(targetNames.SharedObject, components.prefix,
-                               targetNames.Base, components.suffix,
-                               targetNames.Output, soversion);
+    targetNames.SharedObject = this->ComputeVersionedName(
+      components.prefix, targetNames.Base, components.suffix,
+      targetNames.Output, soversion);
 
     // The library's real name on disk.
-    this->ComputeVersionedName(targetNames.Real, components.prefix,
-                               targetNames.Base, components.suffix,
-                               targetNames.Output, version);
+    targetNames.Real = this->ComputeVersionedName(
+      components.prefix, targetNames.Base, components.suffix,
+      targetNames.Output, version);
   }
 
   // The import library names.
@@ -3468,14 +3472,13 @@ cmGeneratorTarget::Names cmGeneratorTarget::GetLibraryNames(
       targetNames.ImportLibrary = targetNames.ImportOutput;
     } else {
       // The import library's soname.
-      this->ComputeVersionedName(
-        targetNames.ImportLibrary, importComponents.prefix,
-        importComponents.base, importComponents.suffix,
-        targetNames.ImportOutput, soversion);
+      targetNames.ImportLibrary = this->ComputeVersionedName(
+        importComponents.prefix, importComponents.base,
+        importComponents.suffix, targetNames.ImportOutput, soversion);
 
       // The import library's real name on disk.
-      this->ComputeVersionedName(
-        targetNames.ImportReal, importComponents.prefix, importComponents.base,
+      targetNames.ImportReal = this->ComputeVersionedName(
+        importComponents.prefix, importComponents.base,
         importComponents.suffix, targetNames.ImportOutput, version);
     }
   }
@@ -4155,16 +4158,19 @@ std::string cmGeneratorTarget::GetFrameworkVersion() const
   return "A";
 }
 
-void cmGeneratorTarget::ComputeVersionedName(
-  std::string& vName, std::string const& prefix, std::string const& base,
-  std::string const& suffix, std::string const& name, cmValue version) const
+std::string cmGeneratorTarget::ComputeVersionedName(std::string const& prefix,
+                                                    std::string const& base,
+                                                    std::string const& suffix,
+                                                    std::string const& name,
+                                                    cmValue version) const
 {
-  vName = this->IsApple() ? (prefix + base) : name;
+  std::string vName = this->IsApple() ? (prefix + base) : name;
   if (version) {
     vName += ".";
     vName += *version;
   }
   vName += this->IsApple() ? suffix : std::string();
+  return vName;
 }
 
 std::vector<std::string> cmGeneratorTarget::GetPropertyKeys() const

+ 5 - 3
Source/cmGeneratorTarget.h

@@ -1182,9 +1182,11 @@ private:
   // Returns ARCHIVE, LIBRARY, or RUNTIME based on platform and type.
   const char* GetOutputTargetType(cmStateEnums::ArtifactType artifact) const;
 
-  void ComputeVersionedName(std::string& vName, std::string const& prefix,
-                            std::string const& base, std::string const& suffix,
-                            std::string const& name, cmValue version) const;
+  std::string ComputeVersionedName(std::string const& prefix,
+                                   std::string const& base,
+                                   std::string const& suffix,
+                                   std::string const& name,
+                                   cmValue version) const;
 
   mutable std::map<std::string, CustomTransitiveProperties>
     CustomTransitiveBuildPropertiesMap;

+ 4 - 2
Tests/SharedLibraryArchive/CMakeLists.txt

@@ -9,7 +9,7 @@ if(NOT aix_sla)
   message(FATAL_ERROR "AIX_SHARED_LIBRARY_ARCHIVE not initialized on SHARED library")
 endif()
 add_custom_command(TARGET sla POST_BUILD VERBATIM
-  COMMAND ${CMAKE_COMMAND} -DCMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME} -Dsla=$<TARGET_FILE:sla> -P${CMAKE_CURRENT_SOURCE_DIR}/sla-check.cmake
+  COMMAND ${CMAKE_COMMAND} -DCMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME} -Dsla=$<TARGET_FILE:sla> -Dname=sla -Dsoversion= -P${CMAKE_CURRENT_SOURCE_DIR}/sla-check.cmake
   )
 
 add_executable(UseSLA use_sla.c)
@@ -25,8 +25,10 @@ get_property(aix_sla_versioned TARGET sla_versioned PROPERTY AIX_SHARED_LIBRARY_
 if(NOT aix_sla_versioned)
   message(FATAL_ERROR "AIX_SHARED_LIBRARY_ARCHIVE not initialized on SHARED library")
 endif()
-
 set_target_properties(sla_versioned PROPERTIES OUTPUT_NAME "sla_versioned" VERSION 3 SOVERSION 2)
+add_custom_command(TARGET sla_versioned POST_BUILD VERBATIM
+  COMMAND ${CMAKE_COMMAND} -DCMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME} -Dsla=$<TARGET_FILE:sla_versioned> -Dname=sla_versioned -Dsoversion=2 -P${CMAKE_CURRENT_SOURCE_DIR}/sla-check.cmake
+  )
 
 add_executable(UseSLA_versioned use_sla.c)
 get_property(aix_sla_versioned TARGET UseSLA_versioned PROPERTY AIX_SHARED_LIBRARY_ARCHIVE)

+ 8 - 3
Tests/SharedLibraryArchive/sla-check.cmake

@@ -1,9 +1,14 @@
 if(CMAKE_SYSTEM_NAME STREQUAL "AIX")
-  if(NOT sla MATCHES [[/libsla\.a]])
+  set(sla_regex "/lib${name}\\.a$")
+  if(NOT sla MATCHES "${sla_regex}")
     message(FATAL_ERROR "sla library does not look like an archive:\n ${sla}")
   endif()
   execute_process(COMMAND ar t ${sla} OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE sla_members)
-  if(NOT sla_members MATCHES [[^libsla\.so]])
-    message(FATAL_ERROR "sla library archive does not have expected members:\n ${sla_members}")
+  if(soversion)
+    set(soversion_regex "\\.${soversion}")
+  endif()
+  set(sla_members_regex "^lib${name}\\.so${soversion_regex}$")
+  if(NOT sla_members MATCHES "${sla_members_regex}")
+    message(FATAL_ERROR "sla library archive has members:\n ${sla_members}\nthat do not match:\n ${sla_members_regex}")
   endif()
 endif()