• source navigation  • diff markup  • identifier search  • freetext search  • 

Sources/libubox/CMakeLists.txt

  1 cmake_minimum_required(VERSION 3.13)
  2 INCLUDE(CheckLibraryExists)
  3 INCLUDE(CheckFunctionExists)
  4 
  5 PROJECT(ubox C)
  6 
  7 ADD_DEFINITIONS(-Wall -Werror)
  8 IF(CMAKE_C_COMPILER_VERSION VERSION_GREATER 6)
  9         ADD_DEFINITIONS(-Wextra -Werror=implicit-function-declaration)
 10         ADD_DEFINITIONS(-Wformat -Werror=format-security -Werror=format-nonliteral)
 11 ENDIF()
 12 ADD_DEFINITIONS(-Os -std=gnu99 -g3 -Wmissing-declarations -Wno-unused-parameter)
 13 
 14 OPTION(BUILD_LUA "build Lua plugin" ON)
 15 OPTION(BUILD_EXAMPLES "build examples" ON)
 16 
 17 INCLUDE(FindPkgConfig)
 18 PKG_SEARCH_MODULE(JSONC json-c)
 19 IF(JSONC_FOUND)
 20   ADD_DEFINITIONS(-DJSONC)
 21   INCLUDE_DIRECTORIES(${JSONC_INCLUDE_DIRS})
 22 ENDIF()
 23 
 24 SET(SOURCES avl.c avl-cmp.c blob.c blobmsg.c uloop.c usock.c ustream.c ustream-fd.c vlist.c utils.c safe_list.c runqueue.c md5.c kvlist.c ulog.c base64.c udebug.c udebug-remote.c)
 25 
 26 ADD_LIBRARY(ubox SHARED ${SOURCES})
 27 ADD_LIBRARY(ubox-static STATIC ${SOURCES})
 28 SET_TARGET_PROPERTIES(ubox-static PROPERTIES OUTPUT_NAME ubox)
 29 
 30 SET(LIBS)
 31 CHECK_FUNCTION_EXISTS(clock_gettime HAVE_GETTIME)
 32 CHECK_FUNCTION_EXISTS(shm_open HAVE_SHM)
 33 IF(NOT HAVE_GETTIME OR NOT HAVE_SHM)
 34         CHECK_LIBRARY_EXISTS(rt clock_gettime "" NEED_GETTIME)
 35         CHECK_LIBRARY_EXISTS(rt shm_open "" NEED_SHM)
 36         IF(NEED_GETTIME OR NEED_SHM)
 37                 TARGET_LINK_LIBRARIES(ubox rt)
 38         ENDIF()
 39 ENDIF()
 40 
 41 FILE(GLOB headers *.h)
 42 LIST(FILTER headers EXCLUDE REGEX "-priv.h$" )
 43 INSTALL(FILES ${headers}
 44         DESTINATION include/libubox
 45 )
 46 INSTALL(TARGETS ubox ubox-static
 47         ARCHIVE DESTINATION lib
 48         LIBRARY DESTINATION lib
 49 )
 50 
 51 ADD_SUBDIRECTORY(lua)
 52 ADD_SUBDIRECTORY(examples)
 53 
 54 MACRO(ADD_UNIT_TEST_SAN name)
 55   ADD_EXECUTABLE(${name}-san ${name}.c)
 56   TARGET_COMPILE_OPTIONS(${name}-san PRIVATE -g -fno-omit-frame-pointer -fsanitize=undefined,address,leak -fno-sanitize-recover=all)
 57   TARGET_LINK_OPTIONS(${name}-san PRIVATE -fsanitize=undefined,address,leak)
 58   TARGET_LINK_LIBRARIES(${name}-san ubox blobmsg_json json_script ${json})
 59   TARGET_INCLUDE_DIRECTORIES(${name}-san PRIVATE ${PROJECT_SOURCE_DIR})
 60 ENDMACRO(ADD_UNIT_TEST_SAN)
 61 
 62 IF(UNIT_TESTING)
 63   ENABLE_TESTING()
 64   ADD_SUBDIRECTORY(tests)
 65 ENDIF()
 66 
 67 find_library(json NAMES json-c)
 68 IF(EXISTS ${json})
 69         ADD_LIBRARY(blobmsg_json SHARED blobmsg_json.c)
 70         TARGET_LINK_LIBRARIES(blobmsg_json ubox ${json})
 71 
 72         ADD_LIBRARY(blobmsg_json-static STATIC blobmsg_json.c)
 73         SET_TARGET_PROPERTIES(blobmsg_json-static
 74                               PROPERTIES OUTPUT_NAME blobmsg_json)
 75 
 76         IF(UNIT_TESTING)
 77                 ADD_UNIT_TEST_SAN(jshn)
 78         ENDIF(UNIT_TESTING)
 79 
 80         ADD_EXECUTABLE(jshn jshn.c)
 81         TARGET_LINK_LIBRARIES(jshn blobmsg_json ${json})
 82 
 83         ADD_LIBRARY(json_script SHARED json_script.c)
 84         TARGET_LINK_LIBRARIES(json_script ubox)
 85 
 86         INSTALL(TARGETS blobmsg_json blobmsg_json-static jshn json_script
 87                 ARCHIVE DESTINATION lib
 88                 LIBRARY DESTINATION lib
 89                 RUNTIME DESTINATION bin
 90         )
 91 
 92         FILE(GLOB scripts sh/*.sh)
 93         INSTALL(FILES ${scripts}
 94                 DESTINATION share/libubox
 95         )
 96 
 97 ENDIF()
 98 
 99 IF(ABIVERSION)
100         SET_TARGET_PROPERTIES(ubox PROPERTIES VERSION ${ABIVERSION})
101         SET_TARGET_PROPERTIES(json_script PROPERTIES VERSION ${ABIVERSION})
102         SET_TARGET_PROPERTIES(blobmsg_json PROPERTIES VERSION ${ABIVERSION})
103 ENDIF()

This page was automatically generated by LXR 0.3.1.  •  OpenWrt