-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
282 lines (233 loc) · 9 KB
/
CMakeLists.txt
File metadata and controls
282 lines (233 loc) · 9 KB
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
cmake_minimum_required(VERSION 3.16)
project(pressured C)
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Build type
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug)
endif()
# Compiler flags
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wpedantic")
set(CMAKE_C_FLAGS_DEBUG "-g -O0 -DDEBUG")
set(CMAKE_C_FLAGS_RELEASE "-O2 -DNDEBUG")
# TLS backend selection (openssl or mbedtls)
set(TLS_BACKEND "openssl" CACHE STRING "TLS backend: openssl or mbedtls")
set_property(CACHE TLS_BACKEND PROPERTY STRINGS "openssl" "mbedtls")
# Find dependencies
find_package(PkgConfig REQUIRED)
pkg_check_modules(CURL REQUIRED libcurl)
pkg_check_modules(JSON_C REQUIRED json-c)
pkg_check_modules(LUA REQUIRED lua5.4)
pkg_check_modules(ZLIB REQUIRED zlib)
# Find TLS backend
if(TLS_BACKEND STREQUAL "mbedtls")
pkg_check_modules(MBEDTLS REQUIRED mbedtls)
message(STATUS "Using mbedTLS for crypto")
set(CRYPTO_SOURCE "plugins/storage/crypto_mbedtls.c")
set(CRYPTO_INCLUDE_DIRS ${MBEDTLS_INCLUDE_DIRS})
# mbedtls pkg-config only returns -lmbedtls, but we need all three libs
set(CRYPTO_LIBRARIES mbedtls mbedx509 mbedcrypto)
set(CRYPTO_LIBRARY_DIRS ${MBEDTLS_LIBRARY_DIRS})
else()
pkg_check_modules(OPENSSL REQUIRED openssl)
message(STATUS "Using OpenSSL for crypto")
set(CRYPTO_SOURCE "plugins/storage/crypto_openssl.c")
set(CRYPTO_INCLUDE_DIRS ${OPENSSL_INCLUDE_DIRS})
set(CRYPTO_LIBRARIES ${OPENSSL_LIBRARIES})
set(CRYPTO_LIBRARY_DIRS ${OPENSSL_LIBRARY_DIRS})
endif()
# Include directories
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/src
${CURL_INCLUDE_DIRS}
${JSON_C_INCLUDE_DIRS}
${LUA_INCLUDE_DIRS}
${CRYPTO_INCLUDE_DIRS}
)
# Link directories (needed for Alpine where libs are in non-standard locations)
link_directories(
${CURL_LIBRARY_DIRS}
${JSON_C_LIBRARY_DIRS}
${LUA_LIBRARY_DIRS}
${CRYPTO_LIBRARY_DIRS}
)
# Core library (no Lua dependency - Lua is in the plugin)
add_library(pressured_core STATIC
src/config.c
src/cgroup.c
src/kubelet.c
src/event_generator.c
src/event.c
src/log.c
src/plugin.c
src/http.c
src/service_registry.c
)
# Enable Position Independent Code for static library (needed when linking into shared libs)
set_target_properties(pressured_core PROPERTIES POSITION_INDEPENDENT_CODE ON)
target_link_libraries(pressured_core
${CURL_LIBRARIES}
${JSON_C_LIBRARIES}
pthread
dl
m
)
# Main executable
add_executable(pressured src/main.c)
target_link_libraries(pressured pressured_core)
# Make the main executable export symbols for plugins
set_target_properties(pressured PROPERTIES ENABLE_EXPORTS ON)
# Tests
enable_testing()
add_executable(test_cgroup src/test_cgroup.c)
target_link_libraries(test_cgroup pressured_core)
add_test(NAME test_cgroup COMMAND test_cgroup)
add_executable(test_plugin src/test_plugin.c)
target_link_libraries(test_plugin pressured_core)
set_target_properties(test_plugin PROPERTIES ENABLE_EXPORTS ON)
add_test(NAME test_plugin COMMAND test_plugin)
add_executable(test_http src/test_http.c)
target_link_libraries(test_http pressured_core)
add_test(NAME test_http COMMAND test_http)
add_executable(test_service_registry src/test_service_registry.c)
target_link_libraries(test_service_registry pressured_core)
add_test(NAME test_service_registry COMMAND test_service_registry)
# Lua plugin shared library
add_library(pressured_plugin_lua SHARED
plugins/lua/lua_plugin.c
plugins/lua/binding_log.c
plugins/lua/binding_http.c
plugins/lua/binding_storage.c
)
set_target_properties(pressured_plugin_lua PROPERTIES
OUTPUT_NAME "lua"
PREFIX ""
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/plugins"
)
target_include_directories(pressured_plugin_lua PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/src
${CMAKE_CURRENT_SOURCE_DIR}/plugins/lua
${LUA_INCLUDE_DIRS}
)
target_link_libraries(pressured_plugin_lua
pressured_core
${LUA_LIBRARIES}
)
# Local storage plugin shared library
add_library(storage_local SHARED
plugins/storage/local_storage.c
)
set_target_properties(storage_local PROPERTIES
OUTPUT_NAME "local-storage"
PREFIX ""
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/plugins"
)
target_include_directories(storage_local PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/include
${JSON_C_INCLUDE_DIRS}
)
target_link_libraries(storage_local
${JSON_C_LIBRARIES}
)
# Storage plugin test
add_executable(test_storage plugins/storage/test_storage.c)
target_link_libraries(test_storage pressured_core)
set_target_properties(test_storage PROPERTIES ENABLE_EXPORTS ON)
add_test(NAME test_storage COMMAND test_storage)
# S3 storage plugin shared library
# MULTIPART is the default because S3 doesn't support Transfer-Encoding: chunked
# for unknown-size uploads. STREAMING mode will fallback to MULTIPART when size is unknown.
set(S3_UPLOAD_MODE "MULTIPART" CACHE STRING "S3 upload mode: STREAMING or MULTIPART")
set_property(CACHE S3_UPLOAD_MODE PROPERTY STRINGS "STREAMING" "MULTIPART")
add_library(storage_s3 SHARED
plugins/storage/s3_storage.c
${CRYPTO_SOURCE}
)
if(S3_UPLOAD_MODE STREQUAL "STREAMING")
target_compile_definitions(storage_s3 PRIVATE S3_UPLOAD_STREAMING)
message(STATUS "S3 storage: using STREAMING mode (single PUT, max 5GB)")
else()
target_compile_definitions(storage_s3 PRIVATE S3_UPLOAD_MULTIPART)
message(STATUS "S3 storage: using MULTIPART mode (unlimited size)")
endif()
set_target_properties(storage_s3 PROPERTIES
OUTPUT_NAME "s3-storage"
PREFIX ""
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/plugins"
)
target_include_directories(storage_s3 PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/plugins/storage
${JSON_C_INCLUDE_DIRS}
${CURL_INCLUDE_DIRS}
${CRYPTO_INCLUDE_DIRS}
)
target_link_libraries(storage_s3
${JSON_C_LIBRARIES}
${CURL_LIBRARIES}
${CRYPTO_LIBRARIES}
)
# AWS SigV4 signing unit tests
add_executable(test_sigv4 plugins/storage/test_sigv4.c plugins/storage/sigv4.c ${CRYPTO_SOURCE})
target_include_directories(test_sigv4 PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/plugins/storage ${CRYPTO_INCLUDE_DIRS})
target_link_libraries(test_sigv4 ${CRYPTO_LIBRARIES})
add_test(NAME test_sigv4 COMMAND test_sigv4)
# pprof parser plugin
add_library(pprof_plugin SHARED
plugins/pprof/pprof_plugin.c
)
set_target_properties(pprof_plugin PROPERTIES
OUTPUT_NAME "pprof"
PREFIX ""
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/plugins"
)
target_include_directories(pprof_plugin PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/plugins/pprof
${ZLIB_INCLUDE_DIRS}
)
target_link_libraries(pprof_plugin
pressured_core
${ZLIB_LIBRARIES}
)
add_executable(test_pprof plugins/pprof/test_pprof.c)
target_include_directories(test_pprof PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/plugins/pprof)
target_link_libraries(test_pprof pressured_core)
set_target_properties(test_pprof PROPERTIES ENABLE_EXPORTS ON)
add_test(NAME test_pprof COMMAND test_pprof)
# Manual tests (not added to ctest - require external services)
add_executable(test_http_e2e src/test_http_e2e.c)
target_link_libraries(test_http_e2e pressured_core)
add_executable(test_lua_http plugins/lua/test_lua_http.c)
target_link_libraries(test_lua_http pressured_core)
set_target_properties(test_lua_http PROPERTIES ENABLE_EXPORTS ON)
add_executable(test_lua_storage plugins/lua/test_lua_storage.c)
target_link_libraries(test_lua_storage pressured_core)
set_target_properties(test_lua_storage PROPERTIES ENABLE_EXPORTS ON)
add_executable(test_lua_multi plugins/lua/test_lua_multi.c)
target_link_libraries(test_lua_multi pressured_core)
set_target_properties(test_lua_multi PROPERTIES ENABLE_EXPORTS ON)
add_executable(test_http_stream_storage src/test_http_stream_storage.c)
target_link_libraries(test_http_stream_storage pressured_core)
set_target_properties(test_http_stream_storage PROPERTIES ENABLE_EXPORTS ON)
add_executable(test_s3_storage plugins/storage/test_s3_storage.c)
target_link_libraries(test_s3_storage pressured_core)
set_target_properties(test_s3_storage PROPERTIES ENABLE_EXPORTS ON)
add_executable(test_large_upload plugins/storage/test_large_upload.c)
target_link_libraries(test_large_upload pressured_core)
set_target_properties(test_large_upload PROPERTIES ENABLE_EXPORTS ON)
add_executable(test_streaming_upload plugins/storage/test_streaming_upload.c)
target_link_libraries(test_streaming_upload pressured_core)
set_target_properties(test_streaming_upload PROPERTIES ENABLE_EXPORTS ON)
add_executable(test_real_aws plugins/storage/test_real_aws.c)
target_link_libraries(test_real_aws pressured_core)
set_target_properties(test_real_aws PROPERTIES ENABLE_EXPORTS ON)
# Install
install(TARGETS pressured DESTINATION bin)
install(TARGETS pressured_plugin_lua DESTINATION lib/pressured/plugins)
install(TARGETS storage_local DESTINATION lib/pressured/plugins)
install(TARGETS storage_s3 DESTINATION lib/pressured/plugins)
install(TARGETS pprof_plugin DESTINATION lib/pressured/plugins)