Skip to content

Commit 56e0bf2

Browse files
authored
Fix for issue #126162: warn for inconsistent Python search options (#126329)
Fixes #126162 I check locally that it works without warning for: - neither options are defined - both defined to the same value And I checked that it warns if: - only one is defined - they defined to different values
1 parent e31a1c8 commit 56e0bf2

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

mlir/cmake/modules/MLIRDetectPythonEnv.cmake

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,21 @@ macro(mlir_configure_python_dev_packages)
2222
find_package(Python3 ${LLVM_MINIMUM_PYTHON_VERSION}
2323
COMPONENTS Interpreter ${_python_development_component} REQUIRED)
2424

25+
# We look for both Python3 and Python, the search algorithm should be
26+
# consistent, otherwise disastrous result is almost guaranteed.
27+
# Warn if the policies for treating virtual environment are not defined
28+
# consistently.
29+
# For more details check issue #126162.
30+
if(((DEFINED Python_FIND_VIRTUALENV) AND (NOT DEFINED Python3_FIND_VIRTUALENV)) OR
31+
((NOT DEFINED Python_FIND_VIRTUALENV) AND (DEFINED Python3_FIND_VIRTUALENV)))
32+
message(WARNING "Only one of Python3_FIND_VIRTUALENV and Python_FIND_VIRTUALENV variables is defined. "
33+
"Make sure that both variables are defined and have the same value.")
34+
elseif((DEFINED Python_FIND_VIRTUALENV) AND (DEFINED Python3_FIND_VIRTUALENV) AND
35+
(NOT Python_FIND_VIRTUALENV STREQUAL Python3_FIND_VIRTUALENV))
36+
message(WARNING "Python3_FIND_VIRTUALENV and Python_FIND_VIRTUALENV are defined differently. "
37+
"Make sure that the variables have the same values.")
38+
endif()
39+
2540
# It's a little silly to detect Python a second time, but nanobind's cmake
2641
# code looks for Python_ not Python3_.
2742
find_package(Python ${LLVM_MINIMUM_PYTHON_VERSION}

0 commit comments

Comments
 (0)