From 123ceab2487d69ddcc14d95e308f77f480d9d9b1 Mon Sep 17 00:00:00 2001 From: Wovchena Date: Mon, 15 Jul 2024 14:58:07 +0400 Subject: [PATCH] Revert "Revert to python3 (#622)" This reverts commit 8ad336c1de9b374c9826b0cd73591955eb4e337e, reversing changes made to e4637b3a197cd03281e9b68f0e2f3a100c47b28a. --- src/python/CMakeLists.txt | 42 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/src/python/CMakeLists.txt b/src/python/CMakeLists.txt index f03f2f58d1..bcbdb77b49 100644 --- a/src/python/CMakeLists.txt +++ b/src/python/CMakeLists.txt @@ -12,9 +12,49 @@ FetchContent_GetProperties(pybind11) # search for FindPython3.cmake instead of legacy modules set(PYBIND11_FINDPYTHON ON) +# Wouraround Python_VERSION_MAJOR and MINOR not being set by finding +# Python package instead of Python3 +macro(ov_find_python_no_3 find_package_mode) + # Settings for FindPython3.cmake + if(NOT DEFINED Python3_USE_STATIC_LIBS) + set(Python3_USE_STATIC_LIBS OFF) + endif() + + if(NOT DEFINED Python3_FIND_VIRTUALENV) + set(Python3_FIND_VIRTUALENV FIRST) + endif() + + if(NOT DEFINED Python3_FIND_IMPLEMENTATIONS) + set(Python3_FIND_IMPLEMENTATIONS CPython PyPy) + endif() + + if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.18) + set(python3_development_component Development.Module) + else() + set(python3_development_component Development) + endif() + + if(CMAKE_CROSSCOMPILING AND LINUX) + # allow to find python headers from host in case of cross-compilation + # e.g. install libpython3-dev: and finds its headers + set(_old_CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ${CMAKE_FIND_ROOT_PATH_MODE_INCLUDE}) + set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH) + ov_cross_compile_define_debian_arch() + endif() + + find_package(Python ${find_package_mode} COMPONENTS Interpreter ${python3_development_component}) + + if(CMAKE_CROSSCOMPILING AND LINUX) + ov_cross_compile_define_debian_arch_reset() + set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ${_old_CMAKE_FIND_ROOT_PATH_MODE_INCLUDE}) + endif() + + unset(python3_development_component) +endmacro() + # the following two calls are required for cross-compilation if(OpenVINODeveloperPackage_DIR) - ov_find_python3(REQUIRED) + ov_find_python_no_3(REQUIRED) ov_detect_python_module_extension() else() if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.18)