-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathCMakeLists.txt
147 lines (121 loc) · 4.72 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
cmake_minimum_required(VERSION 3.5)
project(etcd3cppapi CXX)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
include (ExternalProject)
include(FindProtobuf)
include(FindGRPC++)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -g -ggdb -std=c++14")
ExternalProject_Add(
etcd_repo
GIT_REPOSITORY "https://github.com/coreos/etcd.git"
GIT_TAG "fc00305a2e59b4c2d4a53c9fbb4d30741a96ea67"
UPDATE_COMMAND ""
PATCH_COMMAND ""
CONFIGURE_COMMAND ""
SOURCE_DIR "${CMAKE_SOURCE_DIR}/etcd_repo"
INSTALL_COMMAND ""
BUILD_COMMAND ""
)
ExternalProject_Add(
protobuf_repo
GIT_REPOSITORY "https://github.com/gogo/protobuf"
GIT_TAG "2752d97bbd91927dd1c43296dbf8700e50e2708c"
UPDATE_COMMAND ""
PATCH_COMMAND ""
CONFIGURE_COMMAND ""
SOURCE_DIR "${CMAKE_SOURCE_DIR}/protobuf_repo"
INSTALL_COMMAND ""
BUILD_COMMAND ""
)
ExternalProject_Add(
googleapis_repo
GIT_REPOSITORY "https://github.com/googleapis/googleapis"
GIT_TAG "72ebf10ad5b2355df038e275a1543418ea8ac109"
UPDATE_COMMAND ""
PATCH_COMMAND ""
CONFIGURE_COMMAND ""
SOURCE_DIR "${CMAKE_SOURCE_DIR}/googleapis_repo"
INSTALL_COMMAND ""
BUILD_COMMAND ""
)
# Protobuf
find_package(Protobuf 3.0 REQUIRED)
find_package(GRPC++ REQUIRED)
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/etcd/auth/authpb")
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/etcd/mvcc/mvccpb")
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/gogoproto")
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/google/api")
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/google/protobuf")
set(SRC_PROTO_FILES
"protobuf_repo/gogoproto/gogo.proto"
"googleapis_repo/google/api/http.proto"
"googleapis_repo/google/api/annotations.proto"
"etcd_repo/auth/authpb/auth.proto"
"etcd_repo/mvcc/mvccpb/kv.proto"
"etcd_repo/etcdserver/etcdserverpb/rpc.proto"
)
set(DST_PROTO_FILES
"gogoproto/gogo.proto"
"google/api/http.proto"
"google/api/annotations.proto"
"etcd/auth/authpb/auth.proto"
"etcd/mvcc/mvccpb/kv.proto"
"rpc.proto"
)
list(LENGTH SRC_PROTO_FILES LEN)
math(EXPR PROTO_LIST_NUM "${LEN} - 1")
foreach (LIST_ITEM RANGE ${PROTO_LIST_NUM})
list(GET SRC_PROTO_FILES ${LIST_ITEM} SRC_PROTO_FILE)
list(GET DST_PROTO_FILES ${LIST_ITEM} DST_PROTO_FILE)
get_filename_component(DST_PROTO_FILE_DIR ${DST_PROTO_FILE} DIRECTORY)
add_custom_command (OUTPUT "${DST_PROTO_FILE}"
COMMENT "Copying ${SRC_PROTO_FILE} to ${DST_PROTO_FILE_DIR}"
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/${SRC_PROTO_FILE}" "./${DST_PROTO_FILE_DIR}/."
DEPENDS etcd_repo googleapis_repo protobuf_repo
)
endforeach()
foreach(PROTO_FILE ${DST_PROTO_FILES})
set(CC_EXT ".pb.cc")
set(H_EXT ".pb.h")
get_filename_component(FILE_WE ${PROTO_FILE} NAME_WE)
get_filename_component(FILE_LOC ${PROTO_FILE} DIRECTORY)
set(CC_FILE "${CMAKE_CURRENT_BINARY_DIR}/${FILE_LOC}/${FILE_WE}${CC_EXT}")
set(H_FILE "${CMAKE_CURRENT_BINARY_DIR}/${FILE_LOC}/${FILE_WE}${H_EXT}")
add_custom_command (OUTPUT ${CC_FILE} ${H_FILE}
COMMENT "Generating ${CC_FILE} and ${H_FILE} from ${PROTO_FILE}..."
COMMAND ${PROTOBUF_PROTOC_EXECUTABLE} -I. --cpp_out=${CMAKE_CURRENT_BINARY_DIR} --plugin=`which grpc_cpp_plugin` ${PROTO_FILE}
DEPENDS "${PROTO_FILE}"
)
set(CC_FILES ${CC_FILES} ${CC_FILE})
set(H_FILES ${H_FILES} ${H_FILE})
endforeach()
add_custom_command (OUTPUT rpc.grpc.pb.cc rpc.grpc.pb.h
COMMENT "Generating rpc.grpc.pb.cc and rpc.grpc.pb.h..."
COMMAND ${PROTOBUF_PROTOC_EXECUTABLE} -I. --grpc_out=${CMAKE_CURRENT_BINARY_DIR} --plugin=protoc-gen-grpc=`which grpc_cpp_plugin` rpc.proto
DEPENDS rpc.proto
)
include_directories(${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/src/)
add_library(etcd3cppapi SHARED ${CC_FILES}
${H_FILES}
rpc.grpc.pb.cc
rpc.grpc.pb.h)
target_link_libraries(etcd3cppapi pthread ${GRPC++_LIBRARY} ${PROTOBUF_LIBRARY})
add_executable(watcher_example_1
rpc.grpc.pb.cc
rpc.grpc.pb.h
tst/watcher.cpp)
add_dependencies(watcher_example_1 etcd3cppapi)
target_link_libraries(watcher_example_1 etcd3cppapi)
add_executable(watcher_example_2
rpc.grpc.pb.cc
rpc.grpc.pb.h
tst/watcher.cpp)
add_dependencies(watcher_example_2 etcd3cppapi)
target_link_libraries(watcher_example_2 etcd3cppapi)
add_executable(testcases
rpc.grpc.pb.cc
rpc.grpc.pb.h
tst/testcases.cpp)
add_dependencies(testcases etcd3cppapi)
target_link_libraries(testcases etcd3cppapi)