From 1ae148db9ffbcd495ea78e897ee8b614c321327b Mon Sep 17 00:00:00 2001 From: guru4elephant Date: Mon, 13 Jan 2020 13:22:33 +0800 Subject: [PATCH] refine sdk folder --- sdk-cpp/CMakeLists.txt | 1 + sdk-cpp/include/factory.h | 5 --- sdk-cpp/proto/CMakeLists.txt | 72 ++++++++++++++++++++++++++++++++++++ 3 files changed, 73 insertions(+), 5 deletions(-) diff --git a/sdk-cpp/CMakeLists.txt b/sdk-cpp/CMakeLists.txt index 0c710e26..340d60f6 100644 --- a/sdk-cpp/CMakeLists.txt +++ b/sdk-cpp/CMakeLists.txt @@ -1,3 +1,4 @@ + include(src/CMakeLists.txt) include(proto/CMakeLists.txt) add_library(sdk-cpp ${sdk_cpp_srcs}) diff --git a/sdk-cpp/include/factory.h b/sdk-cpp/include/factory.h index 777f79df..7e8d2a98 100644 --- a/sdk-cpp/include/factory.h +++ b/sdk-cpp/include/factory.h @@ -98,7 +98,6 @@ namespace brpc = baidu::rpc; #define REGIST_STUB_OBJECT_WITH_TAG(D, C, R, I, O, T) \ __attribute__((constructor)) static void PDS_STR_CAT(GlobalRegistObject, \ __LINE__)(void) { \ - RAW_LOG_INFO("REGIST_STUB_OBJECT_WITH_TAG"); \ ::baidu::paddle_serving::sdk_cpp::Factory< \ ::baidu::paddle_serving::sdk_cpp::StubImpl, \ ::baidu::paddle_serving::sdk_cpp::Stub>* factory = \ @@ -158,10 +157,6 @@ class FactoryPool { return -1; } - RAW_LOG_INFO("Succ insert one factory, tag: %s, base type %s", - tag.c_str(), - typeid(B).name()); - return 0; } diff --git a/sdk-cpp/proto/CMakeLists.txt b/sdk-cpp/proto/CMakeLists.txt index 0807eb30..77d5cdf3 100644 --- a/sdk-cpp/proto/CMakeLists.txt +++ b/sdk-cpp/proto/CMakeLists.txt @@ -1,3 +1,75 @@ +function(PROTOBUF_GENERATE_SERVING_CPP FOR_SERVING_SIDE SRCS HDRS ) + if(NOT ARGN) + message(SEND_ERROR "Error: PROTOBUF_GENERATE_SERVING_CPP() called without any proto files") + return() + endif() + + if(PROTOBUF_GENERATE_CPP_APPEND_PATH) + # Create an include path for each file specified + foreach(FIL ${ARGN}) + get_filename_component(ABS_FIL ${FIL} ABSOLUTE) + get_filename_component(ABS_PATH ${ABS_FIL} PATH) + list(FIND _protobuf_include_path ${ABS_PATH} _contains_already) + if(${_contains_already} EQUAL -1) + list(APPEND _protobuf_include_path -I ${ABS_PATH}) + endif() + endforeach() + else() + set(_protobuf_include_path -I ${CMAKE_CURRENT_SOURCE_DIR}) + endif() + + if(DEFINED PROTOBUF_IMPORT_DIRS) + foreach(DIR ${Protobuf_IMPORT_DIRS}) + get_filename_component(ABS_PATH ${DIR} ABSOLUTE) + list(FIND _protobuf_include_path ${ABS_PATH} _contains_already) + if(${_contains_already} EQUAL -1) + list(APPEND _protobuf_include_path -I ${ABS_PATH}) + endif() + endforeach() + endif() + + set(${SRCS}) + set(${HDRS}) + foreach(FIL ${ARGN}) + get_filename_component(ABS_FIL ${FIL} ABSOLUTE) + get_filename_component(FIL_WE ${FIL} NAME_WE) + + list(APPEND ${SRCS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.cc") + list(APPEND ${HDRS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.h") + + if (${FOR_SERVING_SIDE}) + add_custom_command( + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.cc" + "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.h" + COMMAND ${Protobuf_PROTOC_EXECUTABLE} + ARGS --cpp_out=${CMAKE_CURRENT_BINARY_DIR} + --pdcodegen_out=${CMAKE_CURRENT_BINARY_DIR} + --plugin=protoc-gen-pdcodegen=${CMAKE_BINARY_DIR}/pdcodegen/pdcodegen + --proto_path=${CMAKE_SOURCE_DIR}/predictor/proto + ${_protobuf_include_path} ${ABS_FIL} + DEPENDS ${ABS_FIL} ${Protobuf_PROTOC_EXECUTABLE} + COMMENT "Running Paddle-serving C++ protocol buffer compiler on ${FIL}" + VERBATIM) + else() + add_custom_command( + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.cc" + "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.h" + COMMAND ${Protobuf_PROTOC_EXECUTABLE} + ARGS --cpp_out=${CMAKE_CURRENT_BINARY_DIR} + --pdcodegen_out=${CMAKE_CURRENT_BINARY_DIR} + --plugin=protoc-gen-pdcodegen=${CMAKE_BINARY_DIR}/pdcodegen/pdcodegen + ${_protobuf_include_path} ${ABS_FIL} + DEPENDS ${ABS_FIL} ${Protobuf_PROTOC_EXECUTABLE} + COMMENT "Running Paddle-serving C++ protocol buffer compiler on ${FIL}" + VERBATIM) + endif() + endforeach() + + set_source_files_properties(${${SRCS}} ${${HDRS}} PROPERTIES GENERATED TRUE) + set(${SRCS} ${${SRCS}} PARENT_SCOPE) + set(${HDRS} ${${HDRS}} PARENT_SCOPE) +endfunction() + FILE(GLOB protos ${CMAKE_CURRENT_LIST_DIR}/*.proto) list(APPEND protos ${CMAKE_SOURCE_DIR}/predictor/proto/pds_option.proto ${CMAKE_SOURCE_DIR}/predictor/proto/builtin_format.proto) -- GitLab