CMakeLists.txt 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. cmake_minimum_required(VERSION 2.6)
  2. INCLUDE(CheckIncludeFiles)
  3. PROJECT(uclient C)
  4. ADD_DEFINITIONS(-Os -Wall -Werror --std=gnu99 -g3)
  5. IF(CMAKE_C_COMPILER_VERSION VERSION_GREATER 6)
  6. ADD_DEFINITIONS(-Wextra -Werror=implicit-function-declaration)
  7. ADD_DEFINITIONS(-Wformat -Werror=format-security -Werror=format-nonliteral)
  8. ENDIF()
  9. ADD_DEFINITIONS(-Wno-unused-parameter -Wmissing-declarations)
  10. SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
  11. FIND_PATH(ubox_include_dir libubox/ustream-ssl.h)
  12. INCLUDE_DIRECTORIES(${ubox_include_dir})
  13. IF(BUILD_STATIC)
  14. FIND_LIBRARY(ubox_library NAMES ubox.a)
  15. ELSE(BUILD_STATIC)
  16. FIND_LIBRARY(ubox_library NAMES ubox)
  17. ENDIF(BUILD_STATIC)
  18. SET(LIB_SOURCES uclient.c uclient-http.c uclient-utils.c)
  19. ADD_LIBRARY(uclient SHARED ${LIB_SOURCES})
  20. TARGET_LINK_LIBRARIES(uclient ${ubox_library} dl)
  21. SET(CLI_SOURCES uclient-fetch.c progress.c)
  22. ADD_EXECUTABLE(uclient-fetch ${CLI_SOURCES})
  23. TARGET_LINK_LIBRARIES(uclient-fetch uclient)
  24. IF(UNIT_TESTING)
  25. ADD_DEFINITIONS(-DUNIT_TESTING)
  26. ENABLE_TESTING()
  27. ADD_SUBDIRECTORY(tests)
  28. IF(CMAKE_C_COMPILER_ID STREQUAL "Clang")
  29. ADD_LIBRARY(uclient-san SHARED ${LIB_SOURCES})
  30. TARGET_COMPILE_OPTIONS(uclient-san PRIVATE -g -fno-omit-frame-pointer -fsanitize=undefined,address,leak -fno-sanitize-recover=all)
  31. TARGET_LINK_OPTIONS(uclient-san PRIVATE -fsanitize=undefined,address,leak)
  32. TARGET_LINK_LIBRARIES(uclient-san ${ubox_library} dl)
  33. ADD_EXECUTABLE(uclient-fetch-san ${CLI_SOURCES})
  34. TARGET_COMPILE_OPTIONS(uclient-fetch-san PRIVATE -g -fno-omit-frame-pointer -fsanitize=undefined,address,leak -fno-sanitize-recover=all)
  35. TARGET_LINK_OPTIONS(uclient-fetch-san PRIVATE -fsanitize=undefined,address,leak)
  36. TARGET_LINK_LIBRARIES(uclient-fetch-san uclient-san ${ubox_library} dl)
  37. ENDIF()
  38. ENDIF()
  39. INSTALL(FILES uclient.h uclient-utils.h
  40. DESTINATION include/libubox
  41. )
  42. INSTALL(TARGETS uclient uclient-fetch
  43. LIBRARY DESTINATION lib
  44. RUNTIME DESTINATION bin
  45. )