CMakeLists.txt 3.3 KB
Newer Older
G
guru4elephant 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
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")

40
      set(PDCODEGEN "${CMAKE_BINARY_DIR}/core/pdcodegen/pdcodegen")
G
guru4elephant 已提交
41 42 43 44 45 46 47
      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}
G
guru4elephant 已提交
48 49
                  --plugin=protoc-gen-pdcodegen=${CMAKE_BINARY_DIR}/core/pdcodegen/pdcodegen
                  --proto_path=${CMAKE_SOURCE_DIR}/core/predictor/proto
G
guru4elephant 已提交
50
                  ${_protobuf_include_path} ${ABS_FIL}
51
              DEPENDS ${ABS_FIL} ${Protobuf_PROTOC_EXECUTABLE} ${PDCODEGEN}
G
guru4elephant 已提交
52 53 54 55 56 57 58 59 60
              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}
G
guru4elephant 已提交
61
                  --plugin=protoc-gen-pdcodegen=${CMAKE_BINARY_DIR}/core/pdcodegen/pdcodegen
G
guru4elephant 已提交
62
                  ${_protobuf_include_path} ${ABS_FIL}
63
	      DEPENDS ${ABS_FIL} ${Protobuf_PROTOC_EXECUTABLE} ${PDCODEGEN}
G
guru4elephant 已提交
64 65 66 67 68 69 70 71 72 73
              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()

W
sdk-cpp  
wangguibao 已提交
74
FILE(GLOB protos ${CMAKE_CURRENT_LIST_DIR}/*.proto)
G
guru4elephant 已提交
75 76
list(APPEND protos ${CMAKE_SOURCE_DIR}/core//predictor/proto/pds_option.proto
        ${CMAKE_SOURCE_DIR}/core//predictor/proto/builtin_format.proto)
77
PROTOBUF_GENERATE_SERVING_CPP(FALSE PROTO_SRCS PROTO_HDRS ${protos})
W
sdk-cpp  
wangguibao 已提交
78
LIST(APPEND sdk_cpp_srcs ${PROTO_SRCS})