-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
86 lines (77 loc) · 2.91 KB
/
CMakeLists.txt
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
cmake_minimum_required(VERSION 3.2)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
project(cRaft C CXX)
#set(CMAKE_CXX_FLAGS "-g")
set(CMAKE_PREFIX_PATH "/usr/local" ${CMAKE_PREFIX_PATH})
include(common.cmake)
include_directories(${PROJECT_SOURCE_DIR}/src)
# 设置 libtorch 的路径
# include_directories(${PROJECT_SOURCE_DIR}/third_party/libtorch/include/torch/csrc/api/include)
# include_directories(${PROJECT_SOURCE_DIR}/third_party/libtorch/include)
set(Torch_DIR ${PROJECT_SOURCE_DIR}/thrid_party/libtorch/share/cmake/Torch)
find_package(Torch REQUIRED)
if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_GLIBCXX_USE_CXX11_ABI=1")
endif()
# Protos Directory
file(GLOB PROTO_INPUT "./src/protos/*.proto")
get_filename_component(protos_h_cc "./protos_h_cc" ABSOLUTE)
get_filename_component(protos_h_cc "./src/rpc" ABSOLUTE)
message(protos_h_cc = ${protos_h_cc})
# Set the output paths
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)
# Go through every proto file for processing
foreach(hw_proto ${PROTO_INPUT})
get_filename_component(hw_proto_path "${hw_proto}" PATH)
get_filename_component(base_name_we ${hw_proto} NAME_WE)
set(hw_proto_srcs "${protos_h_cc}/${base_name_we}.pb.cc")
set(hw_proto_hdrs "${protos_h_cc}/${base_name_we}.pb.h")
set(hw_grpc_srcs "${protos_h_cc}/${base_name_we}.grpc.pb.cc")
set(hw_grpc_hdrs "${protos_h_cc}/${base_name_we}.grpc.pb.h")
add_custom_command(
OUTPUT "${hw_proto_srcs}" "${hw_proto_hdrs}" "${hw_grpc_srcs}" "${hw_grpc_hdrs}"
COMMAND ${_PROTOBUF_PROTOC}
ARGS --grpc_out "${protos_h_cc}"
--cpp_out "${protos_h_cc}"
-I "${hw_proto_path}"
--plugin=protoc-gen-grpc="${_GRPC_CPP_PLUGIN_EXECUTABLE}"
"${hw_proto}"
DEPENDS "${hw_proto}")
set(hw_proto_srcs_all ${hw_proto_srcs_all} ${hw_proto_srcs})
set(hw_proto_hdrs_all ${hw_proto_hdrs_all} ${hw_proto_hdrs})
set(hw_grpc_srcs_all ${hw_grpc_srcs_all} ${hw_grpc_srcs})
set(hw_grpc_hdrs_all ${hw_grpc_hdrs_all} ${hw_grpc_hdrs})
endforeach()
aux_source_directory(./src/raft/ RAFT_SRC)
set(hw_grpc_srcs_all ${hw_grpc_srcs_all} ${hw_grpc_srcs})
message(raft src = ${RAFT_SRC})
message(raft h = ${RAFT_H})
# # Include generated *.pb.h files
include_directories("${CMAKE_CURRENT_BINARY_DIR}")
# hw_grpc_proto
add_library(craft STATIC
${hw_grpc_srcs_all}
${hw_grpc_hdrs_all}
${hw_proto_srcs_all}
${hw_proto_hdrs_all}
${RAFT_SRC}
)
target_link_libraries(craft PUBLIC
absl::flags
absl::flags_parse
${_REFLECTION}
${_GRPC_GRPCPP}
${_PROTOBUF_LIBPROTOBUF}
libgo
dl
pthread
${TORCH_LIBRARIES}
)
foreach(_target server client)
add_executable(${_target} "${_target}.cc")
target_link_libraries(${_target}
craft
)
endforeach()