1 cmake_minimum_required(VERSION 3.13) 2 3 PROJECT(ubus C) 4 5 ADD_DEFINITIONS(-Wall -Werror) 6 IF(CMAKE_C_COMPILER_VERSION VERSION_GREATER 6) 7 ADD_DEFINITIONS(-Wextra -Werror=implicit-function-declaration) 8 ADD_DEFINITIONS(-Wformat -Werror=format-security -Werror=format-nonliteral) 9 ENDIF() 10 ADD_DEFINITIONS(-Os -std=gnu99 -g3 -Wmissing-declarations -Wno-unused-parameter) 11 12 OPTION(BUILD_LUA "build Lua plugin" ON) 13 OPTION(BUILD_EXAMPLES "build examples" ON) 14 15 SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "") 16 SET(UBUS_UNIX_SOCKET "/var/run/ubus/ubus.sock") 17 SET(UBUS_MAX_MSGLEN 1048576) 18 19 ADD_DEFINITIONS( -DUBUS_UNIX_SOCKET="${UBUS_UNIX_SOCKET}") 20 ADD_DEFINITIONS( -DUBUS_MAX_MSGLEN=${UBUS_MAX_MSGLEN}) 21 22 IF(BUILD_STATIC) 23 FIND_LIBRARY(ubox_library NAMES libubox.a) 24 FIND_LIBRARY(blob_library NAMES libblobmsg_json.a) 25 ELSE(BUILD_STATIC) 26 FIND_LIBRARY(ubox_library NAMES ubox) 27 FIND_LIBRARY(blob_library NAMES blobmsg_json) 28 ENDIF(BUILD_STATIC) 29 30 FIND_PATH(ubox_include_dir libubox/usock.h) 31 INCLUDE_DIRECTORIES(${ubox_include_dir}) 32 33 SET(LIB_SOURCES libubus.c libubus-io.c libubus-obj.c libubus-sub.c libubus-req.c libubus-acl.c) 34 35 IF(BUILD_STATIC) 36 ADD_LIBRARY(ubus STATIC ${LIB_SOURCES}) 37 ELSE(BUILD_STATIC) 38 ADD_LIBRARY(ubus SHARED ${LIB_SOURCES}) 39 ENDIF(BUILD_STATIC) 40 TARGET_LINK_LIBRARIES(ubus ${ubox_library}) 41 42 find_library(json NAMES json-c json) 43 44 MACRO(ADD_UNIT_TEST_SAN name output_name) 45 ADD_EXECUTABLE(${name}-san ${name}.c) 46 TARGET_COMPILE_OPTIONS(${name}-san PRIVATE -g -fno-omit-frame-pointer -fsanitize=undefined,address,leak -fno-sanitize-recover=all) 47 TARGET_LINK_OPTIONS(${name}-san PRIVATE -fsanitize=undefined,address,leak) 48 TARGET_LINK_LIBRARIES(${name}-san ubus ubusd_library ${ubox_library} ${blob_library} ${json}) 49 TARGET_INCLUDE_DIRECTORIES(${name}-san PRIVATE ${PROJECT_SOURCE_DIR}) 50 SET_TARGET_PROPERTIES(${name}-san PROPERTIES OUTPUT_NAME ${output_name}) 51 ENDMACRO(ADD_UNIT_TEST_SAN) 52 53 ADD_LIBRARY(ubusd_library STATIC ubusd.c ubusd_proto.c ubusd_id.c ubusd_obj.c ubusd_event.c ubusd_acl.c ubusd_monitor.c) 54 ADD_EXECUTABLE(ubusd ubusd_main.c) 55 TARGET_LINK_LIBRARIES(ubusd ubusd_library ${ubox_library} ${blob_library} ${json}) 56 57 ADD_EXECUTABLE(cli cli.c) 58 SET_TARGET_PROPERTIES(cli PROPERTIES OUTPUT_NAME ubus) 59 TARGET_LINK_LIBRARIES(cli ubus ${ubox_library} ${blob_library} ${json}) 60 61 ADD_SUBDIRECTORY(lua) 62 ADD_SUBDIRECTORY(examples) 63 64 IF(UNIT_TESTING) 65 ENABLE_TESTING() 66 ADD_SUBDIRECTORY(tests) 67 ADD_UNIT_TEST_SAN(cli ubus-san) 68 ADD_UNIT_TEST_SAN(ubusd_main ubusd-san) 69 ENDIF() 70 71 IF(ABIVERSION) 72 SET_TARGET_PROPERTIES(ubus PROPERTIES VERSION ${ABIVERSION}) 73 ENDIF() 74 75 INSTALL(TARGETS ubus cli 76 ARCHIVE DESTINATION lib 77 LIBRARY DESTINATION lib 78 RUNTIME DESTINATION bin 79 ) 80 INSTALL(TARGETS ubusd 81 RUNTIME DESTINATION sbin 82 ) 83 84 INSTALL(FILES ubusmsg.h ubus_common.h libubus.h DESTINATION include)
This page was automatically generated by LXR 0.3.1. • OpenWrt