From 811f00f9adca089323a1d4e2ddc9e9e4307e323e Mon Sep 17 00:00:00 2001 From: Marc Chevrier Date: Fri, 16 May 2025 17:39:19 +0200 Subject: FindPython: rely on ABIFLAGS on Windows for ABI profile Starting with Python 3.14, the config_var ABIFLAGS is now also available on Windows. --- Modules/FindPython/Support.cmake | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Modules/FindPython/Support.cmake b/Modules/FindPython/Support.cmake index c741ec1..9b89307 100644 --- a/Modules/FindPython/Support.cmake +++ b/Modules/FindPython/Support.cmake @@ -625,18 +625,16 @@ function (_PYTHON_GET_CONFIG_VAR _PYTHON_PGCV_VALUE NAME) set (_values "_d") endif() elseif (NAME STREQUAL "ABIFLAGS" AND WIN32) - # config var ABIFLAGS does not exist, check GIL specific variable + # config var ABIFLAGS does not exist for version < 3.14, check GIL specific variable execute_process (COMMAND ${_${_PYTHON_PREFIX}_INTERPRETER_LAUNCHER} "${_${_PYTHON_PREFIX}_EXECUTABLE}" -c - "import sys; import sysconfig; sys.stdout.write(str(sysconfig.get_config_var('Py_GIL_DISABLED')))" + "import sys\nimport sysconfig\ntry:\n sys.stdout.write(sysconfig.get_config_var('ABIFLAGS'))\nexcept Exception:\n sys.stdout.write('t' if sysconfig.get_config_var('Py_GIL_DISABLED') == 1 else '')" RESULT_VARIABLE _result OUTPUT_VARIABLE _values ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) - if (result OR NOT _values EQUAL "1") + if (_result OR NOT _values) # assume ABI is not supported or GIL is set set (_values "") - else() - set (_values "t") endif() else() set (config_flag "${NAME}") -- cgit v0.12 From 41a4a3213598fb6e1dbc16dbe6b94cc74566de5b Mon Sep 17 00:00:00 2001 From: Marc Chevrier Date: Fri, 16 May 2025 18:42:28 +0200 Subject: FindPython: Avoid implicit link library on Windows Starting with version 3.14, on Windows, by specifying macro Py_NO_LINK_LIB, the python library is no longer implicitly specified at the link step. Fixes: #26756 --- Modules/FindPython/Support.cmake | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Modules/FindPython/Support.cmake b/Modules/FindPython/Support.cmake index 9b89307..2997650 100644 --- a/Modules/FindPython/Support.cmake +++ b/Modules/FindPython/Support.cmake @@ -4069,7 +4069,11 @@ if(_${_PYTHON_PREFIX}_CMAKE_ROLE STREQUAL "PROJECT") set_property (TARGET ${__name} PROPERTY INTERFACE_COMPILE_DEFINITIONS "${${_PYTHON_PREFIX}_DEFINITIONS}") endif() - + if(WIN32) + # avoid implicit library link (recognized by version 3.14 and upper) + set_property (TARGET ${__name} + APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS "Py_NO_LINK_LIB") + endif() if (${_PYTHON_PREFIX}_${_PREFIX}LIBRARY_RELEASE AND ${_PYTHON_PREFIX}_RUNTIME_${_PREFIX}LIBRARY_RELEASE) # System manage shared libraries in two parts: import and runtime @@ -4131,6 +4135,11 @@ if(_${_PYTHON_PREFIX}_CMAKE_ROLE STREQUAL "PROJECT") set_property (TARGET ${__name} PROPERTY INTERFACE_COMPILE_DEFINITIONS "${${_PYTHON_PREFIX}_DEFINITIONS}") endif() + if(WIN32) + # avoid implicit library link (recognized by version 3.14 and upper) + set_property (TARGET ${__name} + APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS "Py_NO_LINK_LIB") + endif() # When available, enforce shared library generation with undefined symbols if (APPLE) -- cgit v0.12