5 set(hiredis_FOUND FALSE)
7 if(HIREDIS_FROM_INTERNET AND NOT HIREDIS_FROM_INTERNET STREQUAL "AUTO")
8 message(STATUS "Using hiredis from the Internet")
11 find_package(PkgConfig)
13 pkg_check_modules(HIREDIS hiredis>=${hiredis_FIND_VERSION})
14 find_library(HIREDIS_LIBRARY ${HIREDIS_LIBRARIES} HINTS ${HIREDIS_LIBDIR})
15 find_path(HIREDIS_INCLUDE_DIR hiredis/hiredis.h HINTS ${HIREDIS_PREFIX}/include)
16 if(HIREDIS_LIBRARY AND HIREDIS_INCLUDE_DIR)
17 message(STATUS "Using hiredis from ${HIREDIS_LIBRARY} via pkg-config")
18 set(hiredis_FOUND TRUE)
23 find_library(HIREDIS_LIBRARY hiredis)
24 find_path(HIREDIS_INCLUDE_DIR hiredis/hiredis.h)
25 if(HIREDIS_LIBRARY AND HIREDIS_INCLUDE_DIR)
26 message(STATUS "Using hiredis from ${HIREDIS_LIBRARY}")
27 set(hiredis_FOUND TRUE)
32 mark_as_advanced(HIREDIS_INCLUDE_DIR HIREDIS_LIBRARY)
33 add_library(HIREDIS::HIREDIS UNKNOWN IMPORTED)
34 set_target_properties(
37 IMPORTED_LOCATION "${HIREDIS_LIBRARY}"
38 INTERFACE_COMPILE_OPTIONS "${HIREDIS_CFLAGS_OTHER}"
39 INTERFACE_INCLUDE_DIRECTORIES "${HIREDIS_INCLUDE_DIR}"
41 if(WIN32 AND STATIC_LINK)
42 target_link_libraries(HIREDIS::HIREDIS INTERFACE ws2_32)
44 set(hiredis_FOUND TRUE)
45 set(target HIREDIS::HIREDIS)
46 elseif(HIREDIS_FROM_INTERNET STREQUAL "AUTO")
47 message(STATUS "*** WARNING ***: Using hiredis from the Internet because it was not found and HIREDIS_FROM_INTERNET is AUTO")
50 include(FindPackageHandleStandardArgs)
51 find_package_handle_standard_args(
53 REQUIRED_VARS HIREDIS_LIBRARY HIREDIS_INCLUDE_DIR
59 set(hiredis_version "1.2.0")
60 set(hiredis_dir ${CMAKE_BINARY_DIR}/hiredis-${hiredis_version})
61 set(hiredis_build ${CMAKE_BINARY_DIR}/hiredis-build)
66 URL https://github.com/redis/hiredis/archive/refs/tags/v${hiredis_version}.tar.gz
67 SOURCE_DIR ${hiredis_dir}
68 BINARY_DIR ${hiredis_build}
71 FetchContent_GetProperties(hiredis)
72 if(NOT hiredis_POPULATED)
73 FetchContent_Populate(hiredis)
78 "${hiredis_dir}/alloc.c"
79 "${hiredis_dir}/async.c"
80 "${hiredis_dir}/dict.c"
81 "${hiredis_dir}/hiredis.c"
82 "${hiredis_dir}/net.c"
83 "${hiredis_dir}/read.c"
84 "${hiredis_dir}/sds.c"
85 "${hiredis_dir}/sockcompat.c"
87 add_library(libhiredis_static STATIC EXCLUDE_FROM_ALL ${hiredis_sources})
88 add_library(HIREDIS::HIREDIS ALIAS libhiredis_static)
91 target_compile_definitions(libhiredis_static PRIVATE _CRT_SECURE_NO_WARNINGS)
94 make_directory("${hiredis_dir}/include")
95 make_directory("${hiredis_dir}/include/hiredis")
96 file(GLOB hiredis_headers "${hiredis_dir}/*.h")
97 file(COPY ${hiredis_headers} DESTINATION "${hiredis_dir}/include/hiredis")
98 set_target_properties(
101 INTERFACE_INCLUDE_DIRECTORIES "$<BUILD_INTERFACE:${hiredis_dir}/include>")
103 set(hiredis_FOUND TRUE)
104 set(target libhiredis_static)
107 if(WIN32 AND hiredis_FOUND)
108 target_link_libraries(${target} INTERFACE ws2_32)
111 include(FeatureSummary)
112 set_package_properties(
115 URL "https://github.com/redis/hiredis"
116 DESCRIPTION "Hiredis is a minimalistic C client library for the Redis database"