From e12e5e056610c5768fd04fbed22937989a5aba2c Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 10 Oct 2024 13:10:13 -0400 Subject: cmGeneratorTarget: Simplify ComputeVersionedName signature --- Source/cmGeneratorTarget.cxx | 34 ++++++++++++++++++---------------- Source/cmGeneratorTarget.h | 8 +++++--- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 20c5dca..b99f01f 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -3438,14 +3438,14 @@ cmGeneratorTarget::Names cmGeneratorTarget::GetLibraryNames( cmStrCat(components.prefix, targetNames.Base, components.suffix); } 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 +3468,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 +4154,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 cmGeneratorTarget::GetPropertyKeys() const diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h index 525cef0..8ae98e8 100644 --- a/Source/cmGeneratorTarget.h +++ b/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 CustomTransitiveBuildPropertiesMap; -- cgit v0.12 From 7fb05af311f8f49a36ecd3bd5ead19de845cf7b3 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 10 Oct 2024 13:18:01 -0400 Subject: cmGeneratorTarget: Simplify AIX shared library archive name computation --- Source/cmGeneratorTarget.cxx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index b99f01f..8bac4a1 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -3434,8 +3434,7 @@ 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); + targetNames.Real = targetNames.Output; } else { // The library's soname. targetNames.SharedObject = this->ComputeVersionedName( -- cgit v0.12 From dc8e4f8f0cf4ca8224ca4f791974362740aba465 Mon Sep 17 00:00:00 2001 From: Aditya Vidyadhar Kamath Date: Thu, 10 Oct 2024 05:16:28 -0500 Subject: AIX: Enable versioned shared objects with CMAKE_AIX_SHARED_LIBRARY_ARCHIVE Closes: #26358 --- Source/cmGeneratorTarget.cxx | 9 +++++++-- Tests/SharedLibraryArchive/CMakeLists.txt | 6 ++++-- Tests/SharedLibraryArchive/sla-check.cmake | 11 ++++++++--- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 8bac4a1..fb92771 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/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,6 +3435,10 @@ cmGeneratorTarget::Names cmGeneratorTarget::GetLibraryNames( } else if (this->IsArchivedAIXSharedLibrary()) { targetNames.SharedObject = cmStrCat(components.prefix, targetNames.Base, ".so"); + if (soversion) { + targetNames.SharedObject += "."; + targetNames.SharedObject += *soversion; + } targetNames.Real = targetNames.Output; } else { // The library's soname. diff --git a/Tests/SharedLibraryArchive/CMakeLists.txt b/Tests/SharedLibraryArchive/CMakeLists.txt index 3af0f76..f6bef24 100644 --- a/Tests/SharedLibraryArchive/CMakeLists.txt +++ b/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=$ -P${CMAKE_CURRENT_SOURCE_DIR}/sla-check.cmake + COMMAND ${CMAKE_COMMAND} -DCMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME} -Dsla=$ -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=$ -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) diff --git a/Tests/SharedLibraryArchive/sla-check.cmake b/Tests/SharedLibraryArchive/sla-check.cmake index bc1fee5..90a0de4 100644 --- a/Tests/SharedLibraryArchive/sla-check.cmake +++ b/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() -- cgit v0.12