Support of protobuf >= 21 (#18351)

* Corrected typo

* Ability to compile with newer protobuf versions
This commit is contained in:
Ilya Lavrenov 2023-07-04 17:08:29 +04:00 committed by GitHub
parent 0b3a004825
commit 642c69115d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 46 additions and 11 deletions

View File

@ -2,7 +2,7 @@
ade/0.1.2a
onetbb/[>=2021.2.1]
pugixml/[>=1.10]
protobuf/[>=3.20.3]
protobuf/3.21.9
ittapi/[>=3.23.0]
zlib/[>=1.2.8]
opencl-icd-loader/2023.04.17
@ -19,7 +19,7 @@ flatbuffers/[>=22.9.24]
[tool_requires]
cmake/[>=3.15]
patchelf/[>=0.12]
protobuf/[>=3.20.3]
protobuf/3.21.9
flatbuffers/[>=22.9.24]
[options]

View File

@ -9,3 +9,4 @@ add_library(${TARGET_NAME} STATIC shutdown_protobuf.cpp)
target_include_directories(${TARGET_NAME} SYSTEM PRIVATE
$<BUILD_INTERFACE:$<TARGET_PROPERTY:protobuf::libprotobuf,INTERFACE_INCLUDE_DIRECTORIES>>)
set_target_properties(${TARGET_NAME} PROPERTIES INTERPROCEDURAL_OPTIMIZATION_RELEASE ${ENABLE_LTO})
target_compile_features(${TARGET_NAME} PRIVATE $<TARGET_PROPERTY:protobuf::libprotobuf,INTERFACE_COMPILE_FEATURES>)

View File

@ -2,7 +2,15 @@
// SPDX-License-Identifier: Apache-2.0
//
#include <google/protobuf/stubs/logging.h>
#include <google/protobuf/port_def.inc>
#if PROTOBUF_VERSION >= 4022000 // protobuf 4.22
# define OV_PROTOBUF_ABSL_IS_USED
#endif
#include <google/protobuf/port_undef.inc>
#ifndef OV_PROTOBUF_ABSL_IS_USED
# include <google/protobuf/stubs/logging.h>
#endif
#include <fstream>
#include <input_model.hpp>
@ -37,7 +45,9 @@ ONNX_FRONTEND_C_API void* get_front_end_data() {
};
#ifndef OPENVINO_DEBUG_ENABLE
// disable protobuf logging
# ifndef OV_PROTOBUF_ABSL_IS_USED
google::protobuf::SetLogHandler(nullptr);
# endif
#endif
return res;
}

View File

@ -4,7 +4,15 @@
#include "openvino/frontend/paddle/frontend.hpp"
#include <google/protobuf/stubs/logging.h>
#include <google/protobuf/port_def.inc>
#if PROTOBUF_VERSION >= 4022000 // protobuf 4.22
# define OV_PROTOBUF_ABSL_IS_USED
#endif
#include <google/protobuf/port_undef.inc>
#ifndef OV_PROTOBUF_ABSL_IS_USED
# include <google/protobuf/stubs/logging.h>
#endif
#include <fstream>
#include <map>
@ -551,7 +559,9 @@ PADDLE_C_API void* get_front_end_data() {
#ifndef OPENVINO_DEBUG_ENABLE
// disable protobuf logging
# ifndef OV_PROTOBUF_ABSL_IS_USED
google::protobuf::SetLogHandler(nullptr);
# endif
#endif
return res;
}

View File

