From 63c9356544ccd1471e3c428f21662420c0ceb00b Mon Sep 17 00:00:00 2001 From: Marc Chevrier Date: Tue, 2 Oct 2018 11:09:45 +0200 Subject: FindPython*: fix erroneous handling of virtual environments fixes: #18408 --- Modules/FindPython.cmake | 6 ++++++ Modules/FindPython/Support.cmake | 26 +++++++++++++++----------- Modules/FindPython2.cmake | 6 ++++++ Modules/FindPython3.cmake | 6 ++++++ 4 files changed, 33 insertions(+), 11 deletions(-) diff --git a/Modules/FindPython.cmake b/Modules/FindPython.cmake index 0bf0b4f..8645a0d 100644 --- a/Modules/FindPython.cmake +++ b/Modules/FindPython.cmake @@ -135,6 +135,12 @@ Hints Value ``ONLY`` is not supported so ``FIRST`` will be used instead. +.. note:: + + If a Python virtual environment is configured, set variable + ``Python_FIND_REGISTRY`` (Windows) or ``CMAKE_FIND_FRAMEWORK`` (macOS) with + value ``LAST`` or ``NEVER`` to select it preferably. + Commands ^^^^^^^^ diff --git a/Modules/FindPython/Support.cmake b/Modules/FindPython/Support.cmake index 1834591..a8a73a7 100644 --- a/Modules/FindPython/Support.cmake +++ b/Modules/FindPython/Support.cmake @@ -355,20 +355,23 @@ if ("Interpreter" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) ${_${_PYTHON_PREFIX}_IRON_PYTHON_NAMES} NAMES_PER_DIR HINTS ${_${_PYTHON_PREFIX}_HINTS} - PATH_SUFFIXES bin + PATH_SUFFIXES bin ${_${_PYTHON_PREFIX}_IRON_PYTHON_PATH_SUFFIXES} NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH) # try using standard paths. - # NAMES_PER_DIR is not defined on purpose to have a chance to find - # expected version. - # For example, typical systems have 'python' for version 2.* and 'python3' - # for version 3.*. So looking for names per dir will find, potentially, - # systematically 'python' (i.e. version 2) even if version 3 is searched. - find_program (${_PYTHON_PREFIX}_EXECUTABLE - NAMES python${_${_PYTHON_PREFIX}_VERSION} - python${_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR} - python - ${_${_PYTHON_PREFIX}_IRON_PYTHON_NAMES}) + if (WIN32) + find_program (${_PYTHON_PREFIX}_EXECUTABLE + NAMES python${_${_PYTHON_PREFIX}_VERSION} + python${_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR} + python + ${_${_PYTHON_PREFIX}_IRON_PYTHON_NAMES} + NAMES_PER_DIR) + else() + find_program (${_PYTHON_PREFIX}_EXECUTABLE + NAMES python${_${_PYTHON_PREFIX}_VERSION} + python${_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR} + NAMES_PER_DIR) + endif() # Apple frameworks handling if (APPLE AND _${_PYTHON_PREFIX}_FIND_FRAMEWORK STREQUAL "LAST") @@ -413,6 +416,7 @@ if ("Interpreter" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS) NAMES python${_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR} python ${_${_PYTHON_PREFIX}_IRON_PYTHON_NAMES} + NAMES_PER_DIR HINTS ${_${_PYTHON_PREFIX}_HINTS} PATH_SUFFIXES bin ${_${_PYTHON_PREFIX}_IRON_PYTHON_PATH_SUFFIXES} NO_SYSTEM_ENVIRONMENT_PATH diff --git a/Modules/FindPython2.cmake b/Modules/FindPython2.cmake index 2735a25..998e992 100644 --- a/Modules/FindPython2.cmake +++ b/Modules/FindPython2.cmake @@ -136,6 +136,12 @@ Hints Value ``ONLY`` is not supported so ``FIRST`` will be used instead. +.. note:: + + If a Python virtual environment is configured, set variable + ``Python_FIND_REGISTRY`` (Windows) or ``CMAKE_FIND_FRAMEWORK`` (macOS) with + value ``LAST`` or ``NEVER`` to select it preferably. + Commands ^^^^^^^^ diff --git a/Modules/FindPython3.cmake b/Modules/FindPython3.cmake index ed7e1a3..2176f3f 100644 --- a/Modules/FindPython3.cmake +++ b/Modules/FindPython3.cmake @@ -136,6 +136,12 @@ Hints Value ``ONLY`` is not supported so ``FIRST`` will be used instead. +.. note:: + + If a Python virtual environment is configured, set variable + ``Python_FIND_REGISTRY`` (Windows) or ``CMAKE_FIND_FRAMEWORK`` (macOS) with + value ``LAST`` or ``NEVER`` to select it preferably. + Commands ^^^^^^^^ -- cgit v0.12