Skip to content

Commit 1eb2c96

Browse files
committed
🐛 fix build module with python3.13t on windows #55
1 parent 3e00945 commit 1eb2c96

1 file changed

Lines changed: 37 additions & 2 deletions

File tree

CMakeLists.txt

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,55 @@ set(Python_FIND_REGISTRY "LAST")
2929
set(PYBIND11_FINDPYTHON ON)
3030
add_subdirectory(depends/pybind11)
3131
list(APPEND c104_tests_PRIVATE_LIBRARIES pybind11::embed)
32-
if(MSVC)
32+
if(WIN32)
3333
list(APPEND c104_tests_PRIVATE_LIBRARIES pybind11::windows_extras)
3434
endif()
3535
3636
# Run Python to check for GIL status
3737
execute_process(
3838
COMMAND
3939
${Python_EXECUTABLE} -c
40-
"import sysconfig; print(bool(sysconfig.get_config_var(\"Py_GIL_DISABLED\")) and 1 or 0)"
40+
"import sysconfig; print(bool(sysconfig.get_config_var('Py_GIL_DISABLED')) and 1 or 0)"
4141
OUTPUT_VARIABLE PYTHON_FREE_THREADED
4242
OUTPUT_STRIP_TRAILING_WHITESPACE)
4343
if(PYTHON_FREE_THREADED)
44+
# set Py_GIL_DISABLED=1 to build pybind11 for free threaded python
4445
list(APPEND c104_PRIVATE_DEFINITIONS Py_GIL_DISABLED=1)
4546
message(STATUS "Python is running without GIL (free threaded)")
47+
48+
# fix library path on windows
49+
if(WIN32 AND DEFINED Python_LIBRARY)
50+
get_filename_component(_PYTHON_LIB_DIR "${Python_LIBRARY}" DIRECTORY)
51+
get_filename_component(_PYTHON_LIB_NAME "${Python_LIBRARY}" NAME_WE)
52+
get_filename_component(_PYTHON_LIB_EXT "${Python_LIBRARY}" EXT)
53+
54+
# Check if library name already has 't' suffix
55+
if(NOT _PYTHON_LIB_NAME MATCHES "t$")
56+
set(_PYTHON_LIB_NAME "${_PYTHON_LIB_NAME}t")
57+
set(_CORRECTED_PYTHON_LIBRARY
58+
"${_PYTHON_LIB_DIR}/${_PYTHON_LIB_NAME}${_PYTHON_LIB_EXT}")
59+
60+
message(STATUS "Hotfix free-threaded Python library path:")
61+
message(STATUS " Original: ${Python_LIBRARY}")
62+
message(STATUS " Corrected: ${_CORRECTED_PYTHON_LIBRARY}")
63+
64+
# Verify the corrected library exists
65+
if(EXISTS "${_CORRECTED_PYTHON_LIBRARY}")
66+
set(Python_LIBRARY
67+
"${_CORRECTED_PYTHON_LIBRARY}"
68+
CACHE STRING "Path to Python library" FORCE)
69+
set(Python_LIBRARIES
70+
"${_CORRECTED_PYTHON_LIBRARY}"
71+
CACHE STRING "Python libraries" FORCE)
72+
else()
73+
message(
74+
WARNING
75+
"Corrected Python library file not found: ${_CORRECTED_PYTHON_LIBRARY}"
76+
)
77+
endif()
78+
endif()
79+
80+
endif()
4681
else()
4782
message(STATUS "Python is running with GIL (classic)")
4883
endif()

0 commit comments

Comments
 (0)