AIX: Enable shared library archives by default

This is the preferred convention for shared libraries on AIX.
Add policy CMP0182 to provide compatibility.

Closes: #26372
This commit is contained in:
Brad King 2024-11-20 14:49:25 -05:00
parent 7a05e8e994
commit 5c78623143
9 changed files with 99 additions and 6 deletions

View File

@ -57,6 +57,7 @@ Policies Introduced by CMake 3.32
.. toctree::
:maxdepth: 1
CMP0182: Create shared library archives by default on AIX. </policy/CMP0182>
CMP0181: Link command-line fragment variables are parsed and re-quoted. </policy/CMP0181>
Policies Introduced by CMake 3.31

31
Help/policy/CMP0182.rst Normal file
View File

@ -0,0 +1,31 @@
CMP0182
-------
.. versionadded:: 3.32
Create shared library archives by default on AIX.
CMake 3.30 and below always represented ``SHARED`` library targets
as plain shared object ``.so`` files. This is consistent with other
UNIX platforms, but is not the preferred convention on AIX.
CMake 3.31 added the :prop_tgt:`AIX_SHARED_LIBRARY_ARCHIVE` target
property to create a shared library archive: the shared object ``.so``
file is placed inside an archive ``.a`` file. However, the behavior
was disabled by default for compatibility with existing projects that
do not set :prop_tgt:`AIX_SHARED_LIBRARY_ARCHIVE`.
CMake 3.32 and above prefer, when :prop_tgt:`AIX_SHARED_LIBRARY_ARCHIVE`
is not set, to enable creation of shared library archives by default
because it is the preferred convention on AIX. This policy provides
compatibility for projects that have not been updated.
The ``OLD`` behavior for this policy is to disable shared library
archives when :prop_tgt:`AIX_SHARED_LIBRARY_ARCHIVE` is not set.
The ``NEW`` behavior for this policy is to enable shared library
archives when :prop_tgt:`AIX_SHARED_LIBRARY_ARCHIVE` is not set.
.. |INTRODUCED_IN_CMAKE_VERSION| replace:: 3.32
.. |WARNS_OR_DOES_NOT_WARN| replace:: does *not* warn
.. include:: STANDARD_ADVICE.txt
.. include:: DEPRECATED.txt

View File

@ -22,5 +22,13 @@ 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.
For a non-imported target, if this property is not set, the
default is *disabled*.
.. versionchanged:: 3.32
For a non-imported target, if this property is not set, the
default is *enabled*. See policy :policy:`CMP0182`.
In CMake 3.31, policy :policy:`CMP0182` did not exist,
so the default was *disabled*.
In CMake 3.30 and lower, :prop_tgt:`!AIX_SHARED_LIBRARY_ARCHIVE`
did not exist, so the default was *disabled*.

View File

@ -0,0 +1,5 @@
aix-archive-shared-libraries
----------------------------
* On AIX, ``SHARED`` library targets now produce a shared library archive
by default. See policy :policy:`CMP0182`.

View File

@ -548,7 +548,9 @@ class cmMakefile;
31, 0, WARN) \
SELECT(POLICY, CMP0181, \
"Link command-line fragment variables are parsed and re-quoted.", 3, \
32, 0, WARN)
32, 0, WARN) \
SELECT(POLICY, CMP0182, \
"Create shared library archives by default on AIX.", 3, 32, 0, WARN)
#define CM_SELECT_ID(F, A1, A2, A3, A4, A5, A6) F(A1)
#define CM_FOR_EACH_POLICY_ID(POLICY) \
@ -594,7 +596,8 @@ class cmMakefile;
F(CMP0160) \
F(CMP0162) \
F(CMP0179) \
F(CMP0181)
F(CMP0181) \
F(CMP0182)
#define CM_FOR_EACH_CUSTOM_COMMAND_POLICY(F) \
F(CMP0116) \

View File

@ -1307,8 +1307,25 @@ bool cmTarget::IsFrameworkOnApple() const
bool cmTarget::IsArchivedAIXSharedLibrary() const
{
return (this->GetType() == cmStateEnums::SHARED_LIBRARY && this->IsAIX() &&
this->GetPropertyAsBool("AIX_SHARED_LIBRARY_ARCHIVE"));
if (this->GetType() == cmStateEnums::SHARED_LIBRARY && this->IsAIX()) {
cmValue value = this->GetProperty("AIX_SHARED_LIBRARY_ARCHIVE");
if (!value.IsEmpty()) {
return value.IsOn();
}
if (this->IsImported()) {
return false;
}
switch (this->GetPolicyStatusCMP0182()) {
case cmPolicies::WARN:
case cmPolicies::OLD:
// The OLD behavior's default is to disable shared library archives.
break;
case cmPolicies::NEW:
// The NEW behavior's default is to enable shared library archives.
return true;
}
}
return false;
}
bool cmTarget::IsAppBundleOnApple() const

View File

@ -45,6 +45,7 @@
\* CMP0162
\* CMP0179
\* CMP0181
\* CMP0182
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)

View File

@ -42,3 +42,24 @@ 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()
unset(CMAKE_AIX_SHARED_LIBRARY_ARCHIVE)
cmake_policy(SET CMP0182 NEW)
add_library(sla_CMP0182 SHARED sla.c)
get_property(aix_sla_CMP0182 TARGET sla_CMP0182 PROPERTY AIX_SHARED_LIBRARY_ARCHIVE)
if(aix_sla_CMP0182)
message(FATAL_ERROR "AIX_SHARED_LIBRARY_ARCHIVE initialized without CMAKE_AIX_SHARED_LIBRARY_ARCHIVE")
endif()
add_custom_command(TARGET sla_CMP0182 POST_BUILD VERBATIM
COMMAND ${CMAKE_COMMAND} -DCMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME} -Dsla=$<TARGET_FILE:sla_CMP0182> -Dname=sla_CMP0182 -Dsoversion= -P${CMAKE_CURRENT_SOURCE_DIR}/sla-check.cmake
)
add_executable(UseSLA_CMP0182 use_sla.c)
target_link_libraries(UseSLA_CMP0182 PRIVATE sla_CMP0182)
add_library(nosla_CMP0182 SHARED sla.c)
set_property(TARGET nosla_CMP0182 PROPERTY AIX_SHARED_LIBRARY_ARCHIVE OFF)
add_custom_command(TARGET nosla_CMP0182 POST_BUILD VERBATIM
COMMAND ${CMAKE_COMMAND} -DCMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME} -Dnosla=$<TARGET_FILE:nosla_CMP0182> -Dname=nosla_CMP0182 -P${CMAKE_CURRENT_SOURCE_DIR}/nosla-check.cmake
)

View File

@ -0,0 +1,6 @@
if(CMAKE_SYSTEM_NAME STREQUAL "AIX")
set(nosla_regex "/lib${name}\\.so$")
if(NOT nosla MATCHES "${nosla_regex}")
message(FATAL_ERROR "nosla library does not look like a shared object:\n ${nosla}")
endif()
endif()