From 1a1907090328531f61a87c6d709bc52fcf4249ff Mon Sep 17 00:00:00 2001 From: Przemyslaw Wysocki Date: Mon, 4 Sep 2023 15:03:14 +0200 Subject: [PATCH] Backport Robust detection of Cython version (#19537) (#19547) * Robust detection of Cython version (#19537) * Aligned protobuf version in conanfile.txt with onnx recipe (#19525) --------- Co-authored-by: Ilya Lavrenov --- .../src/compatibility/openvino/CMakeLists.txt | 2 +- .../openvino/cmake/CythonConfig.cmake | 27 +++++++++++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/bindings/python/src/compatibility/openvino/CMakeLists.txt b/src/bindings/python/src/compatibility/openvino/CMakeLists.txt index c81cd8a16a9215..9cc46f5ac480a9 100644 --- a/src/bindings/python/src/compatibility/openvino/CMakeLists.txt +++ b/src/bindings/python/src/compatibility/openvino/CMakeLists.txt @@ -22,7 +22,7 @@ endif() include (cmake/UseCython.cmake) # Check Cython version -if(CYTHON_VERSION VERSION_LESS "0.29") +if(CYTHON_VERSION VERSION_LESS 0.29) message(FATAL_ERROR "OpenVINO Python API needs at least Cython version 0.29, found version ${CYTHON_VERSION}") else() message(STATUS "Found Cython version ${CYTHON_VERSION}") diff --git a/src/bindings/python/src/compatibility/openvino/cmake/CythonConfig.cmake b/src/bindings/python/src/compatibility/openvino/cmake/CythonConfig.cmake index 05f75ceeb51772..4cc32dacec1375 100644 --- a/src/bindings/python/src/compatibility/openvino/cmake/CythonConfig.cmake +++ b/src/bindings/python/src/compatibility/openvino/cmake/CythonConfig.cmake @@ -50,7 +50,30 @@ include( FindPackageHandleStandardArgs ) FIND_PACKAGE_HANDLE_STANDARD_ARGS( Cython REQUIRED_VARS CYTHON_EXECUTABLE ) # Find Cython version -execute_process(COMMAND ${CYTHON_EXECUTABLE} -V ERROR_VARIABLE CYTHON_OUTPUT OUTPUT_QUIET) -string(REGEX REPLACE "^Cython version ([0-9]+\\.[0-9]+(\\.[0-9]+)?).*" "\\1" CYTHON_VERSION "${CYTHON_OUTPUT}") +execute_process(COMMAND ${CYTHON_EXECUTABLE} -V + ERROR_VARIABLE CYTHON_OUTPUT + OUTPUT_VARIABLE CYTHON_ERROR_MESSAGE + RESULT_VARIABLE CYTHON_EXIT_CODE + OUTPUT_STRIP_TRAILING_WHITESPACE) + +if(CYTHON_EXIT_CODE EQUAL 0) + if(NOT CYTHON_OUTPUT) + set(CYTHON_OUTPUT "${CYTHON_ERROR_MESSAGE}") + endif() + string(REGEX REPLACE "^Cython version ([0-9]+\\.[0-9]+(\\.[0-9]+)?).*" "\\1" CYTHON_VERSION "${CYTHON_OUTPUT}") +else() + if(${CMAKE_FIND_PACKAGE_NAME}_FIND_QUIETLY) + set(CYTHON_MESSAGE_MODE TRACE) + endif() + if(${CMAKE_FIND_PACKAGE_NAME}_FIND_REQUIRED) + set(CYTHON_MESSAGE_MODE FATAL_ERROR) + endif() + message(${CYTHON_MESSAGE_MODE} "Failed to detect cython version: ${CYTHON_ERROR_MESSAGE}") + unset(CYTHON_MESSAGE_MODE) +endif() + +unset(CYTHON_OUTPUT) +unset(CYTHON_EXIT_CODE) +unset(CYTHON_ERROR_MESSAGE) mark_as_advanced( CYTHON_EXECUTABLE CYTHON_VERSION )