Skip to content
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