Skip to content

Commit

Permalink
Select Python 3.7+ stable ABI "manually" if CMake doesn't support it
Browse files Browse the repository at this point in the history
  • Loading branch information
encukou committed Oct 3, 2023
1 parent 69db01e commit 1f41d7e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
7 changes: 4 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ option(ENABLE_CUTF8 "Enable C.UTF-8 as default locale" ON)
option(ENABLE_NLS "Enable native language support" ON)
option(ENABLE_OPENMP "Enable OpenMP threading support" ON)
option(ENABLE_PYTHON "Enable Python bindings" ON)
cmake_dependent_option(
ENABLE_PYTHON_SABI "Build Python bindings with the Stable ABI" ON
"ENABLE_PYTHON; CMAKE_VERSION VERSION_GREATER_EQUAL 3.26" OFF)
option(ENABLE_PLUGINS "Enable plugin support" ON)
option(ENABLE_WERROR "Stop build on warnings" OFF)
option(ENABLE_SQLITE "Enable sqlite rpmdb support" ON)
Expand Down Expand Up @@ -237,6 +234,10 @@ if (ENABLE_BDB_RO)
endif()
list(APPEND db_backends dummy)

cmake_dependent_option(ENABLE_PYTHON_SABI
"Use CMake's mechanism for Python Stable ABI. Needs Python 3.7+."
ON "ENABLE_PYTHON; CMAKE_VERSION VERSION_GREATER_EQUAL 3.26" OFF
)
if (ENABLE_PYTHON)
if (ENABLE_PYTHON_SABI)
find_package(Python3 3.7 COMPONENTS Interpreter Development.SABIModule REQUIRED)
Expand Down
5 changes: 5 additions & 0 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,14 @@ set (sources
)

if (ENABLE_PYTHON_SABI)
# Use CMake's support for Python stable ABI
Python3_add_library(_rpm USE_SABI 3.7 ${sources})
else ()
Python3_add_library(_rpm ${sources})
if (PYTHON_VERSION VERSION_GREATER_EQUAL 3.7)
# Select Python stable ABI "manually" on Python 3.7+
target_compile_definitions(_rpm PRIVATE Py_LIMITED_API=0x03070000)
endif ()
endif ()

target_link_libraries(_rpm PRIVATE librpmio librpm librpmbuild librpmsign)
Expand Down

0 comments on commit 1f41d7e

Please sign in to comment.