@@ -36,7 +36,8 @@ related to making Python extension modules.
3636
3737If you are making a Limited API / Stable ABI package, you'll need the
3838` Development.SABIModule ` component instead (CMake 3.26+). You can use the
39- ` SKBUILD_SABI_COMPONENT ` variable to check to see if it was requested.
39+ ` SKBUILD_SABI_COMPONENT ` variable to check to see if it was requested. You can
40+ get the version requested with ` ${SKBUILD_SABI_VERSION} ` .
4041
4142<!-- prettier-ignore-start -->
4243:::{warning}
@@ -142,13 +143,25 @@ When defining your module, if you only support the Stable ABI after some point,
142143you should use (for example for 3.11):
143144
144145``` cmake
145- if(NOT "${SKBUILD_SABI_COMPONENT }" STREQUAL "")
146- python_add_library(some_ext MODULE WITH_SOABI USE_SABI 3.11 ...)
146+ if(NOT "${SKBUILD_SABI_VERSION }" STREQUAL "")
147+ python_add_library(some_ext MODULE WITH_SOABI USE_SABI ${SKBUILD_SABI_VERSION} ...)
147148else()
148149 python_add_library(some_ext MODULE WITH_SOABI ...)
149150endif()
150151```
151152
153+ If you have a lot of libraries, you can conditionally save these two items into
154+ a variable with ` set(USE_SABI USE_SABI ${SKBUILD_SABI_VERSION}) ` and use it in
155+ all your ` python_add_library ` calls:
156+
157+ ```
158+ if(NOT "${SKBUILD_SABI_VERSION}" STREQUAL "")
159+ set(USE_SABI "USE_SABI ${SKBUILD_SABI_VERSION}")
160+ endif()
161+
162+ python_add_library(some_ext MODULE WITH_SOABI ${USE_SABI} ...)
163+ ```
164+
152165This will define ` Py_LIMITED_API ` for you. If you want to support building
153166directly from CMake, you need to protect this for Python version,
154167` Python_INTERPRETER_ID STREQUAL Python ` , and free-threading Python 3.13+ doesn't
0 commit comments