Skip to content

Commit d542b02

Browse files
committed
COMP: Find Python3 once for wrapping builds
The component list no longer depends on a discovered version, so the range search and the exact-version re-search collapse into one call. NumPy now follows BUILD_TESTING consistently: the first search had always demanded it, while only the second was checked.
1 parent e2ade13 commit d542b02

1 file changed

Lines changed: 22 additions & 33 deletions

File tree

CMake/ITKSetPython3Vars.cmake

Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -61,38 +61,6 @@ if(NOT PYTHON_DEVELOPMENT_REQUIRED)
6161
)
6262
set(ITK_WRAP_PYTHON_VERSION "ITK_WRAP_PYTHON=OFF")
6363
else()
64-
# set(Python3_FIND_REGISTRY LAST) # default is FIRST. Do we need/want this?
65-
find_package(
66-
Python3
67-
${PYTHON_VERSION_MIN}...${PYTHON_VERSION_MAX}
68-
COMPONENTS
69-
Interpreter
70-
# NOTE: dockcross build environments do not supply
71-
# `Development` python-dev resources
72-
Development.SABIModule
73-
NumPy
74-
)
75-
set(ITK_WRAP_PYTHON_VERSION "${Python3_VERSION}")
76-
77-
# An empty Python3_VERSION means the range found nothing; otherwise the second
78-
# find_package below runs unversioned and silently accepts a below-floor Python.
79-
if(
80-
NOT
81-
Python3_VERSION
82-
OR
83-
Python3_VERSION
84-
VERSION_LESS
85-
${ITK_WRAP_PYTHON_MINIMUM_VERSION}
86-
)
87-
message(
88-
FATAL_ERROR
89-
"ITK Python wrapping (ITK_WRAP_PYTHON=ON) requires Python >= ${ITK_WRAP_PYTHON_MINIMUM_VERSION}, "
90-
"but no such interpreter was found in range ${PYTHON_VERSION_MIN}...${PYTHON_VERSION_MAX} "
91-
"(resolved version '${Python3_VERSION}', Python3_EXECUTABLE='${Python3_EXECUTABLE}'). "
92-
"Provide a Python >= ${ITK_WRAP_PYTHON_MINIMUM_VERSION} interpreter, or set ITK_WRAP_PYTHON=OFF."
93-
)
94-
endif()
95-
9664
# Wrapping requires this version and every module is abi3, so the wrapping
9765
# floor and the Limited API floor are the same number. Cached so
9866
# itk_end_wrap_module.cmake can pin USE_SABI to it.
@@ -123,13 +91,34 @@ else()
12391
endif()
12492
set(_missing_required_component FALSE)
12593
set(_missing_python_components "")
94+
# set(Python3_FIND_REGISTRY LAST) # default is FIRST. Do we need/want this?
12695
find_package(
12796
Python3
128-
${ITK_WRAP_PYTHON_VERSION}
97+
${PYTHON_VERSION_MIN}...${PYTHON_VERSION_MAX}
12998
COMPONENTS
99+
# NOTE: dockcross build environments do not supply
100+
# `Development` python-dev resources
130101
${_python_find_components}
131102
)
132103
set(ITK_WRAP_PYTHON_VERSION "${Python3_VERSION}")
104+
105+
# An empty Python3_VERSION means the range found nothing.
106+
if(
107+
NOT
108+
Python3_VERSION
109+
OR
110+
Python3_VERSION
111+
VERSION_LESS
112+
${ITK_WRAP_PYTHON_MINIMUM_VERSION}
113+
)
114+
message(
115+
FATAL_ERROR
116+
"ITK Python wrapping (ITK_WRAP_PYTHON=ON) requires Python >= ${ITK_WRAP_PYTHON_MINIMUM_VERSION}, "
117+
"but no such interpreter was found in range ${PYTHON_VERSION_MIN}...${PYTHON_VERSION_MAX} "
118+
"(resolved version '${Python3_VERSION}', Python3_EXECUTABLE='${Python3_EXECUTABLE}'). "
119+
"Provide a Python >= ${ITK_WRAP_PYTHON_MINIMUM_VERSION} interpreter, or set ITK_WRAP_PYTHON=OFF."
120+
)
121+
endif()
133122
message(STATUS "Python3_FOUND=${Python3_FOUND}")
134123
foreach(_required_component ${_python_find_components})
135124
if(NOT Python3_${_required_component}_FOUND)

0 commit comments

Comments
 (0)