6 # Set timestamps on extracted files to time of extraction.
7 cmake_policy(SET CMP0135 NEW)
10 set(hiredis_FOUND FALSE)
12 if(HIREDIS_FROM_INTERNET AND NOT HIREDIS_FROM_INTERNET STREQUAL "AUTO")
13 message(STATUS "Using hiredis from the Internet")
16 find_package(PkgConfig)
18 pkg_check_modules(HIREDIS hiredis>=${hiredis_FIND_VERSION})
19 find_library(HIREDIS_LIBRARY ${HIREDIS_LIBRARIES} HINTS ${HIREDIS_LIBDIR})
20 find_path(HIREDIS_INCLUDE_DIR hiredis/hiredis.h HINTS ${HIREDIS_PREFIX}/include)
21 if(HIREDIS_LIBRARY AND HIREDIS_INCLUDE_DIR)
22 message(STATUS "Using hiredis from ${HIREDIS_LIBRARY} via pkg-config")
23 set(hiredis_FOUND TRUE)
28 find_library(HIREDIS_LIBRARY hiredis)
29 find_path(HIREDIS_INCLUDE_DIR hiredis/hiredis.h)
30 if(HIREDIS_LIBRARY AND HIREDIS_INCLUDE_DIR)
31 message(STATUS "Using hiredis from ${HIREDIS_LIBRARY}")
32 set(hiredis_FOUND TRUE)
37 mark_as_advanced(HIREDIS_INCLUDE_DIR HIREDIS_LIBRARY)
38 add_library(HIREDIS::HIREDIS UNKNOWN IMPORTED)
39 set_target_properties(
42 IMPORTED_LOCATION "${HIREDIS_LIBRARY}"
43 INTERFACE_COMPILE_OPTIONS "${HIREDIS_CFLAGS_OTHER}"
44 INTERFACE_INCLUDE_DIRECTORIES "${HIREDIS_INCLUDE_DIR}"
46 if(WIN32 AND STATIC_LINK)
47 target_link_libraries(HIREDIS::HIREDIS INTERFACE ws2_32)
49 set(hiredis_FOUND TRUE)
50 set(target HIREDIS::HIREDIS)
51 elseif(HIREDIS_FROM_INTERNET STREQUAL "AUTO")
52 message(STATUS "*** WARNING ***: Using hiredis from the Internet because it was not found and HIREDIS_FROM_INTERNET is AUTO")
58 set(hiredis_version "1.1.0")
59 set(hiredis_dir ${CMAKE_BINARY_DIR}/hiredis-${hiredis_version})
60 set(hiredis_build ${CMAKE_BINARY_DIR}/hiredis-build)
65 URL https://github.com/redis/hiredis/archive/refs/tags/v${hiredis_version}.tar.gz
66 SOURCE_DIR ${hiredis_dir}
67 BINARY_DIR ${hiredis_build}
70 FetchContent_GetProperties(hiredis)
71 if(NOT hiredis_POPULATED)
72 FetchContent_Populate(hiredis)
77 "${hiredis_dir}/alloc.c"
78 "${hiredis_dir}/async.c"
79 "${hiredis_dir}/dict.c"
80 "${hiredis_dir}/hiredis.c"
81 "${hiredis_dir}/net.c"
82 "${hiredis_dir}/read.c"
83 "${hiredis_dir}/sds.c"
84 "${hiredis_dir}/sockcompat.c"
86 add_library(libhiredis_static STATIC EXCLUDE_FROM_ALL ${hiredis_sources})
87 add_library(HIREDIS::HIREDIS ALIAS libhiredis_static)
90 target_compile_definitions(libhiredis_static PRIVATE _CRT_SECURE_NO_WARNINGS)
93 make_directory("${hiredis_dir}/include")
94 make_directory("${hiredis_dir}/include/hiredis")
95 file(GLOB hiredis_headers "${hiredis_dir}/*.h")
96 file(COPY ${hiredis_headers} DESTINATION "${hiredis_dir}/include/hiredis")
97 set_target_properties(
100 INTERFACE_INCLUDE_DIRECTORIES "$<BUILD_INTERFACE:${hiredis_dir}/include>")
102 set(hiredis_FOUND TRUE)
103 set(target libhiredis_static)
106 if(WIN32 AND hiredis_FOUND)
107 target_link_libraries(${target} INTERFACE ws2_32)
110 include(FeatureSummary)
111 set_package_properties(
114 URL "https://github.com/redis/hiredis"
115 DESCRIPTION "Hiredis is a minimalistic C client library for the Redis database"