CMakeLists.txt 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. CMAKE_MINIMUM_REQUIRED(VERSION 3.4.0)
  2. INCLUDE(GNUInstallDirs)
  3. PROJECT(hiredis)
  4. OPTION(ENABLE_SSL "Build hiredis_ssl for SSL support" OFF)
  5. MACRO(getVersionBit name)
  6. SET(VERSION_REGEX "^#define ${name} (.+)$")
  7. FILE(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/hiredis.h"
  8. VERSION_BIT REGEX ${VERSION_REGEX})
  9. STRING(REGEX REPLACE ${VERSION_REGEX} "\\1" ${name} "${VERSION_BIT}")
  10. ENDMACRO(getVersionBit)
  11. getVersionBit(HIREDIS_MAJOR)
  12. getVersionBit(HIREDIS_MINOR)
  13. getVersionBit(HIREDIS_PATCH)
  14. getVersionBit(HIREDIS_SONAME)
  15. SET(VERSION "${HIREDIS_MAJOR}.${HIREDIS_MINOR}.${HIREDIS_PATCH}")
  16. MESSAGE("Detected version: ${VERSION}")
  17. PROJECT(hiredis VERSION "${VERSION}")
  18. SET(ENABLE_EXAMPLES OFF CACHE BOOL "Enable building hiredis examples")
  19. ADD_LIBRARY(hiredis SHARED
  20. async.c
  21. dict.c
  22. hiredis.c
  23. net.c
  24. read.c
  25. sds.c
  26. sockcompat.c)
  27. SET_TARGET_PROPERTIES(hiredis
  28. PROPERTIES
  29. VERSION "${HIREDIS_SONAME}")
  30. IF(WIN32 OR MINGW)
  31. TARGET_LINK_LIBRARIES(hiredis PRIVATE ws2_32)
  32. ENDIF()
  33. TARGET_INCLUDE_DIRECTORIES(hiredis PUBLIC .)
  34. CONFIGURE_FILE(hiredis.pc.in hiredis.pc @ONLY)
  35. INSTALL(TARGETS hiredis
  36. DESTINATION "${CMAKE_INSTALL_LIBDIR}")
  37. INSTALL(FILES hiredis.h read.h sds.h async.h
  38. DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/hiredis)
  39. INSTALL(DIRECTORY adapters
  40. DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/hiredis)
  41. INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/hiredis.pc
  42. DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
  43. IF(ENABLE_SSL)
  44. IF (NOT OPENSSL_ROOT_DIR)
  45. IF (APPLE)
  46. SET(OPENSSL_ROOT_DIR "/usr/local/opt/openssl")
  47. ENDIF()
  48. ENDIF()
  49. FIND_PACKAGE(OpenSSL REQUIRED)
  50. ADD_LIBRARY(hiredis_ssl SHARED
  51. ssl.c)
  52. TARGET_INCLUDE_DIRECTORIES(hiredis_ssl PRIVATE "${OPENSSL_INCLUDE_DIR}")
  53. TARGET_LINK_LIBRARIES(hiredis_ssl PRIVATE ${OPENSSL_LIBRARIES})
  54. CONFIGURE_FILE(hiredis_ssl.pc.in hiredis_ssl.pc @ONLY)
  55. INSTALL(TARGETS hiredis_ssl
  56. DESTINATION "${CMAKE_INSTALL_LIBDIR}")
  57. INSTALL(FILES hiredis_ssl.h
  58. DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/hiredis)
  59. INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/hiredis_ssl.pc
  60. DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
  61. ENDIF()
  62. IF(NOT (WIN32 OR MINGW))
  63. ENABLE_TESTING()
  64. ADD_EXECUTABLE(hiredis-test test.c)
  65. TARGET_LINK_LIBRARIES(hiredis-test hiredis)
  66. ADD_TEST(NAME hiredis-test
  67. COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/test.sh)
  68. ENDIF()
  69. # Add examples
  70. IF(ENABLE_EXAMPLES)
  71. ADD_SUBDIRECTORY(examples)
  72. ENDIF(ENABLE_EXAMPLES)