compile protobuf

pull/253/head
wqtshg 4 years ago
parent 15775d3218
commit cd4eb3384c

@ -41,7 +41,9 @@ include(${GE_SOURCE_DIR}/cmake/ge_utils.cmake)
include(${GE_SOURCE_DIR}/cmake/external_libs/json.cmake)
include(${GE_SOURCE_DIR}/cmake/external_libs/eigen.cmake)
include(${GE_SOURCE_DIR}/cmake/external_libs/gtest.cmake)
include(${GE_SOURCE_DIR}/cmake/external_libs/protobuf.cmake)
#include(${GE_SOURCE_DIR}/cmake/external_libs/protobuf.cmake)
include(${GE_SOURCE_DIR}/cmake/external_libs/protobuf_shared.cmake)
include(${GE_SOURCE_DIR}/cmake/external_libs/protoc.cmake)
include(${GE_SOURCE_DIR}/cmake/external_libs/onnx.cmake)
include(${GE_SOURCE_DIR}/cmake/external_libs/securec.cmake)
set(CMAKE_SKIP_RPATH TRUE)

@ -0,0 +1,60 @@
if (HAVE_PROTOBUF)
return()
endif()
include(ExternalProject)
include(GNUInstallDirs)
if ((${CMAKE_INSTALL_PREFIX} STREQUAL /usr/local) OR
(${CMAKE_INSTALL_PREFIX} STREQUAL "C:/Program Files (x86)/ascend"))
set(CMAKE_INSTALL_PREFIX ${GE_SOURCE_DIR}/output CACHE STRING "path for install()" FORCE)
message(STATUS "No install prefix selected, default to ${CMAKE_INSTALL_PREFIX}.")
endif()
set(protobuf_CXXFLAGS "-Wno-maybe-uninitialized -Wno-unused-parameter -fPIC -fstack-protector-all -D_FORTIFY_SOURCE=2 -D_GLIBCXX_USE_CXX11_ABI=0 -O2")
set(protobuf_LDFLAGS "-Wl,-z,relro,-z,now,-z,noexecstack")
ExternalProject_Add(protobuf_build
URL https://github.com/protocolbuffers/protobuf/archive/v3.8.0.tar.gz
#URL /home/txd/workspace/linux_cmake/pkg/protobuf-3.8.0.tar.gz
#SOURCE_DIR ${METADEF_DIR}/../../third_party/protobuf/src/protobuf-3.8.0
#DOWNLOAD_COMMAND ${CMAKE_COMMAND} -E copy_directory ${METADEF_DIR}/../../third_party/protobuf/src/protobuf-3.8.0 <SOURCE_DIR>
#CONFIGURE_COMMAND ${CMAKE_COMMAND}
#-DCMAKE_INSTALL_LIBDIR=${CMAKE_INSTALL_LIBDIR}
#-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
#-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
#-DCMAKE_LINKER=${CMAKE_LINKER}
#-DCMAKE_AR=${CMAKE_AR}
#-DCMAKE_RANLIB=${CMAKE_RANLIB}
#-Dprotobuf_WITH_ZLIB=OFF
#-Dprotobuf_BUILD_TESTS=OFF -DBUILD_SHARED_LIBS=ON -DCMAKE_CXX_FLAGS=${protobuf_CXXFLAGS} -DCMAKE_CXX_LDFLAGS=${protobuf_LDFLAGS} -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}/protobuf <SOURCE_DIR>/cmake
CONFIGURE_COMMAND cd <SOURCE_DIR>
&& ./autogen.sh && cd <BINARY_DIR> && <SOURCE_DIR>/configure --prefix=${CMAKE_INSTALL_PREFIX}/protobuf --with-zlib=no CC=${CMAKE_C_COMPILER} CXX=${CMAKE_CXX_COMPILER} CXXFLAGS=${protobuf_CXXFLAGS} LDFLAGS=${protobuf_LDFLAGS}
&& bash -c "sed -i 's|^hardcode_libdir_flag_spec=.*|hardcode_libdir_flag_spec=\"\"|g' libtool && sed -i 's|^runpath_var=LD_RUN_PATH|runpath_var=DIE_RPATH_DIE|g' libtool"
BUILD_COMMAND $(MAKE)
INSTALL_COMMAND $(MAKE) install
EXCLUDE_FROM_ALL TRUE
)
include(GNUInstallDirs)
set(PROTOBUF_SHARED_PKG_DIR ${CMAKE_INSTALL_PREFIX}/protobuf)
add_library(protobuf SHARED IMPORTED)
file(MAKE_DIRECTORY ${PROTOBUF_SHARED_PKG_DIR}/include)
set_target_properties(protobuf PROPERTIES
IMPORTED_LOCATION ${PROTOBUF_SHARED_PKG_DIR}/lib/libprotobuf.so
)
target_include_directories(protobuf INTERFACE ${PROTOBUF_SHARED_PKG_DIR}/include)
set(INSTALL_BASE_DIR "")
set(INSTALL_LIBRARY_DIR lib)
install(FILES ${PROTOBUF_SHARED_PKG_DIR}/lib/libprotobuf.so ${PROTOBUF_SHARED_PKG_DIR}/lib/libprotobuf.so.19.0.0 OPTIONAL
DESTINATION ${INSTALL_LIBRARY_DIR})
add_dependencies(protobuf protobuf_build)
#set(HAVE_PROTOBUF TRUE CACHE BOOL "protobuf build add")
set(HAVE_PROTOBUF TRUE)

