Skip to content

Commit

Permalink
Revert "Fixed usage of system protobuf (openvinotoolkit#6716)"
Browse files Browse the repository at this point in the history
This reverts commit 1a446b4.
  • Loading branch information
azhogov committed Jul 21, 2021
1 parent e7a00e9 commit c74e810
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 47 deletions.
1 change: 1 addition & 0 deletions cmake/features.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ else()
endif()

ie_dependent_option(NGRAPH_ONNX_IMPORT_ENABLE "Enable ONNX importer" ON "protoc_available" OFF)
ie_dependent_option(NGRAPH_ONNX_EDITOR_ENABLE "Enable ONNX Editor" ON "NGRAPH_ONNX_IMPORT_ENABLE" OFF)
ie_dependent_option(NGRAPH_PDPD_FRONTEND_ENABLE "Enable PaddlePaddle FrontEnd" ON "protoc_available" OFF)
ie_dependent_option(NGRAPH_USE_PROTOBUF_LITE "Compiles and links with protobuf-lite" OFF
"NGRAPH_ONNX_IMPORT_ENABLE OR NGRAPH_PDPD_FRONTEND_ENABLE" OFF)
Expand Down
12 changes: 9 additions & 3 deletions ngraph/frontend/paddlepaddle/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ set(PROTO_HDRS)
# Generate protobuf file on build time for each '.proto' file in src/proto
file(GLOB proto_files ${CMAKE_CURRENT_SOURCE_DIR}/src/proto/*.proto)

if(CMAKE_CROSSCOMPILING)
set(PDPD_PROTOC_EXECUTABLE ${SYSTEM_PROTOC})
else()
set(PDPD_PROTOC_EXECUTABLE $<TARGET_FILE:protoc>)
endif()

foreach(INFILE ${proto_files})
get_filename_component(FILE_DIR ${INFILE} DIRECTORY)
get_filename_component(FILE_WE ${INFILE} NAME_WE)
Expand All @@ -31,9 +37,9 @@ foreach(INFILE ${proto_files})
set(GENERATED_PROTO ${INFILE})
add_custom_command(
OUTPUT "${OUTPUT_PB_SRC}" "${OUTPUT_PB_HEADER}"
COMMAND ${PROTOC_EXECUTABLE} ARGS --cpp_out ${CMAKE_CURRENT_BINARY_DIR} -I ${FILE_DIR} ${FILE_WE}.proto
DEPENDS ${PROTOC_EXECUTABLE} ${GENERATED_PROTO}
COMMENT "Running C++ protocol buffer compiler (${PROTOC_EXECUTABLE}) on ${GENERATED_PROTO}"
COMMAND ${PDPD_PROTOC_EXECUTABLE} ARGS --cpp_out ${CMAKE_CURRENT_BINARY_DIR} -I ${FILE_DIR} ${FILE_WE}.proto
DEPENDS ${PDPD_PROTOC_EXECUTABLE} ${GENERATED_PROTO}
COMMENT "Running C++ protocol buffer compiler (${PDPD_PROTOC_EXECUTABLE}) on ${GENERATED_PROTO}"
VERBATIM
COMMAND_EXPAND_LISTS)
list(APPEND PROTO_SRCS "${OUTPUT_PB_SRC}")
Expand Down
32 changes: 0 additions & 32 deletions thirdparty/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -126,47 +126,15 @@ endif()

if(NGRAPH_PDPD_FRONTEND_ENABLE OR NGRAPH_ONNX_IMPORT_ENABLE)
if(NGRAPH_USE_SYSTEM_PROTOBUF)
set(Protobuf_USE_STATIC_LIBS ON)
if(VERBOSE_BUILD)
set(Protobuf_DEBUG ON)
endif()
find_package(Protobuf REQUIRED)
if(NGRAPH_USE_PROTOBUF_LITE)
set(Protobuf_LIBRARIES protobuf::libprotobuf-lite)
else()
set(Protobuf_LIBRARIES protobuf::libprotobuf)
endif()
set(SYSTEM_PROTOC protobuf::protoc)
set(PROTOC_EXECUTABLE ${SYSTEM_PROTOC})

foreach(target ${SYSTEM_PROTOC} ${Protobuf_LIBRARIES})
set_property(TARGET ${target} PROPERTY IMPORTED_GLOBAL TRUE)
endforeach()
else()
add_subdirectory(protobuf)
endif()

# forward variables used in the other places
set(SYSTEM_PROTOC ${SYSTEM_PROTOC} PARENT_SCOPE)
set(PROTOC_EXECUTABLE ${PROTOC_EXECUTABLE} PARENT_SCOPE)
set(Protobuf_LIBRARIES ${Protobuf_LIBRARIES} PARENT_SCOPE)
set(Protobuf_INCLUDE_DIRS ${Protobuf_INCLUDE_DIRS} PARENT_SCOPE)

# set public / interface compile options
foreach(target IN LISTS Protobuf_LIBRARIES)
set(link_type PUBLIC)
if(NGRAPH_USE_SYSTEM_PROTOBUF)
set(link_type INTERFACE)
endif()
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "^(Apple)?Clang$")
target_compile_options(${target} ${link_type} -Wno-undef)
endif()
endforeach()

# version checks
if(protobuf_VERSION VERSION_LESS "3.9" AND NGRAPH_USE_PROTOBUF_LITE)
message(FATAL_ERROR "Minimum supported version of protobuf-lite library is 3.9.0 (provided ${protobuf_VERSION})")
endif()
endif()

#
Expand Down
26 changes: 14 additions & 12 deletions thirdparty/protobuf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ if(OV_COMPILER_IS_CLANG)
endif()

set(protobuf_BUILD_TESTS OFF CACHE BOOL "Build tests")
set(protobuf_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS} CACHE BOOL "Build shared libs" FORCE)
set(protobuf_WITH_ZLIB OFF CACHE BOOL "Build with zlib support")

# When we build dll libraries. These flags make sure onnx and protobuf build with /MD, not /MT.
# These two options can't be mixed, because they requires link two imcompatiable runtime.
set(protobuf_WITH_ZLIB OFF CACHE BOOL "Build with zlib support")

if(NOT DEFINED protobuf_MSVC_STATIC_RUNTIME)
set(protobuf_MSVC_STATIC_RUNTIME OFF CACHE BOOL "Link protobuf to static runtime libraries" FORCE)
endif()
Expand All @@ -47,6 +47,10 @@ if(CMAKE_CROSSCOMPILING)
set(protobuf_BUILD_PROTOC_BINARIES OFF CACHE BOOL "Build libprotoc and protoc compiler" FORCE)
endif()

set(protobuf_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS} CACHE BOOL "Build shared libs" FORCE)
set(protobuf_BUILD_TESTS OFF CACHE BOOL "Build tests")
set(protobuf_WITH_ZLIB OFF CACHE BOOL "Build with zlib support")

add_subdirectory(protobuf/cmake EXCLUDE_FROM_ALL)
get_directory_property(protobuf_VERSION DIRECTORY protobuf/cmake DEFINITION protobuf_VERSION)

Expand All @@ -68,9 +72,10 @@ if(CMAKE_COMPILER_IS_GNUCXX OR OV_COMPILER_IS_CLANG)
CXX_VISIBILITY_PRESET default
C_VISIBILITY_PRESET default
VISIBILITY_INLINES_HIDDEN OFF)
foreach(target IN LISTS Protobuf_LIBRARIES)
foreach(target libprotobuf libprotobuf-lite)
target_compile_options(${target}
PRIVATE -Wno-all -Wno-unused-variable)
PRIVATE -Wno-all -Wno-unused-variable
PUBLIC -Wno-undef)
endforeach()
endif()

Expand All @@ -83,6 +88,10 @@ if(NGRAPH_USE_PROTOBUF_LITE)
VISIBILITY_INLINES_HIDDEN OFF)
endif()

if(protobuf_VERSION VERSION_LESS "3.9" AND NGRAPH_USE_PROTOBUF_LITE)
message(FATAL_ERROR "Minimum supported version of protobuf-lite library is 3.9.0")
endif()

if(ENABLE_LTO AND protobuf_VERSION VERSION_GREATER_EQUAL "3.8")
message(WARNING "Protobuf in version 3.8.0+ can throw runtime exceptions if LTO is enabled.")
endif()
Expand All @@ -92,13 +101,6 @@ if(CMAKE_CROSSCOMPILING AND NOT PROTOC_VERSION VERSION_EQUAL protobuf_VERSION)
endif()

# forward variables used in the other places
if(SYSTEM_PROTOC)
set(SYSTEM_PROTOC ${SYSTEM_PROTOC} PARENT_SCOPE)
set(PROTOC_EXECUTABLE ${SYSTEM_PROTOC} PARENT_SCOPE)
else()
set(PROTOC_EXECUTABLE $<TARGET_FILE:protoc> PARENT_SCOPE)
endif()

set(protobuf_VERSION ${protobuf_VERSION} PARENT_SCOPE)
set(SYSTEM_PROTOC ${SYSTEM_PROTOC} PARENT_SCOPE)
set(Protobuf_LIBRARIES ${Protobuf_LIBRARIES} PARENT_SCOPE)
set(Protobuf_INCLUDE_DIRS ${Protobuf_INCLUDE_DIRS} PARENT_SCOPE)

0 comments on commit c74e810

Please sign in to comment.