Static protobuf for FEs (#6588)

* protobuf static + mixed editor and importer

* merged onnx common

* remove ngraph_test_util to onnx_importer and onnx

* styles applied

* Revert "remove ngraph_test_util to onnx_importer and onnx".

* test ngraph_test_util dependencies

* Fixed static protobuf

* Next

* Fixes

* Fixed cross-compilation

* Don't export / install onnx_proto

* Fixed Windows

* Fixed opencl headers

* Fix

* Added exclude-all for exe as well

* Fixed code style

* Try without LTO

* LTO off only for onnx importer

Co-authored-by: mbencer <mateusz.bencer@intel.com>
This commit is contained in:
Ilya Lavrenov
2021-07-16 07:25:40 +03:00
committed by GitHub
parent 2a15e3e79c
commit 1621c66ad8
29 changed files with 113 additions and 275 deletions

View File

@@ -1,23 +0,0 @@
# Copyright (C) 2018-2021 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
#
cmake_minimum_required(VERSION 3.13)
project(libprotobuf_static)
message("Add PROTOBUF dependency - static")
set(BUILD_SHARED_LIBS_OLD ${BUILD_SHARED_LIBS})
set(BUILD_STANDALONE_STATIC_OLD ${BUILD_STANDALONE_STATIC})
set(USE_STATIC_PROTOBUF_OLD ${USE_STATIC_PROTOBUF})
set(BUILD_SHARED_LIBS OFF)
set(BUILD_STANDALONE_STATIC ON)
set(USE_STATIC_PROTOBUF ON)
add_subdirectory(../protobuf ${CMAKE_BINARY_DIR}/_deps/static-protobuf)
set(BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS_OLD})
set(BUILD_STANDALONE_STATIC ${BUILD_STANDALONE_STATIC_OLD})
set(USE_STATIC_PROTOBUF ${USE_STATIC_PROTOBUF_OLD})

View File

@@ -2,6 +2,8 @@
# SPDX-License-Identifier: Apache-2.0
#
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE OFF)
#------------------------------------------------------------------------------
# Configure and install libonnx ...
#------------------------------------------------------------------------------
@@ -17,22 +19,9 @@ macro(onnx_set_target_properties)
elseif(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "^(Apple)?Clang$")
target_compile_options(onnx PRIVATE -Wno-all)
target_compile_options(onnx_proto PRIVATE -Wno-all -Wno-unused-variable)
# it fixes random problems with double registration of descriptors to protobuf database
set_target_properties(onnx_proto PROPERTIES
CXX_VISIBILITY_PRESET default
C_VISIBILITY_PRESET default
VISIBILITY_INLINES_HIDDEN OFF)
endif()
target_compile_definitions(onnx PUBLIC ONNX_BUILD_SHARED_LIBS)
install(TARGETS onnx_proto
RUNTIME DESTINATION ${NGRAPH_INSTALL_LIB} COMPONENT ngraph
ARCHIVE DESTINATION ${NGRAPH_INSTALL_LIB} COMPONENT ngraph
LIBRARY DESTINATION ${NGRAPH_INSTALL_LIB} COMPONENT ngraph)
export(TARGETS onnx onnx_proto NAMESPACE ngraph:: APPEND FILE "${NGRAPH_TARGETS_FILE}")
endmacro()
set(ONNX_USE_PROTOBUF_SHARED_LIBS ${BUILD_SHARED_LIBS} CACHE BOOL "Use dynamic protobuf by ONNX library")

View File

