FindPython: honour virtual environments without tweaking CMAKE_FIND_FRAMEWORK
Virtual environments are first class citizens in Python. In CMake 3.12, knowing where the virtual env was built, I was able to pass Python3_EXECUTABLE
on the command line, pointing to a specific version of python3 inside the virtual environment.
In CMake 3.14 this is not possible anymore (OSX) as Python3_EXECUTABLE
is overridden during the search loop of the module, and is cleared to whatever framework found on the system. Instead, the documentation suggests to change CMAKE_FIND_FRAMEWORK
to another value. However, CMAKE_FIND_FRAMEWORK
has global incidence and this may have side effects that are not understood by the developers.
If we run CMake from within a virtual environment, then the intent of the developer can be though as explicit and using the python interpreter of the virtual environment should have the top priority. If the user provides Python3_EXECUTABLE
, this variable should not be overridden and should be used for the framework, libraries and include lookup.
I suggest the following:
- if
Python3_EXECUTABLE
is set, then we do not perform any other search for frameworks. We use this executable instead, given the fact that it exists on disk and its version matches the one that is provided on thefind_package(Python3 ...)
command - if
Python3_EXECUTABLE
is not set, we /first/ look forpython3
executable on thePATH
. If the version matches withfind_package
, this would be the executable that is chosen for subsequent lookup, - then system defaults and HINTS are used as this is the case today
After Python3_EXECUTABLE
is found, the python interpreter should be used for determining the corresponding framework location. This can be done with the sys.base_prefix
as this value reflects the installation of the python interpreter from which the virtual environment has been built.
If you agree with those changes, I can work on a MR.