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 5.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. add_library(UT_PROTO_SRC_LIB STATIC ${PROTO_SRC_LIST})
  69. include_directories("${CMAKE_CURRENT_BINARY_DIR}/mindspore_serving") # for proto header file
  70. include_directories("${CMAKE_CURRENT_BINARY_DIR}")
  71. # serving_common for c++ server and python interface
  72. file(GLOB_RECURSE UT_CORE_SRC RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
  73. "../../../mindspore_serving/ccsrc/master/*.cc"
  74. "../../../mindspore_serving/ccsrc/common/*.cc"
  75. "../../../mindspore_serving/ccsrc/worker/*.cc")
  76. file(GLOB_RECURSE UT_RM_SRC RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
  77. "../../../mindspore_serving/ccsrc/worker/inference/*.cc")
  78. list(REMOVE_ITEM UT_CORE_SRC ${UT_RM_SRC})
  79. list(APPEND FINAL_SERVING_SRC ${UT_CORE_SRC})
  80. #add_library(serving_common SHARED ${SERVING_SRC})
  81. include(CheckPIESupported)
  82. check_pie_supported()
  83. # set_property(TARGET serving_common PROPERTY POSITION_INDEPENDENT_CODE TRUE)
  84. include_directories(${CMAKE_CURRENT_SOURCE_DIR})
  85. include_directories(${CMAKE_CURRENT_SOURCE_DIR}/stub)
  86. include_directories(${CMAKE_SOURCE_DIR})
  87. include_directories(${CMAKE_SOURCE_DIR}/mindspore_serving/ccsrc)
  88. link_directories(${CMAKE_BINARY_DIR}/googletest/googlemock/gtest)
  89. link_directories(${CMKAE_BINARY_DIR}/securec/src)
  90. file(GLOB_RECURSE UT_LIST RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.cc")
  91. set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR})
  92. add_executable(serving_ut ${UT_LIST} ${FINAL_SERVING_SRC})
  93. target_link_libraries(serving_ut mindspore_serving::gtest)
  94. target_link_libraries(serving_ut UT_PROTO_SRC_LIB mindspore_serving::event mindspore_serving::event_pthreads)
  95. target_link_libraries(serving_ut ${_REFLECTION} ${_GRPC_GRPCPP} ${_PROTOBUF_LIBPROTOBUF} pthread mindspore::glog)
  96. target_link_libraries(serving_ut ${SECUREC_LIBRARY})

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