This repository has been archived by the owner on Jul 18, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
CMakeLists.txt
444 lines (373 loc) · 12.4 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
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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
cmake_minimum_required(VERSION 2.8)
include(GNUInstallDirs)
include(CPack)
project(librpc)
if(UNIX AND NOT APPLE)
set(LINUX TRUE)
endif()
set(PYTHON_VERSION python3 CACHE STRING "Target Python version for py-librpc")
option(RPC_DEBUG "Enable debug output")
option(BUNDLED_BLOCKS_RUNTIME "Use bundled BlocksRuntime")
option(BUILD_DOC "Create and install HTML API documentation")
option(BUILD_TESTS "Build and install tests")
option(BUILD_EXAMPLES "Build and install example programs" ON)
option(BUILD_PYTHON "Build and install Python extension" ON)
option(BUILD_CPLUSPLUS "Build and install C++ library")
option(BUILD_JSON "Build and install JSON serializer" ON)
option(BUILD_WS "Build and install WebSockets transport" ON)
option(BUILD_LIBUSB "Build and install libusb transport")
option(BUILD_XPC "Build and install XPC transport")
option(BUILD_RPCTOOL "Build and install rpctool" ON)
option(BUILD_RPCGUI "Build and install rpcgui" ON)
option(BUILD_RPCD "Build and install rpcd" ON)
option(BUILD_RPCDOC "Build and install rpcdoc" ON)
option(BUILD_RPCLINT "Build and install rpclint" ON)
option(ENABLE_UBSAN "Enable undefined behavior sanitizer")
option(ENABLE_UBSAN_NULLABILITY "Enable nullability sanitizer")
option(ENABLE_ASAN "Enable address sanitizer")
option(ENABLE_LIBDISPATCH "Enable libdispatch support")
option(ENABLE_COVERAGE "Enable code coverage")
option(ENABLE_RPATH "Enable @rpath on macOS" ON)
if(LINUX)
option(ENABLE_SYSTEMD "Enable systemd support" ON)
option(BUILD_BUS "Build and install bus transport" ON)
option(BUILD_KMOD "Build and install kmod")
endif()
if(APPLE)
option(ENABLE_LAUNCHD "Enable launchd support" ON)
endif()
set(PKGCONFIG_C_FLAGS "-fblocks")
set(CPACK_PACKAGE_NAME librpc)
set(CPACK_PACKAGE_VENDOR Two Pore Guys)
set(CPACK_PACKAGE_VERSION_MAJOR 0)
set(CPACK_PACKAGE_VERSION_MINOR 3)
set(CPACK_DEBIAN_PACKAGE_MAINTAINER Jakub Klama <jakub.klama@twoporeguys.com>)
set(CPACK_GENERATOR DEB)
execute_process(
COMMAND git describe --exact-match HEAD
RESULT_VARIABLE RELEASE_TAG
OUTPUT_QUIET
ERROR_QUIET
)
if(NOT RELEASE_TAG)
execute_process(
COMMAND git rev-list --count HEAD
OUTPUT_VARIABLE CPACK_PACKAGE_VERSION_PATCH
OUTPUT_STRIP_TRAILING_WHITESPACE)
endif()
find_package(PkgConfig REQUIRED)
pkg_check_modules(GLIB REQUIRED glib-2.0>=2.40)
pkg_check_modules(YAML REQUIRED yaml-0.1)
if(BUILD_JSON)
pkg_check_modules(YAJL REQUIRED yajl>=2.0.0)
endif()
if(UNIX)
pkg_check_modules(GIO REQUIRED gio-unix-2.0)
endif()
if(BUILD_LIBUSB)
pkg_check_modules(LIBUSB REQUIRED libusb-1.0)
endif()
if(BUILD_WS)
pkg_check_modules(SOUP REQUIRED libsoup-2.4)
endif()
if(BUILD_BUS AND LINUX)
pkg_check_modules(UDEV REQUIRED libudev)
endif()
if(ENABLE_SYSTEMD)
pkg_check_modules(SYSTEMD REQUIRED libsystemd)
endif()
if(BUNDLED_BLOCKS_RUNTIME)
include_directories(contrib/BlocksRuntime)
endif()
if(ENABLE_UBSAN)
set(PKGCONFIG_C_FLAGS "${PKGCONFIG_C_FLAGS} -fsanitize=undefined -fsanitize=integer")
endif()
if(ENABLE_UBSAN_NULLABILITY)
set(PKGCONFIG_C_FLAGS "${PKGCONFIG_C_FLAGS} -fsanitize=nullability")
endif()
if(ENABLE_ASAN)
set(PKGCONFIG_C_FLAGS "${PKGCONFIG_C_FLAGS} -fsanitize=address")
endif()
if(ENABLE_COVERAGE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --coverage")
endif()
function(python_install SETUP_PY)
if(EXISTS "$ENV{DESTDIR}/${CMAKE_INSTALL_PREFIX}/lib/${PYTHON_VERSION}/dist-packages")
install(CODE "
execute_process(
COMMAND ${PYTHON} ${SETUP_PY} install
--record python_manifest.txt
--root=/\$ENV{DESTDIR}
--install-lib=${CMAKE_INSTALL_PREFIX}/lib/${PYTHON_VERSION}/dist-packages
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)")
elseif(DEFINED "$ENV{CUSTOM_PREFIX}")
install(CODE "
execute_process(
COMMAND ${PYTHON} ${SETUP_PY} install
--record python_manifest.txt
--root=/\$ENV{DESTDIR}
--prefix=${CMAKE_INSTALL_PREFIX}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)")
else()
install(CODE "
execute_process(
COMMAND ${PYTHON} ${SETUP_PY} install
--record python_manifest.txt
--root=/\$ENV{DESTDIR}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)")
endif()
endfunction()
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fblocks -Wall -Wextra -Wno-unused-parameter -DRPC_PREFIX=${CMAKE_INSTALL_PREFIX} -DRPC_TRACE ${PKGCONFIG_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -fblocks -Wall -Wextra -Wno-unused-parameter -DRPC_PREFIX=${CMAKE_INSTALL_PREFIX} -DRPC_TRACE ${PKGCONFIG_C_FLAGS}")
set(CMAKE_C_FLAGS_DEBUG "-g -O0")
set(CMAKE_CXX_FLAGS_DEBUG "-g -O0")
include_directories(include)
include_directories(contrib/libyuarel)
include_directories(/usr/local/include)
include_directories(${CMAKE_BINARY_DIR}/include)
include_directories (${GLIB_INCLUDE_DIRS})
link_directories(${GLIB_LIBRARY_DIRS})
include_directories(${GIO_INCLUDE_DIRS})
link_directories(${GIO_LIBRARY_DIRS})
include_directories(${YAML_INCLUDE_DIRS})
link_directories(${YAML_LIBRARY_DIRS})
if(RPC_DEBUG)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DRPC_DEBUG")
endif()
if(ENABLE_LIBDISPATCH)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DLIBDISPATCH_SUPPORT")
endif()
if(BUILD_JSON)
include_directories(${YAJL_INCLUDE_DIRS})
link_directories(${YAJL_LIBRARY_DIRS})
endif()
if(BUILD_WS)
include_directories(${SOUP_INCLUDE_DIRS})
link_directories(${SOUP_LIBRARY_DIRS})
endif()
if(BUILD_LIBUSB)
include_directories(${LIBUSB_INCLUDE_DIRS})
link_directories(${LIBUSB_LIBRARY_DIRS})
endif()
if(ENABLE_SYSTEMD)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DSYSTEMD_SUPPORT")
include_directories(${SYSTEMD_INCLUDE_DIRS})
link_directories(${SYSTEMD_LIBRARY_DIRS})
endif()
if(ENABLE_LAUNCHD)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DLAUNCHD_SUPPORT")
endif()
set(HEADERS
include/rpc/object.h
include/rpc/connection.h
include/rpc/server.h
include/rpc/client.h
include/rpc/service.h
include/rpc/query.h
include/rpc/bus.h
include/rpc/serializer.h
include/rpc/typing.h)
set(CORE_FILES
src/rpc_connection.c
src/rpc_object.c
src/rpc_server.c
src/rpc_service.c
src/rpc_client.c
src/rpc_query.c
src/rpc_bus.c
src/rpc_serializer.c
src/rpc_typing.c
src/rpc_rpcd_client.c
src/utils.c
src/internal.h
src/linker_set.h
src/memfd.h
contrib/libyuarel/yuarel.c
contrib/libyuarel/yuarel.h)
set(TRANSPORT_FILES
src/transport/socket.c
src/transport/loopback.c
src/transport/fd.c)
set(SERIALIZER_FILES
src/serializer/msgpack.c
src/serializer/msgpack.h
src/serializer/yaml.c
src/serializer/yaml.h
contrib/mpack/mpack.c)
set(TYPE_CLASS_FILES
src/class/struct.c
src/class/union.c
src/class/typedef.c
src/class/container.c
src/class/enum.c
src/class/builtin.c)
set(VALIDATOR_FILES
src/validator/string_length.c
src/validator/string_regex.c
src/validator/int64_range.c)
if(LINUX)
set(CORE_FILES ${CORE_FILES} src/notify_eventfd.c)
endif()
if(APPLE)
set(CORE_FILES ${CORE_FILES} src/notify_kqueue.c)
endif()
if(BUILD_JSON)
set(SERIALIZER_FILES
${SERIALIZER_FILES}
src/serializer/json.c
src/serializer/json.h)
endif()
if(BUNDLED_BLOCKS_RUNTIME)
set(CORE_FILES ${CORE_FILES}
contrib/BlocksRuntime/data.c
contrib/BlocksRuntime/runtime.c)
endif()
if(BUILD_LIBUSB)
set(TRANSPORT_FILES ${TRANSPORT_FILES} src/transport/libusb.c)
endif()
if(BUILD_LIBUSB)
set(TRANSPORT_FILES ${TRANSPORT_FILES} src/transport/ws.c)
endif()
if(BUILD_BUS AND LINUX)
set(TRANSPORT_FILES ${TRANSPORT_FILES} src/transport/bus.c)
endif()
if(BUILD_XPC)
set(TRANSPORT_FILES ${TRANSPORT_FILES} src/transport/xpc.c)
endif()
add_library(librpc SHARED
${HEADERS}
${TRANSPORT_FILES}
${SERIALIZER_FILES}
${TYPE_CLASS_FILES}
${VALIDATOR_FILES}
${CORE_FILES})
set_target_properties(librpc PROPERTIES PREFIX "")
set_target_properties(librpc PROPERTIES SOVERSION 1)
target_link_libraries(librpc ${GLIB_LIBRARIES})
target_link_libraries(librpc ${GIO_LIBRARIES})
target_link_libraries(librpc ${YAJL_LIBRARIES})
target_link_libraries(librpc ${YAML_LIBRARIES})
if(ENABLE_RPATH)
set_target_properties(librpc PROPERTIES MACOSX_RPATH ON)
endif()
if(BUILD_WS)
target_link_libraries(librpc ${SOUP_LIBRARIES})
endif()
if(BUILD_LIBUSB)
target_link_libraries(librpc ${LIBUSB_LIBRARIES})
endif()
if(BUILD_BUS AND LINUX)
target_link_libraries(librpc ${UDEV_LIBRARIES})
endif()
if(NOT APPLE)
target_link_libraries(librpc BlocksRuntime)
endif()
if(ENABLE_LIBDISPATCH AND NOT APPLE)
target_link_libraries(librpc dispatch)
endif()
if(ENABLE_SYSTEMD)
target_link_libraries(librpc ${SYSTEMD_LIBRARIES})
endif()
configure_file(librpc.pc.in ${CMAKE_CURRENT_BINARY_DIR}/librpc.pc @ONLY)
configure_file(config.h.in ${CMAKE_CURRENT_BINARY_DIR}/include/rpc/config.h)
install(TARGETS librpc DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_PREFIX}/include)
install(DIRECTORY ${CMAKE_BINARY_DIR}/include/ DESTINATION ${CMAKE_INSTALL_PREFIX}/include)
install(DIRECTORY idl/ DESTINATION ${CMAKE_INSTALL_PREFIX}/share/idl)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/librpc.pc DESTINATION ${CMAKE_INSTALL_PREFIX}/share/pkgconfig)
if(BUILD_TESTS)
set(TEST_SOURCES
src/linker_set.h
tests/tests.h
tests/main.c
tests/api/bus.c
tests/api/client.c
tests/api/connection.c
tests/api/object.c
tests/api/query.c
tests/api/serializer.c
tests/api/server.c
tests/api/service.c
tests/api/typing.c
tests/internal.c
tests/transport.c)
add_executable(test_suite ${TEST_SOURCES})
target_link_libraries(test_suite ${GLIB_LIBRARIES})
target_link_libraries(test_suite librpc)
endif()
if(BUILD_EXAMPLES)
add_subdirectory(examples/client)
add_subdirectory(examples/event)
add_subdirectory(examples/loopback)
add_subdirectory(examples/pack-unpack)
add_subdirectory(examples/server)
add_subdirectory(examples/error-backtrace)
add_subdirectory(examples/query)
add_subdirectory(examples/validation)
if(UNIX)
add_subdirectory(examples/fd-client)
add_subdirectory(examples/fd-server)
add_subdirectory(examples/fd-transport)
endif()
if(LINUX)
add_subdirectory(examples/shm-client)
add_subdirectory(examples/shm-server)
endif()
if (BUILD_BUS OR BUILD_LIBUSB)
add_subdirectory(examples/bus)
add_subdirectory(examples/log-reader)
endif()
if (ENABLE_LIBDISPATCH)
add_subdirectory(examples/libdispatch)
endif()
endif()
if(BUILD_RPCTOOL)
add_subdirectory(tools/rpctool)
endif()
if(BUILD_PYTHON AND BUILD_RPCGUI)
add_subdirectory(tools/rpcgui)
endif()
if(BUILD_RPCD AND LINUX)
add_subdirectory(tools/rpcd)
endif()
if(BUILD_PYTHON AND BUILD_RPCDOC)
add_subdirectory(tools/rpcdoc)
endif()
if(BUILD_PYTHON AND BUILD_RPCLINT)
add_subdirectory(tools/rpclint)
endif()
if(BUILD_PYTHON)
add_subdirectory(bindings/python)
endif()
if(BUILD_CPLUSPLUS)
add_subdirectory(bindings/c++)
endif()
if(BUILD_DOC)
find_package(Doxygen)
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/doxygen)
configure_file(${CMAKE_SOURCE_DIR}/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY)
add_custom_target(doc ALL
${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
COMMAND
env BUILD_DIR=${CMAKE_CURRENT_BINARY_DIR} sphinx-build
${CMAKE_SOURCE_DIR}/docs/source ${CMAKE_CURRENT_BINARY_DIR}/docs
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/doxygen)
endif()
if(BUILD_BUS AND BUILD_KMOD)
add_subdirectory(kmod)
endif()
# uninstall target
if(NOT TARGET uninstall)
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY)
add_custom_target(uninstall
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
endif()