@ -0,0 +1,112 @@
if (HAVE_PROTOC)
return()
endif()
include(ExternalProject)
include(GNUInstallDirs)
#set(CMAKE_INSTALL_PREFIX ${GE_CODE_DIR}/output)
if ((${CMAKE_INSTALL_PREFIX} STREQUAL /usr/local) OR
(${CMAKE_INSTALL_PREFIX} STREQUAL "C:/Program Files (x86)/ascend"))
set(CMAKE_INSTALL_PREFIX ${GE_SOURCE_DIR}/output CACHE STRING "path for install()" FORCE)
message(STATUS "No install prefix selected, default to ${CMAKE_INSTALL_PREFIX}.")
endif()
if (ENABLE_GITEE)
set(REQ_URL "https://gitee.com/mirrors/protobuf_source/repository/archive/v3.8.0.tar.gz")
set(MD5 "eba86ae9f07ba5cfbaf8af3bc4e84236")
else()
set(REQ_URL "https://github.com/protocolbuffers/protobuf/archive/v3.8.0.tar.gz")
set(MD5 "3d9e32700639618a4d2d342c99d4507a")
endif ()
set(protobuf_CXXFLAGS "-Wno-maybe-uninitialized -Wno-unused-parameter -fPIC -fstack-protector-all -D_FORTIFY_SOURCE=2 -D_GLIBCXX_USE_CXX11_ABI=0 -O2")
set(protobuf_LDFLAGS "-Wl,-z,relro,-z,now,-z,noexecstack")
ExternalProject_Add(protoc_build
URL ${REQ_URL}
#URL /home/txd/workspace/linux_cmake/pkg/protobuf-3.8.0.tar.gz
#SOURCE_DIR ${GE_CODE_DIR}/../third_party/protobuf/src/protobuf-3.8.0
CONFIGURE_COMMAND ${CMAKE_COMMAND} -Dprotobuf_WITH_ZLIB=OFF -Dprotobuf_BUILD_TESTS=OFF -DBUILD_SHARED_LIBS=OFF -DCMAKE_CXX_FLAGS=${protobuf_CXXFLAGS} -DCMAKE_CXX_LDFLAGS=${protobuf_LDFLAGS} -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}/protoc <SOURCE_DIR>/cmake
BUILD_COMMAND $(MAKE)
INSTALL_COMMAND $(MAKE) install
EXCLUDE_FROM_ALL TRUE
)
set(PROTOC_PKG_DIR ${CMAKE_INSTALL_PREFIX}/protoc)
set(protoc_EXECUTABLE ${PROTOC_PKG_DIR}/${CMAKE_INSTALL_BINDIR}/protoc)
function(protobuf_generate comp c_var h_var)
if(NOT ARGN)
message(SEND_ERROR "Error: protobuf_generate() called without any proto files")
return()
endif()
set(${c_var})
set(${h_var})
foreach(file ${ARGN})
get_filename_component(abs_file ${file} ABSOLUTE)
get_filename_component(file_name ${file} NAME_WE)
get_filename_component(file_dir ${abs_file} PATH)
get_filename_component(parent_subdir ${file_dir} NAME)
if("${parent_subdir}" STREQUAL "proto")
set(proto_output_path ${CMAKE_BINARY_DIR}/proto/${comp}/proto)
else()
set(proto_output_path ${CMAKE_BINARY_DIR}/proto/${comp}/proto/${parent_subdir})
endif()
list(APPEND ${c_var} "${proto_output_path}/${file_name}.pb.cc")
list(APPEND ${h_var} "${proto_output_path}/${file_name}.pb.h")
add_custom_command(
OUTPUT "${proto_output_path}/${file_name}.pb.cc" "${proto_output_path}/${file_name}.pb.h"
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
COMMAND ${CMAKE_COMMAND} -E make_directory "${proto_output_path}"
COMMAND ${protoc_EXECUTABLE} -I${file_dir} --cpp_out=${proto_output_path} ${abs_file}
DEPENDS protoc_build ${abs_file}
COMMENT "Running C++ protocol buffer compiler on ${file}" VERBATIM )
endforeach()
set_source_files_properties(${${c_var}} ${${h_var}} PROPERTIES GENERATED TRUE)
set(${c_var} ${${c_var}} PARENT_SCOPE)
set(${h_var} ${${h_var}} PARENT_SCOPE)
endfunction()
function(protobuf_generate_py comp py_var)
if(NOT ARGN)
message(SEND_ERROR "Error: protobuf_generate_py() called without any proto files")
return()
endif()
set(${py_var})
foreach(file ${ARGN})
get_filename_component(abs_file ${file} ABSOLUTE)
get_filename_component(file_name ${file} NAME_WE)
get_filename_component(file_dir ${abs_file} PATH)
get_filename_component(parent_subdir ${file_dir} NAME)
if("${parent_subdir}" STREQUAL "proto")
set(proto_output_path ${CMAKE_BINARY_DIR}/proto/${comp}/proto)
else()
set(proto_output_path ${CMAKE_BINARY_DIR}/proto/${comp}/proto/${parent_subdir})
endif()
list(APPEND ${py_var} "${proto_output_path}/${file_name}_pb2.py")
add_custom_command(
OUTPUT "${proto_output_path}/${file_name}_pb2.py"
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
COMMAND ${CMAKE_COMMAND} -E make_directory "${proto_output_path}"
COMMAND ${protoc_EXECUTABLE} -I${file_dir} --python_out=${proto_output_path} ${abs_file}
DEPENDS protoc_build ${abs_file}
COMMENT "Running PYTHON protocol buffer compiler on ${file}" VERBATIM )
endforeach()
set_source_files_properties(${${py_var}} PROPERTIES GENERATED TRUE)
set(${py_var} ${${py_var}} PARENT_SCOPE)
endfunction()
#set(HAVE_PROTOC TRUE CACHE BOOL "protoc build add")
set(HAVE_PROTOC TRUE)

