You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

CMakeLists.txt 6.1 kB

5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. # This branch assumes that gRPC and all its dependencies are already installed
  2. # on this system, so they can be located by find_package().
  3. # Find Protobuf installation
  4. # Looks for protobuf-config.cmake file installed by Protobuf's cmake installation.
  5. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,-rpath,$ORIGIN:$ORIGIN/lib")
  6. add_library(protobuf::libprotobuf ALIAS protobuf::protobuf)
  7. add_executable(protobuf::libprotoc ALIAS protobuf::protoc)
  8. set(_PROTOBUF_LIBPROTOBUF protobuf::libprotobuf)
  9. if (CMAKE_CROSSCOMPILING)
  10. find_program(_PROTOBUF_PROTOC protoc)
  11. else ()
  12. set(_PROTOBUF_PROTOC $<TARGET_FILE:protobuf::protoc>)
  13. endif ()
  14. # Find gRPC installation
  15. # Looks for gRPCConfig.cmake file installed by gRPC's cmake installation.
  16. if (EXISTS ${grpc_ROOT}/lib64)
  17. set(gRPC_DIR "${grpc_ROOT}/lib64/cmake/grpc")
  18. else ()
  19. set(gRPC_DIR "${grpc_ROOT}/lib/cmake/grpc")
  20. endif ()
  21. message("serving using grpc_DIR : " ${gPRC_DIR})
  22. find_package(gRPC CONFIG REQUIRED)
  23. message(STATUS "Using gRPC ${gRPC_VERSION}")
  24. set(_GRPC_GRPCPP gRPC::grpc++)
  25. set(_REFLECTION gRPC::grpc++_reflection)
  26. if (CMAKE_CROSSCOMPILING)
  27. find_program(_GRPC_CPP_PLUGIN_EXECUTABLE grpc_cpp_plugin)
  28. find_program(_GRPC_PYTHON_PLUGIN_EXECUTABLE grpc_python_plugin)
  29. else ()
  30. set(_GRPC_CPP_PLUGIN_EXECUTABLE $<TARGET_FILE:gRPC::grpc_cpp_plugin>)
  31. set(_GRPC_PYTHON_PLUGIN_EXECUTABLE $<TARGET_FILE:gRPC::grpc_python_plugin>)
  32. endif ()
  33. # Proto file
  34. # Generated sources
  35. file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/proto/")
  36. file(GLOB_RECURSE PROTO_FILE_LIST RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/mindspore_serving/proto/ FOLLOW_SYMLINKS *.proto)
  37. foreach (proto_file ${PROTO_FILE_LIST})
  38. message(------proto file: ${proto_file})
  39. get_filename_component(proto_I_DIR "./" ABSOLUTE)
  40. get_filename_component(proto_file_absolute "mindspore_serving/proto/${proto_file}" ABSOLUTE)
  41. set(proto_file_relative "mindspore_serving/proto/${proto_file}")
  42. string(REGEX REPLACE .proto "" proto_file_prefix ${proto_file})
  43. set(protoc_output_prefix ${CMAKE_CURRENT_BINARY_DIR}/mindspore_serving/proto)
  44. set(hw_proto_srcs "${protoc_output_prefix}/${proto_file_prefix}.pb.cc")
  45. set(hw_proto_hdrs "${protoc_output_prefix}/${proto_file_prefix}.pb.h")
  46. set(hw_grpc_srcs "${protoc_output_prefix}/${proto_file_prefix}.grpc.pb.cc")
  47. set(hw_grpc_hdrs "${protoc_output_prefix}/${proto_file_prefix}.grpc.pb.h")
  48. set(hw_py_pb2 "${protoc_output_prefix}/${proto_file_prefix}_pb2.py")
  49. set(hw_py_pb2_grpc "${protoc_output_prefix}/${proto_file_prefix}_pb2_grpc.py")
  50. add_custom_command(
  51. OUTPUT "${hw_proto_srcs}" "${hw_proto_hdrs}" "${hw_grpc_srcs}" "${hw_grpc_hdrs}" "${hw_py_pb2}" "${hw_py_pb2_grpc}"
  52. WORKING_DIRECTORY ${proto_I_DIR}
  53. COMMAND ${_PROTOBUF_PROTOC}
  54. ARGS --grpc_out "${CMAKE_CURRENT_BINARY_DIR}"
  55. --cpp_out "${CMAKE_CURRENT_BINARY_DIR}"
  56. -I "${proto_I_DIR}"
  57. --plugin=protoc-gen-grpc="${_GRPC_CPP_PLUGIN_EXECUTABLE}"
  58. "${proto_file_relative}"
  59. COMMAND ${_PROTOBUF_PROTOC}
  60. ARGS --grpc_out "${CMAKE_CURRENT_BINARY_DIR}"
  61. --python_out "${CMAKE_CURRENT_BINARY_DIR}"
  62. -I "${proto_I_DIR}"
  63. --plugin=protoc-gen-grpc="${_GRPC_PYTHON_PLUGIN_EXECUTABLE}"
  64. "${proto_file_relative}"
  65. DEPENDS "${proto_file_absolute}")
  66. list(APPEND PROTO_SRC_LIST ${hw_proto_srcs} ${hw_grpc_srcs})
  67. endforeach (proto_file)
  68. include_directories("${CMAKE_CURRENT_BINARY_DIR}/mindspore_serving") # for proto header file
  69. include_directories("${CMAKE_CURRENT_BINARY_DIR}")
  70. # serving_common for c++ server and python interface
  71. file(GLOB_RECURSE UT_SERVING_CORE_SRC RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
  72. "../../../mindspore_serving/ccsrc/master/*.cc"
  73. "../../../mindspore_serving/ccsrc/common/*.cc"
  74. "../../../mindspore_serving/ccsrc/worker/*.cc")
  75. file(GLOB_RECURSE UT_SERVING_STUB RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "../cpp/stub/*.cc")
  76. set(UT_SERVING_COMMON ${UT_SERVING_CORE_SRC} ${UT_SERVING_STUB} ${PROTO_SRC_LIST})
  77. include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../cpp/)
  78. include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../cpp/stub)
  79. include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../cpp/stub/include)
  80. include_directories(${CMAKE_SOURCE_DIR})
  81. include_directories(${CMAKE_SOURCE_DIR}/mindspore_serving/ccsrc)
  82. link_directories(${CMKAE_BINARY_DIR}/securec/src)
  83. # python ut
  84. add_compile_definitions(ENABLE_PYTHON)
  85. file(GLOB_RECURSE PY_SRC_LIST RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "../../../mindspore_serving/ccsrc/python/*.cc")
  86. find_package(Python3 3.7 COMPONENTS Interpreter Development)
  87. if (Python3_FOUND)
  88. set(PYTHON_INCLUDE_DIRS "${Python3_INCLUDE_DIRS}")
  89. set(PYTHON_LIBRARIES "${Python3_LIBRARIES}")
  90. else ()
  91. find_python_package(py_inc py_lib)
  92. set(PYTHON_INCLUDE_DIRS "${py_inc}")
  93. set(PYTHON_LIBRARIES "${py_lib}")
  94. endif ()
  95. include_directories(${PYTHON_INCLUDE_DIRS})
  96. set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/mindspore_serving)
  97. pybind11_add_module(_mindspore_serving ${PY_SRC_LIST} ${UT_SERVING_COMMON})
  98. target_link_libraries(_mindspore_serving PRIVATE "${PYTHON_LIBRARIES}")
  99. target_include_directories(_mindspore_serving PRIVATE ${pybind11_INCLUDE_DIRS})
  100. target_link_libraries(_mindspore_serving PRIVATE mindspore_serving::event mindspore_serving::event_pthreads)
  101. target_link_libraries(_mindspore_serving PRIVATE ${_REFLECTION} ${_GRPC_GRPCPP} ${_PROTOBUF_LIBPROTOBUF} pthread mindspore::glog)
  102. target_link_libraries(_mindspore_serving PRIVATE ${SECUREC_LIBRARY})
  103. # disable auto rpath
  104. set_target_properties(_mindspore_serving PROPERTIES SKIP_BUILD_RPATH TRUE RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
  105. # copy libevent lib
  106. file(GLOB_RECURSE LIBEVENT_LIB_LIST ${libevent_LIBPATH}/libevent* libevent_LIBPATH}/libevent_pthreads*)
  107. file(COPY ${LIBEVENT_LIB_LIST} DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
  108. # copy glog lib
  109. file(GLOB_RECURSE GLOG_LIB_LIST ${glog_LIBPATH}/libglog*)
  110. file(COPY ${GLOG_LIB_LIST} DESTINATION ${CMAKE_CURRENT_BINARY_DIR})

A lightweight and high-performance service module that helps MindSpore developers efficiently deploy online inference services in the production environment.