From cd6fb6309328a9c113f1fe3c2b842d4650c81980 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 21 Nov 2024 18:18:33 -0500 Subject: AIX: Propagate AIX_SHARED_LIBRARY_ARCHIVE through exports Teach `export()` and `install(EXPORT)` to record this setting on the imported targets they generate. Make this property's non-presence authoritative on imported targets since they represent what was built elsewhere. --- Help/prop_tgt/AIX_SHARED_LIBRARY_ARCHIVE.rst | 6 ++++-- Help/variable/CMAKE_AIX_SHARED_LIBRARY_ARCHIVE.rst | 4 ++-- Source/cmExportCMakeConfigGenerator.cxx | 6 ++++++ Source/cmInstallImportedRuntimeArtifactsGenerator.cxx | 12 +++++++----- Source/cmTarget.cxx | 5 +++++ Tests/ExportImport/Export/CMakeLists.txt | 10 ++++++---- Tests/ExportImport/Export/testSharedLibArchiveAIX.c | 10 ---------- Tests/ExportImport/Export/testSharedObjectAIX.c | 10 ++++++++++ Tests/ExportImport/Import/A/CMakeLists.txt | 4 ++-- Tests/ExportImport/Import/A/imp_testExe1.c | 4 ++-- Tests/SharedLibraryArchive/CMakeLists.txt | 6 ++++++ 11 files changed, 50 insertions(+), 27 deletions(-) delete mode 100644 Tests/ExportImport/Export/testSharedLibArchiveAIX.c create mode 100644 Tests/ExportImport/Export/testSharedObjectAIX.c diff --git a/Help/prop_tgt/AIX_SHARED_LIBRARY_ARCHIVE.rst b/Help/prop_tgt/AIX_SHARED_LIBRARY_ARCHIVE.rst index d0106c5..9e81594 100644 --- a/Help/prop_tgt/AIX_SHARED_LIBRARY_ARCHIVE.rst +++ b/Help/prop_tgt/AIX_SHARED_LIBRARY_ARCHIVE.rst @@ -16,5 +16,7 @@ the :prop_tgt:`SOVERSION` target property, if set, and otherwise from the :prop_tgt:`VERSION` target property, if set. This property defaults to :variable:`CMAKE_AIX_SHARED_LIBRARY_ARCHIVE` -if that variable is set when a ``SHARED`` library target is created -by :command:`add_library`. +if that variable is set when a non-imported ``SHARED`` library target +is created by :command:`add_library`. Imported targets must explicitly +enable :prop_tgt:`!AIX_SHARED_LIBRARY_ARCHIVE` if they import an AIX +shared library archive. diff --git a/Help/variable/CMAKE_AIX_SHARED_LIBRARY_ARCHIVE.rst b/Help/variable/CMAKE_AIX_SHARED_LIBRARY_ARCHIVE.rst index 10fdf04..2b636c0 100644 --- a/Help/variable/CMAKE_AIX_SHARED_LIBRARY_ARCHIVE.rst +++ b/Help/variable/CMAKE_AIX_SHARED_LIBRARY_ARCHIVE.rst @@ -6,5 +6,5 @@ CMAKE_AIX_SHARED_LIBRARY_ARCHIVE On AIX, enable creation of shared library archives. This variable initializes the :prop_tgt:`AIX_SHARED_LIBRARY_ARCHIVE` -target property on ``SHARED`` library targets as they are created -by :command:`add_library`. See that target property for details. +target property on non-imported ``SHARED`` library targets as they are +created by :command:`add_library`. See that target property for details. diff --git a/Source/cmExportCMakeConfigGenerator.cxx b/Source/cmExportCMakeConfigGenerator.cxx index 4f4765c..e85d949 100644 --- a/Source/cmExportCMakeConfigGenerator.cxx +++ b/Source/cmExportCMakeConfigGenerator.cxx @@ -334,6 +334,12 @@ void cmExportCMakeConfigGenerator::GenerateImportTargetCode( os << "set_property(TARGET " << targetName << " PROPERTY BUNDLE 1)\n"; } + // Mark the imported library if it is an AIX shared library archive. + if (target->IsArchivedAIXSharedLibrary()) { + os << "set_property(TARGET " << targetName + << " PROPERTY AIX_SHARED_LIBRARY_ARCHIVE 1)\n"; + } + // generate DEPRECATION if (target->IsDeprecated()) { os << "set_property(TARGET " << targetName << " PROPERTY DEPRECATION " diff --git a/Source/cmInstallImportedRuntimeArtifactsGenerator.cxx b/Source/cmInstallImportedRuntimeArtifactsGenerator.cxx index 01980ac..79b18e5 100644 --- a/Source/cmInstallImportedRuntimeArtifactsGenerator.cxx +++ b/Source/cmInstallImportedRuntimeArtifactsGenerator.cxx @@ -107,11 +107,13 @@ void cmInstallImportedRuntimeArtifactsGenerator::GenerateScriptForConfig( } } else { std::vector files{ location }; - auto soName = this->Target->GetSOName(config); - auto soNameFile = - cmStrCat(this->Target->GetDirectory(config), '/', soName); - if (!soName.empty() && soNameFile != location) { - files.push_back(soNameFile); + if (!this->Target->IsArchivedAIXSharedLibrary()) { + auto soName = this->Target->GetSOName(config); + auto soNameFile = + cmStrCat(this->Target->GetDirectory(config), '/', soName); + if (!soName.empty() && soNameFile != location) { + files.push_back(soNameFile); + } } this->AddInstallRule(os, this->GetDestination(config), cmInstallType_SHARED_LIBRARY, files, diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index f220837..f1dcc76 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -1087,6 +1087,11 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type, } } + // Imported targets must set AIX_SHARED_LIBRARY_ARCHIVE explicitly. + if (this->IsImported() && property == "AIX_SHARED_LIBRARY_ARCHIVE"_s) { + return; + } + // Replace everything after "CMAKE_" defKey.replace(defKey.begin() + 6, defKey.end(), property); if (cmValue value = mf->GetDefinition(defKey)) { diff --git a/Tests/ExportImport/Export/CMakeLists.txt b/Tests/ExportImport/Export/CMakeLists.txt index 2cc2354..f6d32b8 100644 --- a/Tests/ExportImport/Export/CMakeLists.txt +++ b/Tests/ExportImport/Export/CMakeLists.txt @@ -5,6 +5,8 @@ if(POLICY CMP0129) endif() project(Export C CXX) +set(CMAKE_AIX_SHARED_LIBRARY_ARCHIVE 1) + find_package(Foo REQUIRED CONFIG NO_DEFAULT_PATH) # Pretend that RelWithDebInfo should link to debug libraries to test @@ -482,8 +484,8 @@ add_library(testMod1 MODULE empty.cpp) add_library(testMod2 MODULE empty.cpp) set_property(TARGET testMod2 PROPERTY BUNDLE 1) -add_library(testSharedLibArchiveAIX SHARED testSharedLibArchiveAIX.c) -set_property(TARGET testSharedLibArchiveAIX PROPERTY AIX_SHARED_LIBRARY_ARCHIVE 1) +add_library(testSharedObjectAIX SHARED testSharedObjectAIX.c) +set_property(TARGET testSharedObjectAIX PROPERTY AIX_SHARED_LIBRARY_ARCHIVE 0) install(TARGETS testLibRequired EXPORT RequiredExp DESTINATION lib @@ -625,7 +627,7 @@ install( systemlib testInterfaceIncludeUser testInterfaceIncludeUser2 - testSharedLibArchiveAIX + testSharedObjectAIX EXPORT exp RUNTIME DESTINATION $<1:bin>$<0:/wrong> LIBRARY DESTINATION $<1:lib>$<0:/wrong> NAMELINK_SKIP @@ -703,7 +705,7 @@ export(TARGETS testExe2 testLib4 testLib5 testLib6 testLib7 testExe3 testExe4 te testExeWithPluginHelper testExePluginHelperObj testMod1 testMod2 testLibPerConfigDest - testSharedLibArchiveAIX + testSharedObjectAIX NAMESPACE bld_ APPEND FILE ExportBuildTree.cmake ) diff --git a/Tests/ExportImport/Export/testSharedLibArchiveAIX.c b/Tests/ExportImport/Export/testSharedLibArchiveAIX.c deleted file mode 100644 index 25a29e0..0000000 --- a/Tests/ExportImport/Export/testSharedLibArchiveAIX.c +++ /dev/null @@ -1,10 +0,0 @@ -#if defined(_WIN32) || defined(__CYGWIN__) -# define EXPORT __declspec(dllexport) -#else -# define EXPORT -#endif - -EXPORT int testSharedLibArchiveAIX(void) -{ - return 0; -} diff --git a/Tests/ExportImport/Export/testSharedObjectAIX.c b/Tests/ExportImport/Export/testSharedObjectAIX.c new file mode 100644 index 0000000..9879c39 --- /dev/null +++ b/Tests/ExportImport/Export/testSharedObjectAIX.c @@ -0,0 +1,10 @@ +#if defined(_WIN32) || defined(__CYGWIN__) +# define EXPORT __declspec(dllexport) +#else +# define EXPORT +#endif + +EXPORT int testSharedObjectAIX(void) +{ + return 0; +} diff --git a/Tests/ExportImport/Import/A/CMakeLists.txt b/Tests/ExportImport/Import/A/CMakeLists.txt index 84a50a6..7d933a4 100644 --- a/Tests/ExportImport/Import/A/CMakeLists.txt +++ b/Tests/ExportImport/Import/A/CMakeLists.txt @@ -68,7 +68,7 @@ target_link_libraries(imp_testExe1 exp_testLib7 exp_testLibCycleA exp_testLibPerConfigDest - exp_testSharedLibArchiveAIX + exp_testSharedObjectAIX exp_testStaticLibWithPlugin ) @@ -124,7 +124,7 @@ target_link_libraries(imp_testExe1b bld_testLib7 bld_testLibCycleA bld_testLibPerConfigDest - bld_testSharedLibArchiveAIX + bld_testSharedObjectAIX bld_testStaticLibWithPlugin ) diff --git a/Tests/ExportImport/Import/A/imp_testExe1.c b/Tests/ExportImport/Import/A/imp_testExe1.c index 7f30c5d..554bf4b 100644 --- a/Tests/ExportImport/Import/A/imp_testExe1.c +++ b/Tests/ExportImport/Import/A/imp_testExe1.c @@ -11,7 +11,7 @@ extern int testLib7(void); extern int testLibCycleA1(void); extern int testLibPerConfigDest(void); extern int testStaticLibPlugin(void); -extern int testSharedLibArchiveAIX(void); +extern int testSharedObjectAIX(void); /* Switch a symbol between debug and optimized builds to make sure the proper library is found from the testLib4 link interface. */ @@ -27,6 +27,6 @@ int main(void) return (testLib2() + generated_by_testExe1() + testLib3() + testLib4() + testLib5() + testLib6() + testLib7() + testLibCycleA1() + testLibPerConfigDest() + testStaticLibPlugin() + - testSharedLibArchiveAIX() + generated_by_testExe3() + + testSharedObjectAIX() + generated_by_testExe3() + generated_by_testExe4() + testLib4lib() + testLib4libcfg()); } diff --git a/Tests/SharedLibraryArchive/CMakeLists.txt b/Tests/SharedLibraryArchive/CMakeLists.txt index f6bef24..cc961f1 100644 --- a/Tests/SharedLibraryArchive/CMakeLists.txt +++ b/Tests/SharedLibraryArchive/CMakeLists.txt @@ -36,3 +36,9 @@ if(aix_sla_versioned) message(FATAL_ERROR "AIX_SHARED_LIBRARY_ARCHIVE initialized on EXECUTABLE") endif() target_link_libraries(UseSLA_versioned PRIVATE sla_versioned) + +add_library(imported SHARED IMPORTED) +get_property(aix_sla TARGET imported PROPERTY AIX_SHARED_LIBRARY_ARCHIVE) +if(aix_sla) + message(FATAL_ERROR "AIX_SHARED_LIBRARY_ARCHIVE initialized on imported target") +endif() -- cgit v0.12