@ -446,8 +446,16 @@ if(ENABLE_OV_PADDLE_FRONTEND OR ENABLE_OV_ONNX_FRONTEND OR ENABLE_OV_TF_FRONTEND
if(CMAKE_VERBOSE_MAKEFILE)
set(Protobuf_DEBUG ON)
endif()
# Note: we also specify 'protobuf' in NAMES because vcpkg
find_package(Protobuf 3.20.3 REQUIRED NAMES Protobuf protobuf)
# Note: we also specify 'protobuf' in NAMES because of vcpkg
set(find_package_protobuf_names Protobuf protobuf)
# try to find newer version first (major is changed)
# see https://protobuf.dev/support/version-support/ and
# https://github.com/protocolbuffers/protobuf/commit/d61f75ff6db36b4f9c0765f131f8edc2f86310fa
find_package(Protobuf 4.22.0 QUIET NAMES ${find_package_protobuf_names})
if(NOT Protobuf_FOUND)
# otherwise, fallback to existing default
find_package(Protobuf 3.20.3 REQUIRED NAMES ${find_package_protobuf_names})
endif()
set(PROTOC_EXECUTABLE protobuf::protoc)
else()
add_subdirectory(thirdparty/protobuf EXCLUDE_FROM_ALL)

View File

@ -49,7 +49,6 @@ endforeach()
if(WIN32)
# from onnx==1.13.1 it requires C++17 when compiling on Windows
target_compile_features(onnx PRIVATE cxx_std_17)
set_target_properties(onnx PROPERTIES CXX_STANDARD 17)
# OPTIONAL is a reserved word for mingw at least
if(MINGW)
target_compile_definitions(onnx PRIVATE OPTIONAL=OPTIONAL_PLACEHOLDER)

View File

@ -22,6 +22,7 @@ set(protobuf_VERBOSE ON)
set(protobuf_BUILD_TESTS OFF CACHE BOOL "Build tests" FORCE)
set(protobuf_BUILD_SHARED_LIBS OFF CACHE BOOL "Build shared libs" FORCE)
set(protobuf_WITH_ZLIB OFF CACHE BOOL "Build with zlib support" FORCE)
set(ABSL_PROPAGATE_CXX_STD ON CACHE BOOL "Abseil protogate CXX standard to dependent targets" FORCE)
# note: HOST_AARCH64 AND X86_64 are not handled for Apple explicitly, because it can work via Rosetta
if(CMAKE_CROSSCOMPILING OR
@ -38,8 +39,14 @@ if(NOT DEFINED protobuf_MSVC_STATIC_RUNTIME)
set(protobuf_MSVC_STATIC_RUNTIME OFF CACHE BOOL "Link protobuf to static runtime libraries" FORCE)
endif()
add_subdirectory(protobuf/cmake EXCLUDE_FROM_ALL)
get_directory_property(protobuf_VERSION DIRECTORY protobuf/cmake DEFINITION protobuf_VERSION)
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/protobuf/CMakeLists.txt")
set(protobuf_dir protobuf)
else()
set(protobuf_dir protobuf/cmake)
endif()
add_subdirectory(${protobuf_dir} EXCLUDE_FROM_ALL)
get_directory_property(protobuf_VERSION DIRECTORY ${protobuf_dir} DEFINITION protobuf_VERSION)
set(Protobuf_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/protobuf/src)
@ -61,7 +68,7 @@ if(CMAKE_COMPILER_IS_GNUCXX OR OV_COMPILER_IS_CLANG OR
INTERPROCEDURAL_OPTIMIZATION_RELEASE ${ENABLE_LTO})
endif()
if(protobuf_VERSION VERSION_LESS "3.9")
if(protobuf_VERSION VERSION_LESS 3.9)
message(FATAL_ERROR "Minimum supported version of protobuf-lite library is 3.9.0 (provided ${protobuf_VERSION})")
endif()
@ -76,7 +83,7 @@ if(NOT protobuf_BUILD_PROTOC_BINARIES)
CMAKE_ARGS "-Dprotobuf_VERBOSE=${protobuf_VERBOSE}"
"-Dprotobuf_BUILD_TESTS=${protobuf_BUILD_TESTS}"
"-Dprotobuf_WITH_ZLIB=${protobuf_WITH_ZLIB}"
NATIVE_SOURCE_SUBDIR "protobuf/cmake"
NATIVE_SOURCE_SUBDIR "${protobuf_dir}"
NATIVE_TARGETS protoc libprotobuf-lite)
set(PROTOC_EXECUTABLE "${HOST_PROTOC_INSTALL_DIR}/bin/protoc")