@@ -3,7 +3,7 @@
#
#------------------------------------------------------------------------------
# Configure and install Google Protobuf ...
# Configure Google Protobuf ...
#------------------------------------------------------------------------------
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE OFF)
@@ -13,7 +13,7 @@ if (MSVC)
endif()
if(CMAKE_CROSSCOMPILING)
find_program(SYSTEM_PROTOC protoc PATHS ENV PATH)
find_host_program(SYSTEM_PROTOC protoc PATHS ENV PATH)
if(SYSTEM_PROTOC)
execute_process(
@@ -33,38 +33,14 @@ if(CMAKE_CROSSCOMPILING)
set(protobuf_BUILD_PROTOC_BINARIES OFF CACHE BOOL "Build libprotoc and protoc compiler" FORCE)
endif()
if (CMAKE_GENERATOR STREQUAL "Ninja")
set(MAKE_UTIL make)
else()
set(MAKE_UTIL $(MAKE))
endif()
set(protobuf_BUILD_SHARED_LIBS OFF CACHE BOOL "Build shared libs")
set(protobuf_BUILD_TESTS OFF CACHE BOOL "Build tests")
set(protobuf_WITH_ZLIB OFF CACHE BOOL "Build with zlib support")
if (NOT BUILD_STANDALONE_STATIC)
add_subdirectory(protobuf/cmake EXCLUDE_FROM_ALL)
get_directory_property(protobuf_VERSION DIRECTORY protobuf/cmake DEFINITION protobuf_VERSION)
endif()
if (USE_STATIC_PROTOBUF)
include(FetchContent)
FetchContent_Declare(
ext_protobuf_static
URL ${CMAKE_CURRENT_SOURCE_DIR}/protobuf
)
FetchContent_GetProperties(ext_protobuf_static)
if((NOT ext_protobuf_static_POPULATED) AND BUILD_STANDALONE_STATIC)
FetchContent_Populate(ext_protobuf_static)
add_subdirectory(${ext_protobuf_static_SOURCE_DIR}/cmake ${ext_protobuf_static_BINARY_DIR} EXCLUDE_FROM_ALL)
get_directory_property(protobuf_VERSION DIRECTORY ${ext_protobuf_static_SOURCE_DIR}/cmake DEFINITION protobuf_VERSION)
endif()
endif()
add_subdirectory(protobuf/cmake EXCLUDE_FROM_ALL)
get_directory_property(protobuf_VERSION DIRECTORY protobuf/cmake DEFINITION protobuf_VERSION)
if (BUILD_STANDALONE_STATIC)
set(Protobuf_INCLUDE_DIRS ${ext_protobuf_static_SOURCE_DIR}/src)
else()
set(Protobuf_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/protobuf/src)
endif()
set(Protobuf_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/protobuf/src)
if(NGRAPH_USE_PROTOBUF_LITE)
set(Protobuf_LIBRARIES libprotobuf-lite)
@@ -75,18 +51,21 @@ endif()
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "^(Apple)?Clang$")
set(_proto_libs ${Protobuf_LIBRARIES})
if(TARGET libprotoc)
list(APPEND _proto_libs libprotoc)
target_compile_options(libprotoc PRIVATE -Wno-all -Wno-unused-variable)
target_compile_options(libprotoc PRIVATE -Wno-all -Wno-unused-variable)
# required for protoc compiler
set_target_properties(libprotoc PROPERTIES
CXX_VISIBILITY_PRESET default
C_VISIBILITY_PRESET default
VISIBILITY_INLINES_HIDDEN OFF)
endif()
set_target_properties(${_proto_libs} PROPERTIES
CXX_VISIBILITY_PRESET default
C_VISIBILITY_PRESET default
VISIBILITY_INLINES_HIDDEN OFF)
foreach(target libprotobuf libprotobuf-lite)
foreach(target libprotobuf libprotobuf-lite)
if(TARGET ${target})
target_compile_options(${target}
PRIVATE -Wno-all -Wno-unused-variable -Wno-inconsistent-missing-override
PUBLIC -Wno-undef)
endforeach()
endif()
endforeach()
endif()
if(NGRAPH_USE_PROTOBUF_LITE)
@@ -110,15 +89,6 @@ if(CMAKE_CROSSCOMPILING AND NOT PROTOC_VERSION VERSION_EQUAL protobuf_VERSION)
message(WARNING "system protobuf version does not match with the compiled one, please update system protobuf or submodule")
endif()
if (NOT BUILD_STANDALONE_STATIC)
message("NGRAPH_INSTALL_LIB = ${NGRAPH_INSTALL_LIB}")
install(TARGETS ${Protobuf_LIBRARIES}
RUNTIME DESTINATION ${NGRAPH_INSTALL_LIB} COMPONENT ngraph
ARCHIVE DESTINATION ${NGRAPH_INSTALL_LIB} COMPONENT ngraph
LIBRARY DESTINATION ${NGRAPH_INSTALL_LIB} COMPONENT ngraph)
export(TARGETS ${Protobuf_LIBRARIES} NAMESPACE ngraph:: APPEND FILE "${NGRAPH_TARGETS_FILE}")
endif()
# forward variables used in the other places
set(SYSTEM_PROTOC ${SYSTEM_PROTOC} PARENT_SCOPE)
set(Protobuf_LIBRARIES ${Protobuf_LIBRARIES} PARENT_SCOPE)