-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
130 lines (109 loc) · 3.93 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
cmake_minimum_required(VERSION 3.10)
project(hw-cpp VERSION 1.0 DESCRIPTION "hw client in C++")
# Find required dependencies for HTTP client
find_package(CURL REQUIRED)
set(YAML_CPP_DIR "<path-to-yaml-cpp>")
find_package(yaml-cpp REQUIRED)
include_directories(${YAML_CPP_DIR}/include)
link_directories(${YAML_CPP_DIR}/lib)
find_package(nlohmann_json REQUIRED)
include_directories(${YAML_CPP_INCLUDE_DIRS})
# Protobuf and gRPC
# This assumes that gRPC and all its dependencies are already installed
# on this system, so they can be located by find_package().
# Find Protobuf installation
# Looks for protobuf-config.cmake file installed by Protobuf's cmake installation.
option(protobuf_MODULE_COMPATIBLE TRUE)
# Set CMAKE_PREFIX_PATH to the directory containing protobuf-config.cmake
set(CMAKE_PREFIX_PATH "~/.local/lib/cmake/")
find_package(Protobuf CONFIG REQUIRED)
message(STATUS "Using protobuf ${Protobuf_VERSION}")
set(_PROTOBUF_LIBPROTOBUF protobuf::libprotobuf)
set(_REFLECTION gRPC::grpc++_reflection)
if(CMAKE_CROSSCOMPILING)
find_program(_PROTOBUF_PROTOC protoc)
else()
set(_PROTOBUF_PROTOC $<TARGET_FILE:protobuf::protoc>)
endif()
# Find gRPC installation
# Looks for gRPCConfig.cmake file installed by gRPC's cmake installation.
find_package(gRPC CONFIG REQUIRED)
message(STATUS "Using gRPC ${gRPC_VERSION}")
set(_GRPC_GRPCPP gRPC::grpc++)
if(CMAKE_CROSSCOMPILING)
find_program(_GRPC_CPP_PLUGIN_EXECUTABLE grpc_cpp_plugin)
else()
set(_GRPC_CPP_PLUGIN_EXECUTABLE $<TARGET_FILE:gRPC::grpc_cpp_plugin>)
endif()
# If using Armadillo
# Ensure that Armadillo is installed on the system
#set(ARMADILLO_LIBRARY "~/.local/lib/cmake/lib/libarmadillo.so")
#set(ARMADILLO_INCLUDE_DIR "~/.local/lib/cmake/include")
#set(ARMADILLO_INCLUDE_DIRS "/usr/include")
# Proto file for project
get_filename_component(fedn_proto "src/protos/fedn.proto" ABSOLUTE)
get_filename_component(fedn_proto_path "${fedn_proto}" PATH)
# Generated sources
set(fedn_proto_srcs "${CMAKE_CURRENT_BINARY_DIR}/fedn.pb.cc")
set(fedn_proto_hdrs "${CMAKE_CURRENT_BINARY_DIR}/fedn.pb.h")
set(fedn_grpc_srcs "${CMAKE_CURRENT_BINARY_DIR}/fedn.grpc.pb.cc")
set(fedn_grpc_hdrs "${CMAKE_CURRENT_BINARY_DIR}/fedn.grpc.pb.h")
add_custom_command(
OUTPUT "${fedn_proto_srcs}" "${fedn_proto_hdrs}" "${fedn_grpc_srcs}" "${fedn_grpc_hdrs}"
COMMAND ${_PROTOBUF_PROTOC}
ARGS --grpc_out "${CMAKE_CURRENT_BINARY_DIR}"
--cpp_out "${CMAKE_CURRENT_BINARY_DIR}"
-I "${fedn_proto_path}"
--plugin=protoc-gen-grpc="${_GRPC_CPP_PLUGIN_EXECUTABLE}"
"${fedn_proto}"
DEPENDS "${fedn_proto}")
# Include generated *.pb.h files
# if ${ARMADILLO_INCLUDE_DIR} is set, include it
if(DEFINED ${ARMADILLO_INCLUDE_DIR})
include_directories("${CMAKE_CURRENT_BINARY_DIR}" "${ARMADILLO_INCLUDE_DIRS}" "${ARMADILLO_INCLUDE_DIR}")
else()
include_directories("${CMAKE_CURRENT_BINARY_DIR}")
endif()
# fedn_grpc_proto
add_library(fedn_grpc_proto
${fedn_grpc_srcs}
${fedn_grpc_hdrs}
${fedn_proto_srcs}
${fedn_proto_hdrs})
target_link_libraries(fedn_grpc_proto
${_REFLECTION}
${_GRPC_GRPCPP}
${_PROTOBUF_LIBPROTOBUF})
# Include directories fednlib
include_directories(include)
# Source files fednlib
set(SOURCES
src/http.cpp
src/grpc.cpp
src/fedn.cpp
src/utils.cpp
)
# Add fednlib as a library
add_library(fednlib STATIC ${SOURCES})
# Create an alias target
add_library(fednlib::fednlib ALIAS fednlib)
# Link the fednlib with libraries
target_link_libraries(fednlib PUBLIC
fedn_grpc_proto
absl::flags
absl::flags_parse
${_REFLECTION}
${_GRPC_GRPCPP}
${_PROTOBUF_LIBPROTOBUF}
CURL::libcurl
yaml-cpp
${YAML_CPP_LIBRARIES}
nlohmann_json::nlohmann_json
)
if(DEFINED ${ARMADILLO_LIBRARY})
target_link_libraries(fednlib PRIVATE ${ARMADILLO_LIBRARY})
endif()
# Link header files to fednlib
target_include_directories(fednlib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
# Include directories
include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR})