summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Chevrier <marc.chevrier@gmail.com>2024-08-22 17:23:07 (GMT)
committerBrad King <brad.king@kitware.com>2024-08-27 13:27:35 (GMT)
commit10abd2ac5a9dd8dd3b8d48c2e1735d813fe2aab0 (patch)
tree84beb74ae8edb76e4388cc9c2e16945cc4f740d5
parent0e217de3437699cb1133a04fb1670489378e22dd (diff)
downloadCMake-10abd2ac5a9dd8dd3b8d48c2e1735d813fe2aab0.zip
CMake-10abd2ac5a9dd8dd3b8d48c2e1735d813fe2aab0.tar.gz
CMake-10abd2ac5a9dd8dd3b8d48c2e1735d813fe2aab0.tar.bz2
FindPython: ensure a usable environment is set for the free threaded Python
Define the `Python_DEFINITIONS` variable for the support of free threaded Python developments on Windows. This is a complement to commit 9a0dee7257 (FindPython: Add support for free threaded python, 2024-05-30).
-rw-r--r--Help/release/3.30.rst8
-rw-r--r--Modules/FindPython.cmake5
-rw-r--r--Modules/FindPython/Support.cmake27
-rw-r--r--Modules/FindPython3.cmake5
4 files changed, 45 insertions, 0 deletions
diff --git a/Help/release/3.30.rst b/Help/release/3.30.rst
index 2d57249..ca35d1f 100644
--- a/Help/release/3.30.rst
+++ b/Help/release/3.30.rst
@@ -254,3 +254,11 @@ Changes made since CMake 3.30.0 include the following.
* These versions made no changes to documented features or interfaces.
Some implementation updates were made to support ecosystem changes
and/or fix regressions.
+
+.. 3.30.3 (unreleased)
+
+ * The :module:`FindPython` and :module:`FindPython3` modules now define,
+ respectively, the ``Python_DEFINITIONS`` and ``Python3_DEFINITIONS``
+ variables on Windows to support development with the free threaded
+ version of Python. The :prop_tgt:`INTERFACE_COMPILE_DEFINITIONS` target
+ property is also defined for the various targets provided by these modules.
diff --git a/Modules/FindPython.cmake b/Modules/FindPython.cmake
index 345afc5..58e1348 100644
--- a/Modules/FindPython.cmake
+++ b/Modules/FindPython.cmake
@@ -224,6 +224,11 @@ This module will set the following variables in your project
The Python include directories.
+``Python_DEFINITIONS``
+ .. versionadded:: 3.30.3
+
+ The Python preprocessor definitions.
+
``Python_DEBUG_POSTFIX``
.. versionadded.. 3.30
diff --git a/Modules/FindPython/Support.cmake b/Modules/FindPython/Support.cmake
index 1386117..2f45c1e 100644
--- a/Modules/FindPython/Support.cmake
+++ b/Modules/FindPython/Support.cmake
@@ -3740,6 +3740,14 @@ if (("Development.Module" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS
_${_PYTHON_PREFIX}_RUNTIME_LIBRARY_RELEASE
_${_PYTHON_PREFIX}_RUNTIME_LIBRARY_DEBUG)
endif()
+
+ if (WIN32 AND _${_PYTHON_PREFIX}_LIBRARY_RELEASE MATCHES "t${CMAKE_IMPORT_LIBRARY_SUFFIX}$")
+ # On windows, header file is shared between the different implementations
+ # So Py_GIL_DISABLED should be set explicitly
+ set (${_PYTHON_PREFIX}_DEFINITIONS Py_GIL_DISABLED=1)
+ else()
+ unset (${_PYTHON_PREFIX}_DEFINITIONS)
+ endif()
endif()
if ("SABI_LIBRARY" IN_LIST _${_PYTHON_PREFIX}_FIND_DEVELOPMENT_ARTIFACTS)
@@ -3769,6 +3777,14 @@ if (("Development.Module" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS
_${_PYTHON_PREFIX}_RUNTIME_SABI_LIBRARY_RELEASE
_${_PYTHON_PREFIX}_RUNTIME_SABI_LIBRARY_DEBUG)
endif()
+
+ if (WIN32 AND _${_PYTHON_PREFIX}_SABI_LIBRARY_RELEASE MATCHES "t${CMAKE_IMPORT_LIBRARY_SUFFIX}$")
+ # On windows, header file is shared between the different implementations
+ # So Py_GIL_DISABLED should be set explicitly
+ set (${_PYTHON_PREFIX}_DEFINITIONS Py_GIL_DISABLED=1)
+ else()
+ unset (${_PYTHON_PREFIX}_DEFINITIONS)
+ endif()
endif()
if (_${_PYTHON_PREFIX}_LIBRARY_RELEASE OR _${_PYTHON_PREFIX}_SABI_LIBRARY_RELEASE OR _${_PYTHON_PREFIX}_INCLUDE_DIR)
@@ -4067,6 +4083,12 @@ if(_${_PYTHON_PREFIX}_CMAKE_ROLE STREQUAL "PROJECT")
set_property (TARGET ${__name}
PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${${_PYTHON_PREFIX}_INCLUDE_DIRS}")
+ if (${_PYTHON_PREFIX}_DEFINITIONS)
+ set_property (TARGET ${__name}
+ PROPERTY INTERFACE_COMPILE_DEFINITIONS "${${_PYTHON_PREFIX}_DEFINITIONS}")
+ endif()
+
+
if (${_PYTHON_PREFIX}_${_PREFIX}LIBRARY_RELEASE AND ${_PYTHON_PREFIX}_RUNTIME_${_PREFIX}LIBRARY_RELEASE)
# System manage shared libraries in two parts: import and runtime
if (${_PYTHON_PREFIX}_${_PREFIX}LIBRARY_RELEASE AND ${_PYTHON_PREFIX}_${_PREFIX}LIBRARY_DEBUG)
@@ -4123,6 +4145,11 @@ if(_${_PYTHON_PREFIX}_CMAKE_ROLE STREQUAL "PROJECT")
set_property (TARGET ${__name}
PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${${_PYTHON_PREFIX}_INCLUDE_DIRS}")
+ if (${_PYTHON_PREFIX}_DEFINITIONS)
+ set_property (TARGET ${__name}
+ PROPERTY INTERFACE_COMPILE_DEFINITIONS "${${_PYTHON_PREFIX}_DEFINITIONS}")
+ endif()
+
# When available, enforce shared library generation with undefined symbols
if (APPLE)
set_property (TARGET ${__name}
diff --git a/Modules/FindPython3.cmake b/Modules/FindPython3.cmake
index 9002209..55d33a2 100644
--- a/Modules/FindPython3.cmake
+++ b/Modules/FindPython3.cmake
@@ -226,6 +226,11 @@ This module will set the following variables in your project
The Python 3 include directories.
+``Python3_DEFINITIONS``
+ .. versionadded:: 3.30.3
+
+ The Python 3 preprocessor definitions.
+
``Python3_DEBUG_POSTFIX``
.. versionadded.. 3.30