-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
151 lines (137 loc) · 5.09 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
145
146
147
148
149
150
151
cmake_minimum_required(VERSION 3.11)
if(POLICY CMP0048)
cmake_policy(SET CMP0048 NEW)
endif()
set(PACKAGE_NAME "ArgusD")
set(PACKAGE_VERSION_MAJOR "0")
set(PACKAGE_VERSION_MINOR "5")
set(PACKAGE_VERSION_PATCH "0")
set(PACKAGE_VERSION "${PACKAGE_VERSION_MAJOR}.${PACKAGE_VERSION_MINOR}.${PACKAGE_VERSION_PATCH}")
set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
set(PACKAGE_DESCRIPTION "Argus Daemon - File Integrity Monitoring for Kubernetes")
set(PACKAGE_URL "https://clustergarage.io/argus")
set(PACKAGE_BUGREPORT "https://github.com/clustergarage/argusd/issues")
project(${PACKAGE_NAME} VERSION ${PACKAGE_VERSION} LANGUAGES C CXX)
include(ExternalProject)
include(FetchContent)
set(CMAKE_C_STANDARD 99)
set(CMAKE_CXX_STANDARD 17)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE)
endif()
FetchContent_Declare(grpc
GIT_REPOSITORY https://github.com/grpc/grpc
GIT_TAG v1.17.2)
FetchContent_GetProperties(grpc)
if(NOT grpc_POPULATED)
FetchContent_Populate(grpc)
set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE)
set(BUILD_STATIC_LIBS ON CACHE BOOL "" FORCE)
set(BUILD_PACKAGING OFF CACHE BOOL "" FORCE)
set(BUILD_TESTING OFF CACHE BOOL "" FORCE)
# c-ares
set(CARES_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(CARES_BUILD_TOOLS OFF CACHE BOOL "" FORCE)
set(CARES_SHARED OFF CACHE BOOL "" FORCE)
set(CARES_STATIC ON CACHE BOOL "" FORCE)
set(CARES_STATIC_PIC ON CACHE BOOL "" FORCE)
# zlib
set(BUILD_examples OFF CACHE BOOL "" FORCE)
set(SKIP_INSTALL_LIBRARIES ON CACHE BOOL "" FORCE)
# protobuf
set(protobuf_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
set(protobuf_BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE)
set(protobuf_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(protobuf_MSVC_STATIC_RUNTIME OFF CACHE BOOL "" FORCE)
set(protobuf_WITH_ZLIB OFF CACHE BOOL "" FORCE)
# gflags
set(BUILD_gflags_LIB ON CACHE BOOL "" FORCE)
set(BUILD_gflags_nothreads_LIB OFF CACHE BOOL "" FORCE)
set(GFLAGS_NAMESPACE "google" CACHE STRING "" FORCE)
set(INSTALL_HEADERS ON CACHE BOOL "" FORCE)
set(INSTALL_SHARED_LIBS OFF CACHE BOOL "" FORCE)
set(INSTALL_STATIC_LIBS ON CACHE BOOL "" FORCE)
# grpc
set(gRPC_BUILD_CSHARP_EXT OFF CACHE BOOL "" FORCE)
set(gRPC_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(gRPC_INSTALL ON CACHE BOOL "" FORCE)
set(gRPC_USE_PROTO_LITE ON CACHE BOOL "" FORCE)
add_subdirectory(${grpc_SOURCE_DIR} ${grpc_BINARY_DIR} EXCLUDE_FROM_ALL)
endif()
FetchContent_Declare(glog
GIT_REPOSITORY https://github.com/google/glog
GIT_TAG v0.3.5)
FetchContent_GetProperties(glog)
if(NOT glog_POPULATED)
FetchContent_Populate(glog)
set(WITH_GFLAGS OFF CACHE BOOL "" FORCE)
add_subdirectory(${glog_SOURCE_DIR} ${glog_BINARY_DIR} EXCLUDE_FROM_ALL)
endif()
FetchContent_Declare(fmt
GIT_REPOSITORY https://github.com/fmtlib/fmt
GIT_TAG 5.2.1)
FetchContent_GetProperties(fmt)
if(NOT fmt_POPULATED)
FetchContent_Populate(fmt)
set(FMT_DOC OFF CACHE BOOL "" FORCE)
set(FMT_TEST OFF CACHE BOOL "" FORCE)
add_subdirectory(${fmt_SOURCE_DIR} ${fmt_BINARY_DIR} EXCLUDE_FROM_ALL)
endif()
# Builds libcontainer project from the git repo.
set(LIBCONTAINER_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/libcontainer/include)
set(LIBCONTAINER_LIBRARY ${CMAKE_CURRENT_BINARY_DIR}/libcontainer/lib/libcontainer.a)
ExternalProject_Add(libcontainer
PREFIX libcontainer
GIT_REPOSITORY https://github.com/clustergarage/libcontainer
GIT_TAG v0.1.0
BUILD_ALWAYS 1
BUILD_BYPRODUCTS ${LIBCONTAINER_LIBRARY}
CMAKE_ARGS
-DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
)
#FetchContent_Declare(libcontainer
# PREFIX libcontainer
# GIT_REPOSITORY https://github.com/clustergarage/libcontainer
# GIT_TAG v0.1.0)
#FetchContent_GetProperties(libcontainer)
#if(NOT libcontainer_POPULATED)
# FetchContent_Populate(libcontainer)
# add_subdirectory(${libcontainer_SOURCE_DIR} ${libcontainer_BINARY_DIR} EXCLUDE_FROM_ALL)
# set(LIBCONTAINER_INCLUDE_DIR $<TARGET_PROPERTY:libcontainer,INCLUDE_DIRECTORIES>)
# set(LIBCONTAINER_LIBRARY $<TARGET_FILE:libcontainer>)
#endif()
add_subdirectory(lib)
add_subdirectory(argus-proto)
set(ARGUS_PROTO_SRCS ${PROJECT_SOURCE_DIR}/argus-proto/c++/argus.pb.cc
${PROJECT_SOURCE_DIR}/argus-proto/c++/health.pb.cc)
set(ARGUS_GRPC_SRCS ${PROJECT_SOURCE_DIR}/argus-proto/c++/argus.grpc.pb.cc
${PROJECT_SOURCE_DIR}/argus-proto/c++/health.grpc.pb.cc)
add_executable(argusd
src/argusd_server.cc
src/argusd_impl.cc
src/argusd_auth.cc
src/health_impl.cc
${ARGUS_PROTO_SRCS}
${ARGUS_GRPC_SRCS}
)
add_dependencies(argusd argusnotify libcontainer fmt glog grpc)
target_include_directories(argusd
# Include headers from directories like <[lib|argus-proto]/file.h>.
PRIVATE ${CMAKE_SOURCE_DIR}
PRIVATE ${PROJECT_SOURCE_DIR}/lib
# Include generated *.pb.h files.
PRIVATE ${PROJECT_SOURCE_DIR}/argus-proto
PRIVATE ${LIBCONTAINER_INCLUDE_DIR}
)
target_link_libraries(argusd
argusnotify
${LIBCONTAINER_LIBRARY}
fmt glog gflags
grpc++ grpc gpr address_sorting
libprotobuf ssl crypto
)
if(CMAKE_BUILD_TYPE STREQUAL Release)
# Strip all symbols from built binary.
add_custom_command(TARGET argusd POST_BUILD
COMMAND strip -s $<TARGET_FILE:argusd>)
endif()