@ -19,21 +19,22 @@ set(CMAKE_CXX_FLAGS "-Wno-unused-variable ${CMAKE_CXX_FLAGS}")
# add all proto files, generate corresponding .h and .cc files
file(GLOB_RECURSE PROTO_LIST RELATIVE ${CMAKE_CURRENT_LIST_DIR}
"../../proto/om.proto"
"../../proto/ge_ir.proto"
"../../proto/insert_op.proto"
"../../proto/task.proto"
"../../proto/fwk_adaper.proto"
"../../proto/op_mapping_info.proto"
"../../proto/dump_task.proto"
)
"../../proto/ge_ir.proto"
"../../proto/insert_op.proto"
"../../proto/task.proto"
"../../proto/fwk_adaper.proto"
"../../proto/op_mapping_info.proto"
"../../proto/dump_task.proto"
"../../proto/onnx.proto"
)
file(GLOB_RECURSE ONNX_PROTO_LIST RELATIVE ${CMAKE_CURRENT_LIST_DIR}
"${onnx_INC}/onnx/onnx.proto"
)
)
ge_protobuf_generate(ge PROTO_SRCS PROTO_HDRS ${PROTO_LIST})
ge_protobuf_generate(ge PROTO_ONNX_SRCS PROTO_ONNX_HDRS ${ONNX_PROTO_LIST})
protobuf_generate(ge PROTO_SRCS PROTO_HDRS ${PROTO_LIST})
#protobuf_generate(ge PROTO_ONNX_SRCS PROTO_ONNX_HDRS ${ONNX_PROTO_LIST})
# need to remove dependencies on pb files later
file(GLOB SRC_LIST RELATIVE ${CMAKE_CURRENT_LIST_DIR}
"*.cc"
@ -61,15 +62,17 @@ include_directories(${GE_SOURCE_DIR}/third_party/fwkacllib/inc)
include_directories(${GE_SOURCE_DIR}/third_party/fwkacllib/inc/ops)
include_directories(${CMAKE_BINARY_DIR})
include_directories(${CMAKE_BINARY_DIR}/proto/ge)
include_directories(${CMAKE_BINARY_DIR}/proto/ge/proto)
include_directories(${GE_SOURCE_DIR}/build)
######### libgraph.so #############
add_library(graph SHARED ${SRC_LIST} ${PROTO_SRCS} ${PROTO_ONNX_SRCS})
add_library(graph SHARED ${SRC_LIST} ${PROTO_SRCS})
target_compile_definitions(graph PRIVATE
DAVINCI_CLOUD
Werror)
target_link_libraries(graph PRIVATE
${PROTOBUF_LIBRARY}
#${PROTOBUF_LIBRARY}
protobuf
${c_sec}
${slog}
${error_manager}

@ -33,9 +33,9 @@ file(GLOB PROTO_HEADER_LIST RELATIVE ${CMAKE_CURRENT_LIST_DIR}
"../proto/op_mapping_info.proto"
"../proto/dump_task.proto"
)
ge_protobuf_generate(ge PROTO_SRCS PROTO_HDRS ${PROTO_LIST})
ge_protobuf_generate(ge PROTO_CLIENT_SRCS PROTO_CLIENT_HDRS ${PROTO_CLIENT_LIST})
ge_protobuf_generate(ge PROTO_HEADER_SRCS PROTO_HEADER_HDRS ${PROTO_HEADER_LIST})
protobuf_generate(ge PROTO_SRCS PROTO_HDRS ${PROTO_LIST})
protobuf_generate(ge PROTO_CLIENT_SRCS PROTO_CLIENT_HDRS ${PROTO_CLIENT_LIST})
protobuf_generate(ge PROTO_HEADER_SRCS PROTO_HEADER_HDRS ${PROTO_HEADER_LIST})
# include directories
include_directories(${CMAKE_CURRENT_LIST_DIR})
include_directories(${GE_SOURCE_DIR})
@ -218,7 +218,8 @@ target_link_libraries(ge_runner
graph
ge_common
ge_memory
${PROTOBUF_LIBRARY}
#${PROTOBUF_LIBRARY}
protobuf
${register}
${c_sec}
${slog}
@ -367,7 +368,8 @@ target_link_libraries(ge_compiler
graph
ge_common
ge_memory
${PROTOBUF_LIBRARY}
#${PROTOBUF_LIBRARY}
protobuf
${register}
${c_sec}
${slog}

@ -32,8 +32,8 @@ file(GLOB SRC_LIST RELATIVE ${CMAKE_CURRENT_LIST_DIR}
"ge_prof.cc"
)
ge_protobuf_generate(ge PROTO_SRCS PROTO_HDRS ${PROTO_LIST})
ge_protobuf_generate(ge PROTO_HEADER_SRCS PROTO_HEADER_HDRS ${PROTO_HEADER_LIST})
protobuf_generate(ge PROTO_SRCS PROTO_HDRS ${PROTO_LIST})
protobuf_generate(ge PROTO_HEADER_SRCS PROTO_HEADER_HDRS ${PROTO_HEADER_LIST})
# include directories
include_directories(${CMAKE_CURRENT_LIST_DIR})
@ -61,7 +61,8 @@ target_link_libraries(ge_client
graph
ge_compiler
ge_common
${PROTOBUF_LIBRARY}
#${PROTOBUF_LIBRARY}
protobuf
${register}
${c_sec}
${slog}

@ -67,7 +67,7 @@ file(GLOB SRC_LIST RELATIVE ${CMAKE_CURRENT_LIST_DIR}
"util.cc"
)
ge_protobuf_generate(ge PROTO_SRCS PROTO_HDRS ${PROTO_LIST})
protobuf_generate(ge PROTO_SRCS PROTO_HDRS ${PROTO_LIST})
# include directories
include_directories(${CMAKE_CURRENT_LIST_DIR})
@ -92,7 +92,8 @@ target_compile_definitions(ge_common PUBLIC
OS_CENTOS)
target_link_libraries(ge_common
graph
${PROTOBUF_LIBRARY}
#${PROTOBUF_LIBRARY}
protobuf
${register}
${c_sec}
${slog}

@ -87,7 +87,7 @@ file(GLOB SRC_LIST RELATIVE ${CMAKE_CURRENT_LIST_DIR}
"../single_op/task/tbe_task_builder.cc"
)
ge_protobuf_generate(ge PROTO_SRCS PROTO_HDRS ${PROTO_LIST})
protobuf_generate(ge PROTO_SRCS PROTO_HDRS ${PROTO_LIST})
# include directories
include_directories(${CMAKE_CURRENT_LIST_DIR})
@ -113,6 +113,7 @@ target_link_libraries(ge_executor
ge_common
graph
${PROTOBUF_LIBRARY}
protobuf
${register}
${c_sec}
${runtime}

@ -25,7 +25,7 @@ file(GLOB SRC_LIST RELATIVE ${CMAKE_CURRENT_LIST_DIR}
"ops_kernel_store/op/*.cc"
)
ge_protobuf_generate(ge PROTO_SRCS PROTO_HDRS ${PROTO_LIST})
protobuf_generate(ge PROTO_SRCS PROTO_HDRS ${PROTO_LIST})
# include directories
include_directories(${CMAKE_CURRENT_LIST_DIR})
@ -45,7 +45,8 @@ add_library(ge_local_engine SHARED ${SRC_LIST} ${PROTO_HDRS})
target_compile_definitions(ge_local_engine PRIVATE Werror COMPILE_OMG_PACKAGE)
target_link_libraries(ge_local_engine
graph
${PROTOBUF_LIBRARY}
#${PROTOBUF_LIBRARY}
protobuf
${register}
${c_sec}
${slog}

@ -43,6 +43,7 @@ target_compile_definitions(ge_runtime PUBLIC
Werror)
target_link_libraries(ge_runtime
graph
protobuf
${slog}
${runtime}
${c_sec}

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save