Skip to content

Commit 6b10b7f

Browse files
committed
COMP: Fix Python3_LIBRARY to use version-specific library for FindPython3
For Python >= 3.11, use python311.lib (version-specific) for Python3_LIBRARY instead of python3.lib (stable ABI). CMake's FindPython3 needs the version in the filename to extract major.minor version info for Development.Module to be found. For Python3_SABI_LIBRARY, continue using python3.lib (stable ABI). This fixes the CMake generate error: 'Target Python3::Module not found' that occurs because FindPython3 cannot extract version from python3.lib and fails to set Python3_Development.Module_FOUND to TRUE.
1 parent 495b14c commit 6b10b7f

2 files changed

Lines changed: 18 additions & 5 deletions

File tree

scripts/internal/windows_build_common.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,21 @@ def venv_paths(python_version):
2323
# with a given interpreter.
2424
xy_ver = python_version.split("-")[0]
2525

26-
if int(python_version.split("-")[0][1:]) >= 11:
27-
# Stable ABI
28-
python_library = "C:/Python%s/libs/python3.lib" % (python_version)
26+
# Version-specific library (e.g., python311.lib) - required for
27+
# CMake's FindPython3 to extract version info for Development.Module
28+
python_library = "C:/Python%s/libs/python%s.lib" % (python_version, xy_ver)
29+
30+
# Stable ABI library (python3.lib) - for Development.SABIModule
31+
if int(xy_ver[1:]) >= 11:
32+
python_sabi_library = "C:/Python%s/libs/python3.lib" % (python_version)
2933
else:
30-
python_library = "C:/Python%s/libs/python%s.lib" % (python_version, xy_ver)
34+
python_sabi_library = python_library
3135

3236
print("")
3337
print("Python3_EXECUTABLE: %s" % python_executable)
3438
print("Python3_INCLUDE_DIR: %s" % python_include_dir)
3539
print("Python3_LIBRARY: %s" % python_library)
40+
print("Python3_SABI_LIBRARY: %s" % python_sabi_library)
3641

3742
pip = os.path.join(venv_dir, "Scripts", "pip.exe")
3843

@@ -48,6 +53,7 @@ def venv_paths(python_version):
4853
python_executable,
4954
python_include_dir,
5055
python_library,
56+
python_sabi_library,
5157
pip,
5258
ninja_executable,
5359
path,

scripts/windows_build_wheels.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ def build_wrapped_itk(
6060
python_executable,
6161
python_include_dir,
6262
python_library,
63+
python_sabi_library,
6364
):
6465
tbb_dir = os.path.join(ROOT_DIR, "oneTBB-prefix", "lib", "cmake", "TBB")
6566

@@ -82,7 +83,7 @@ def build_wrapped_itk(
8283
"-DPython3_INCLUDE_DIR:PATH=%s" % python_include_dir,
8384
"-DPython3_INCLUDE_DIRS:PATH=%s" % python_include_dir,
8485
"-DPython3_LIBRARY:FILEPATH=%s" % python_library,
85-
"-DPython3_SABI_LIBRARY:FILEPATH=%s" % python_library,
86+
"-DPython3_SABI_LIBRARY:FILEPATH=%s" % python_sabi_library,
8687
"-DWRAP_ITK_INSTALL_COMPONENT_IDENTIFIER:STRING=PythonWheel",
8788
"-DWRAP_ITK_INSTALL_COMPONENT_PER_MODULE:BOOL=ON",
8889
"-DPY_SITE_PACKAGES_PATH:PATH=.",
@@ -112,6 +113,7 @@ def build_wheel(
112113
python_executable,
113114
python_include_dir,
114115
python_library,
116+
python_sabi_library,
115117
pip,
116118
ninja_executable,
117119
path,
@@ -169,6 +171,8 @@ def build_wheel(
169171
% python_include_dir,
170172
"--config-setting=cmake.define.Python3_LIBRARY:FILEPATH=%s"
171173
% python_library,
174+
"--config-setting=cmake.define.Python3_SABI_LIBRARY:FILEPATH=%s"
175+
% python_sabi_library,
172176
"--config-setting=cmake.define.DOXYGEN_EXECUTABLE:FILEPATH=C:/P/doxygen/doxygen.exe",
173177
]
174178
+ [
@@ -193,6 +197,7 @@ def build_wheel(
193197
python_executable,
194198
python_include_dir,
195199
python_library,
200+
python_sabi_library,
196201
)
197202

198203
# Build wheels
@@ -234,6 +239,8 @@ def build_wheel(
234239
% python_include_dir,
235240
"--config-setting=cmake.define.Python3_LIBRARY:FILEPATH=%s"
236241
% python_library,
242+
"--config-setting=cmake.define.Python3_SABI_LIBRARY:FILEPATH=%s"
243+
% python_sabi_library,
237244
]
238245
+ [
239246
o.replace("-D", "--config-setting=cmake.define.")

0 commit comments

Comments
 (0)