Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed usage of system protobuf #6716

Merged
merged 1 commit into from
Jul 20, 2021
Merged
Show file tree
Hide file tree
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
1 change: 0 additions & 1 deletion cmake/features.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ 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: 3 additions & 9 deletions ngraph/frontend/paddlepaddle/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@ 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 @@ -37,9 +31,9 @@ foreach(INFILE ${proto_files})
set(GENERATED_PROTO ${INFILE})
add_custom_command(
OUTPUT "${OUTPUT_PB_SRC}" "${OUTPUT_PB_HEADER}"
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}"
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}"
VERBATIM
COMMAND_EXPAND_LISTS)
list(APPEND PROTO_SRCS "${OUTPUT_PB_SRC}")
Expand Down
32 changes: 32 additions & 0 deletions thirdparty/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,47 @@ 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: 12 additions & 14 deletions thirdparty/protobuf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "^(Apple)?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,10 +47,6 @@ 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 @@ -72,10 +68,9 @@ if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "^(Apple)?Clang$")
CXX_VISIBILITY_PRESET default
C_VISIBILITY_PRESET default
VISIBILITY_INLINES_HIDDEN OFF)
foreach(target libprotobuf libprotobuf-lite)
foreach(target IN LISTS Protobuf_LIBRARIES)
target_compile_options(${target}
PRIVATE -Wno-all -Wno-unused-variable
PUBLIC -Wno-undef)
PRIVATE -Wno-all -Wno-unused-variable)
endforeach()
endif()

Expand All @@ -88,10 +83,6 @@ 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 @@ -101,6 +92,13 @@ if(CMAKE_CROSSCOMPILING AND NOT PROTOC_VERSION VERSION_EQUAL protobuf_VERSION)
endif()

# forward variables used in the other places
set(SYSTEM_PROTOC ${SYSTEM_PROTOC} PARENT_SCOPE)
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(Protobuf_LIBRARIES ${Protobuf_LIBRARIES} PARENT_SCOPE)
set(Protobuf_INCLUDE_DIRS ${Protobuf_INCLUDE_DIRS} PARENT_SCOPE)