diff --git a/CMakeLists.txt b/CMakeLists.txt index 53357b894d..6d0d45a20c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) @@ -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) diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index 11acf3f362..012b93e9e8 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -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=Py_LIMITED_API=0x03070000) + endif () endif () target_link_libraries(_rpm PRIVATE librpmio librpm librpmbuild librpmsign)