mirror of https://github.com/milvus-io/milvus.git
Fix protobuf compilation error (#9881)
resolves:#9876 Signed-off-by: yangxuan <xuan.yang@zilliz.com>pull/9889/head
parent
47a6f538f1
commit
ea7abf49c3
|
@ -14,4 +14,4 @@ set(exceptions_files
|
|||
)
|
||||
|
||||
add_library(milvus_exceptions ${exceptions_files})
|
||||
target_link_libraries(milvus_exceptions milvus_proto)
|
||||
target_link_libraries(milvus_exceptions PRIVATE milvus_proto)
|
||||
|
|
|
@ -9,33 +9,33 @@
|
|||
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
||||
# or implied. See the License for the specific language governing permissions and limitations under the License
|
||||
|
||||
get_property(PROTOC_EXCUTABLE GLOBAL PROPERTY PROTOC_EXCUTABLE )
|
||||
set( proto_file_names
|
||||
segcore.proto
|
||||
index_cgo_msg.proto
|
||||
plan.proto
|
||||
etcd_meta.proto
|
||||
milvus.proto
|
||||
schema.proto
|
||||
common.proto
|
||||
)
|
||||
|
||||
|
||||
set(proto_file_names common.proto etcd_meta.proto schema.proto milvus.proto index_cgo_msg.proto plan.proto segcore.proto)
|
||||
|
||||
set( PROTO_PATH "${MILVUS_SOURCE_DIR}/../proto/" )
|
||||
set( PROTO_PATH "${MILVUS_SOURCE_DIR}/../proto/" )
|
||||
|
||||
FOREACH(proto_file ${proto_file_names})
|
||||
STRING(REGEX REPLACE "[^/]proto" "" proto_src_file_name ${proto_file})
|
||||
LIST(APPEND MILVUS_PROTO_SRCS "${proto_src_file_name}.pb.cc")
|
||||
STRING( REGEX REPLACE "[^/]proto" "" proto_src_file_name ${proto_file} )
|
||||
LIST( APPEND milvus_proto_srcs "${proto_src_file_name}.pb.cc" )
|
||||
|
||||
ADD_CUSTOM_COMMAND(
|
||||
OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/${proto_src_file_name}.pb.h" "${CMAKE_CURRENT_SOURCE_DIR}/${proto_src_file_name}.pb.cc"
|
||||
COMMAND ${PROTOC_EXCUTABLE} --proto_path=${PROTO_PATH}/
|
||||
--cpp_out=${CMAKE_CURRENT_SOURCE_DIR}/ ${proto_file}
|
||||
DEPENDS ${PROTO_PATH}/${proto_file}
|
||||
)
|
||||
OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/${proto_src_file_name}.pb.h"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/${proto_src_file_name}.pb.cc"
|
||||
COMMAND protobuf::protoc --proto_path=${PROTO_PATH}/
|
||||
--cpp_out=${CMAKE_CURRENT_SOURCE_DIR}/
|
||||
${proto_file}
|
||||
DEPENDS ${PROTO_PATH}/${proto_file} )
|
||||
|
||||
ENDFOREACH(proto_file)
|
||||
|
||||
add_library(milvus_proto STATIC
|
||||
${MILVUS_PROTO_SRCS}
|
||||
)
|
||||
message(${MILVUS_PROTO_SRCS})
|
||||
add_library(milvus_proto STATIC ${milvus_proto_srcs})
|
||||
message(STATUS "milvus proto sources: " ${milvus_proto_srcs})
|
||||
|
||||
target_link_libraries(milvus_proto
|
||||
libprotobuf
|
||||
)
|
||||
|
||||
add_dependencies( milvus_proto protoc )
|
||||
target_link_libraries( milvus_proto PUBLIC protobuf::libprotobuf)
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
# Copyright 2017 gRPC authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
# Licensed to the LF AI & Data foundation under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
|
@ -12,70 +14,34 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
if ( DEFINED ENV{MILVUS_GTEST_URL} )
|
||||
set( GTEST_SOURCE_URL "$ENV{MILVUS_GTEST_URL}" )
|
||||
else()
|
||||
set( GTEST_SOURCE_URL
|
||||
"https://github.com/protocolbuffers/protobuf/releases/download/v3.9.0/protobuf-cpp-3.9.0.zip")
|
||||
endif()
|
||||
set( PROTOBUF_SOURCE_URL
|
||||
"https://github.com/protocolbuffers/protobuf/releases/download/v3.9.0/protobuf-cpp-3.9.0.zip" )
|
||||
|
||||
message( STATUS "Building protobuf-cpp-3.9.0 from source" )
|
||||
|
||||
FetchContent_Declare(
|
||||
protobuf
|
||||
URL ${GTEST_SOURCE_URL}
|
||||
URL_MD5 "9562b27cc6ac5ebd087f201f1310c885"
|
||||
FetchContent_Declare( protobuf
|
||||
URL ${PROTOBUF_SOURCE_URL}
|
||||
URL_MD5 "9562b27cc6ac5ebd087f201f1310c885"
|
||||
DOWNLOAD_DIR ${THIRDPARTY_DOWNLOAD_PATH}
|
||||
SOURCE_DIR ${CMAKE_CURRENT_BINARY_DIR}/protobuf-src
|
||||
BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/protobuf-build
|
||||
|
||||
)
|
||||
|
||||
set( protobuf_BUILD_TESTS CACHE BOOL OFF FORCE )
|
||||
|
||||
set( protobuf_WITH_ZLIB CACHE BOOL OFF FORCE )
|
||||
if ( NOT protobuf_POPULATED )
|
||||
FetchContent_Populate( protobuf )
|
||||
|
||||
add_subdirectory(${protobuf_SOURCE_DIR}/cmake
|
||||
${protobuf_BINARY_DIR}
|
||||
EXCLUDE_FROM_ALL)
|
||||
|
||||
# Adding the following targets:
|
||||
# protobuf::libprotobuf - static target
|
||||
# protobuf::protoc - executable target
|
||||
add_subdirectory( ${protobuf_SOURCE_DIR}/cmake
|
||||
${protobuf_BINARY_DIR}
|
||||
EXCLUDE_FROM_ALL )
|
||||
endif()
|
||||
|
||||
get_target_property( PROTOBUF_INCLUDE_DIR protobuf::libprotobuf INTERFACE_INCLUDE_DIRECTORIES )
|
||||
message( STATUS "protobuf interface include dir" ${PROTOBUF_INCLUDE_DIR} )
|
||||
|
||||
set(_PROTOBUF_LIBRARY_NAME "libprotobuf")
|
||||
|
||||
#if(TARGET libprotoc)
|
||||
set(_gRPC_PROTOBUF_PROTOC_LIBRARIES libprotoc)
|
||||
#endif()
|
||||
|
||||
set(gRPC_PROTOBUF_PROVIDER "module" CACHE STRING "Provider of protobuf library")
|
||||
set_property(CACHE gRPC_PROTOBUF_PROVIDER PROPERTY STRINGS "module" "package")
|
||||
|
||||
|
||||
#if(TARGET protoc)
|
||||
set(_gRPC_PROTOBUF_PROTOC protoc)
|
||||
set(_gRPC_PROTOBUF_PROTOC_EXECUTABLE $<TARGET_FILE:protoc>)
|
||||
#endif()
|
||||
|
||||
# Building the protobuf tests require gmock what is not part of a standard protobuf checkout.
|
||||
# Disable them unless they are explicitly requested from the cmake command line (when we assume
|
||||
# gmock is downloaded to the right location inside protobuf).
|
||||
if(NOT protobuf_BUILD_TESTS)
|
||||
set(protobuf_BUILD_TESTS OFF CACHE BOOL "Build protobuf tests")
|
||||
endif()
|
||||
|
||||
# Disable building protobuf with zlib. Building protobuf with zlib breaks
|
||||
# the build if zlib is not installed on the system.
|
||||
if(NOT protobuf_WITH_ZLIB)
|
||||
set(protobuf_WITH_ZLIB OFF CACHE BOOL "Build protobuf with zlib.")
|
||||
endif()
|
||||
|
||||
if(NOT PROTOBUF_ROOT_DIR)
|
||||
#set(PROTOBUF_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/protobuf)
|
||||
set(PROTOBUF_ROOT_DIR ${protobuf_SOURCE_DIR})
|
||||
endif()
|
||||
|
||||
|
||||
set( PROTOC_EXCUTABLE $<TARGET_FILE:protoc> )
|
||||
set_property( GLOBAL PROPERTY PROTOC_EXCUTABLE ${PROTOC_EXCUTABLE})
|
||||
get_target_property( PROTOC_INCLUDE_DIR protobuf::protoc INCLUDE_DIRECTORIES )
|
||||
message( STATUS "protoc interface include dir" ${PROTOC_INCLUDE_DIR} )
|
||||
|
|
Loading…
Reference in New Issue