CMakeLists.txt 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. cmake_minimum_required(VERSION 2.6)
  2. INCLUDE(GNUInstallDirs)
  3. PROJECT(uci C)
  4. SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
  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. ADD_DEFINITIONS(-DUCI_PREFIX="${CMAKE_INSTALL_PREFIX}")
  12. OPTION(UCI_DEBUG "debugging support" OFF)
  13. OPTION(UCI_DEBUG_TYPECAST "typecast debugging support" OFF)
  14. OPTION(BUILD_LUA "build Lua binding" ON)
  15. OPTION(BUILD_STATIC "statically linking uci" OFF)
  16. FIND_PATH(ubox_include_dir libubox/usock.h)
  17. CONFIGURE_FILE( ${CMAKE_SOURCE_DIR}/uci_config.h.in ${CMAKE_SOURCE_DIR}/uci_config.h )
  18. INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR} ${ubox_include_dir})
  19. SET(LIB_SOURCES libuci.c file.c util.c delta.c parse.c blob.c)
  20. FIND_LIBRARY(ubox NAMES ubox)
  21. IF(BUILD_STATIC)
  22. FIND_LIBRARY(ubox-static NAMES libubox.a)
  23. ENDIF(BUILD_STATIC)
  24. ADD_LIBRARY(uci SHARED ${LIB_SOURCES})
  25. SET_TARGET_PROPERTIES(uci PROPERTIES OUTPUT_NAME uci)
  26. TARGET_LINK_LIBRARIES(uci ${ubox})
  27. ADD_LIBRARY(uci-static STATIC ${LIB_SOURCES})
  28. SET_TARGET_PROPERTIES(uci-static PROPERTIES OUTPUT_NAME uci)
  29. TARGET_LINK_LIBRARIES(uci-static ${ubox-static})
  30. ADD_EXECUTABLE(cli cli.c)
  31. SET_TARGET_PROPERTIES(cli PROPERTIES OUTPUT_NAME uci)
  32. IF(BUILD_STATIC)
  33. TARGET_LINK_LIBRARIES(cli uci-static ${ubox-static})
  34. ELSE(BUILD_STATIC)
  35. TARGET_LINK_LIBRARIES(cli uci ${ubox})
  36. ENDIF(BUILD_STATIC)
  37. ADD_LIBRARY(ucimap STATIC ucimap.c)
  38. IF(BUILD_LUA)
  39. ADD_SUBDIRECTORY(lua)
  40. ENDIF()
  41. IF(UNIT_TESTING)
  42. ENABLE_TESTING()
  43. ADD_SUBDIRECTORY(tests)
  44. IF(CMAKE_C_COMPILER_ID STREQUAL "Clang")
  45. ADD_LIBRARY(uci-san SHARED ${LIB_SOURCES})
  46. SET_TARGET_PROPERTIES(uci-san PROPERTIES OUTPUT_NAME uci-san)
  47. TARGET_COMPILE_OPTIONS(uci-san PRIVATE -g -fno-omit-frame-pointer -fsanitize=undefined,address,leak -fno-sanitize-recover=all)
  48. TARGET_LINK_OPTIONS(uci-san PRIVATE -fsanitize=undefined,address,leak)
  49. TARGET_LINK_LIBRARIES(uci-san ${ubox})
  50. ADD_EXECUTABLE(cli-san cli.c)
  51. SET_TARGET_PROPERTIES(cli-san PROPERTIES OUTPUT_NAME uci-san)
  52. TARGET_COMPILE_OPTIONS(cli-san PRIVATE -g -fno-omit-frame-pointer -fsanitize=undefined,address,leak -fno-sanitize-recover=all)
  53. TARGET_LINK_OPTIONS(cli-san PRIVATE -fsanitize=undefined,address,leak)
  54. TARGET_LINK_LIBRARIES(cli-san uci-san ${ubox})
  55. ENDIF()
  56. ENDIF()
  57. INSTALL(FILES uci.h uci_config.h uci_blob.h ucimap.h
  58. DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
  59. )
  60. INSTALL(TARGETS uci cli
  61. ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
  62. LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
  63. RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
  64. )