libubus: mark ubus socket with close-on-exec
[project/ubus.git] / CMakeLists.txt
1 cmake_minimum_required(VERSION 2.6)
2
3 PROJECT(ubus C)
4 ADD_DEFINITIONS(-Os -Wall -Werror --std=gnu99 -g3 -Wmissing-declarations)
5
6 OPTION(BUILD_LUA "build Lua plugin" ON)
7 OPTION(BUILD_EXAMPLES "build examples" ON)
8 OPTION(ENABLE_SYSTEMD "systemd support" ON)
9
10 SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
11 SET(UBUS_UNIX_SOCKET "/var/run/ubus.sock")
12 SET(UBUS_MAX_MSGLEN 1048576)
13
14 ADD_DEFINITIONS( -DUBUS_UNIX_SOCKET="${UBUS_UNIX_SOCKET}")
15 ADD_DEFINITIONS( -DUBUS_MAX_MSGLEN=${UBUS_MAX_MSGLEN})
16
17 IF(APPLE)
18   INCLUDE_DIRECTORIES(/opt/local/include)
19   LINK_DIRECTORIES(/opt/local/lib)
20 ENDIF()
21
22 ADD_LIBRARY(ubus SHARED libubus.c libubus-io.c libubus-obj.c libubus-sub.c libubus-req.c)
23 TARGET_LINK_LIBRARIES(ubus ubox)
24
25 ADD_EXECUTABLE(ubusd ubusd.c ubusd_id.c ubusd_obj.c ubusd_proto.c ubusd_event.c)
26 TARGET_LINK_LIBRARIES(ubusd ubox)
27
28 find_library(json NAMES json-c json)
29 ADD_EXECUTABLE(cli cli.c)
30 SET_TARGET_PROPERTIES(cli PROPERTIES OUTPUT_NAME ubus)
31 TARGET_LINK_LIBRARIES(cli ubus ubox blobmsg_json ${json})
32
33 ADD_SUBDIRECTORY(lua)
34 ADD_SUBDIRECTORY(examples)
35
36 INSTALL(TARGETS ubus cli
37         LIBRARY DESTINATION lib
38         RUNTIME DESTINATION bin
39 )
40 INSTALL(TARGETS ubusd
41         RUNTIME DESTINATION sbin
42 )
43
44 INSTALL(FILES ubusmsg.h ubus_common.h libubus.h DESTINATION include)
45
46 # FIXME: this works but certainly can be done better:
47 SET(UBUSD_BINARY "${CMAKE_INSTALL_PREFIX}/sbin/ubusd")
48
49 # do this after the installs so we have the proper paths
50 IF(ENABLE_SYSTEMD)
51   INCLUDE(FindPkgConfig)
52   PKG_CHECK_MODULES(SYSTEMD systemd)
53   IF(SYSTEMD_FOUND)
54     ADD_SUBDIRECTORY(systemd)
55   ENDIF()
56 ENDIF()