Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenCVDetectPython.cmake: prefer using FindPython #1133

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 45 additions & 19 deletions cmake/modules/OpenCVDetectPython.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -29,29 +29,55 @@ function(find_python preferred_version min_version library_env include_dir_env
if(NOT ${found})
if(${executable})
set(PYTHON_EXECUTABLE "${${executable}}")
set(Python_EXECUTABLE "${${executable}}")
endif()

find_package(PythonInterp "${preferred_version}")
if(NOT PYTHONINTERP_FOUND)
find_package(PythonInterp "${min_version}")
endif()
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.12")
find_package(Python "${preferred_version}" COMPONENTS Interpreter)
if(NOT Python_Interpreter_FOUND)
find_package(Python "${min_version}" COMPONENTS Interpreter)
endif()

if(PYTHONINTERP_FOUND)
# Copy outputs
set(_found ${PYTHONINTERP_FOUND})
set(_executable ${PYTHON_EXECUTABLE})
set(_version_string ${PYTHON_VERSION_STRING})
set(_version_major ${PYTHON_VERSION_MAJOR})
set(_version_minor ${PYTHON_VERSION_MINOR})
set(_version_patch ${PYTHON_VERSION_PATCH})
if(Python_Interpreter_FOUND)
# Copy outputs
set(_found ${Python_Interpreter_FOUND})
set(_executable ${Python_EXECUTABLE})
set(_version_string ${Python_VERSION})
set(_version_major ${Python_VERSION_MAJOR})
set(_version_minor ${Python_VERSION_MINOR})
set(_version_patch ${Python_VERSION_PATCH})

# Clear find_host_package side effects
unset(PYTHONINTERP_FOUND)
unset(PYTHON_EXECUTABLE CACHE)
unset(PYTHON_VERSION_STRING)
unset(PYTHON_VERSION_MAJOR)
unset(PYTHON_VERSION_MINOR)
unset(PYTHON_VERSION_PATCH)
# Clear find_host_package side effects
unset(Python_Interpreter_FOUND)
unset(Python_EXECUTABLE CACHE)
unset(Python_VERSION)
unset(Python_VERSION_MAJOR)
unset(Python_VERSION_MINOR)
unset(Python_VERSION_PATCH)
endif()
else()
find_package(PythonInterp "${preferred_version}")
if(NOT PYTHONINTERP_FOUND)
find_package(PythonInterp "${min_version}")
endif()

if(PYTHONINTERP_FOUND)
# Copy outputs
set(_found ${PYTHONINTERP_FOUND})
set(_executable ${PYTHON_EXECUTABLE})
set(_version_string ${PYTHON_VERSION_STRING})
set(_version_major ${PYTHON_VERSION_MAJOR})
set(_version_minor ${PYTHON_VERSION_MINOR})
set(_version_patch ${PYTHON_VERSION_PATCH})

# Clear find_host_package side effects
unset(PYTHONINTERP_FOUND)
unset(PYTHON_EXECUTABLE CACHE)
unset(PYTHON_VERSION_STRING)
unset(PYTHON_VERSION_MAJOR)
unset(PYTHON_VERSION_MINOR)
unset(PYTHON_VERSION_PATCH)
endif()
endif()

if(_found)
Expand Down