CMakeLists.txt 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. cmake_minimum_required(VERSION 2.6)
  2. INCLUDE(CheckLibraryExists)
  3. INCLUDE(CheckFunctionExists)
  4. PROJECT(ubox C)
  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. OPTION(BUILD_LUA "build Lua plugin" ON)
  12. OPTION(BUILD_EXAMPLES "build examples" ON)
  13. INCLUDE(FindPkgConfig)
  14. PKG_SEARCH_MODULE(JSONC json-c)
  15. IF(JSONC_FOUND)
  16. ADD_DEFINITIONS(-DJSONC)
  17. INCLUDE_DIRECTORIES(${JSONC_INCLUDE_DIRS})
  18. ENDIF()
  19. 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)
  20. ADD_LIBRARY(ubox SHARED ${SOURCES})
  21. ADD_LIBRARY(ubox-static STATIC ${SOURCES})
  22. SET_TARGET_PROPERTIES(ubox-static PROPERTIES OUTPUT_NAME ubox)
  23. SET(LIBS)
  24. CHECK_FUNCTION_EXISTS(clock_gettime HAVE_GETTIME)
  25. CHECK_FUNCTION_EXISTS(shm_open HAVE_SHM)
  26. IF(NOT HAVE_GETTIME OR NOT HAVE_SHM)
  27. CHECK_LIBRARY_EXISTS(rt clock_gettime "" NEED_GETTIME)
  28. CHECK_LIBRARY_EXISTS(rt shm_open "" NEED_SHM)
  29. IF(NEED_GETTIME OR NEED_SHM)
  30. TARGET_LINK_LIBRARIES(ubox rt)
  31. ENDIF()
  32. ENDIF()
  33. FILE(GLOB headers *.h)
  34. LIST(FILTER headers EXCLUDE REGEX "-priv.h$" )
  35. INSTALL(FILES ${headers}
  36. DESTINATION include/libubox
  37. )
  38. INSTALL(TARGETS ubox ubox-static
  39. ARCHIVE DESTINATION lib
  40. LIBRARY DESTINATION lib
  41. )
  42. ADD_SUBDIRECTORY(lua)
  43. ADD_SUBDIRECTORY(examples)
  44. MACRO(ADD_UNIT_TEST_SAN 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 ubox blobmsg_json json_script ${json})
  49. TARGET_INCLUDE_DIRECTORIES(${name}-san PRIVATE ${PROJECT_SOURCE_DIR})
  50. ENDMACRO(ADD_UNIT_TEST_SAN)
  51. IF(UNIT_TESTING)
  52. ENABLE_TESTING()
  53. ADD_SUBDIRECTORY(tests)
  54. ENDIF()
  55. find_library(json NAMES json-c)
  56. IF(EXISTS ${json})
  57. ADD_LIBRARY(blobmsg_json SHARED blobmsg_json.c)
  58. TARGET_LINK_LIBRARIES(blobmsg_json ubox ${json})
  59. ADD_LIBRARY(blobmsg_json-static STATIC blobmsg_json.c)
  60. SET_TARGET_PROPERTIES(blobmsg_json-static
  61. PROPERTIES OUTPUT_NAME blobmsg_json)
  62. IF(UNIT_TESTING)
  63. ADD_UNIT_TEST_SAN(jshn)
  64. ENDIF(UNIT_TESTING)
  65. ADD_EXECUTABLE(jshn jshn.c)
  66. TARGET_LINK_LIBRARIES(jshn blobmsg_json ${json})
  67. ADD_LIBRARY(json_script SHARED json_script.c)
  68. TARGET_LINK_LIBRARIES(json_script ubox)
  69. INSTALL(TARGETS blobmsg_json blobmsg_json-static jshn json_script
  70. ARCHIVE DESTINATION lib
  71. LIBRARY DESTINATION lib
  72. RUNTIME DESTINATION bin
  73. )
  74. FILE(GLOB scripts sh/*.sh)
  75. INSTALL(FILES ${scripts}
  76. DESTINATION share/libubox
  77. )
  78. ENDIF()
  79. IF(ABIVERSION)
  80. SET_TARGET_PROPERTIES(ubox PROPERTIES VERSION ${ABIVERSION})
  81. SET_TARGET_PROPERTIES(json_script PROPERTIES VERSION ${ABIVERSION})
  82. SET_TARGET_PROPERTIES(blobmsg_json PROPERTIES VERSION ${ABIVERSION})
  83. ENDIF()