瀏覽代碼

Merge topic 'FindPython-free-threaded-python' into release-3.30

10abd2ac5a FindPython: ensure a usable environment is set for the free threaded Python

Acked-by: Kitware Robot <[email protected]>
Merge-request: !9775
Brad King 1 年之前
父節點
當前提交
a0317334ae
共有 4 個文件被更改,包括 45 次插入0 次删除
  1. 8 0
      Help/release/3.30.rst
  2. 5 0
      Modules/FindPython.cmake
  3. 27 0
      Modules/FindPython/Support.cmake
  4. 5 0
      Modules/FindPython3.cmake

+ 8 - 0
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.

+ 5 - 0
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
 

+ 27 - 0
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)
@@ -4066,6 +4082,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)
@@ -4122,6 +4144,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}

+ 5 - 0
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