Skip to content

Instantly share code, notes, and snippets.

@bjosv
Last active September 22, 2022 13:28
Show Gist options
  • Save bjosv/6b61dbb11193fdfd36cbcc82473d1036 to your computer and use it in GitHub Desktop.
Save bjosv/6b61dbb11193fdfd36cbcc82473d1036 to your computer and use it in GitHub Desktop.
FetchContent example
cmake -DDISABLE_TESTS=OFF -DREDIS_PLUS_PLUS_BUILD_TEST=OFF ..
cmake_minimum_required(VERSION 3.24)
project(examples LANGUAGES CXX)
include(FetchContent)
FetchContent_Declare(
hiredis
GIT_REPOSITORY https://github.com/redis/hiredis
GIT_TAG origin/master
GIT_SHALLOW TRUE
# Set path where source is placed
SOURCE_DIR _deps/hiredis
# Make sure redis++ finds fetched content with its find_package()
OVERRIDE_FIND_PACKAGE
)
FetchContent_MakeAvailable(hiredis)
# Set include directory to enable redis++ to find it
include_directories(${CMAKE_BINARY_DIR}/_deps)
FetchContent_Declare(
redis-plus-plus
GIT_REPOSITORY https://github.com/sewenew/redis-plus-plus
GIT_TAG origin/master
GIT_SHALLOW TRUE
)
FetchContent_MakeAvailable(redis-plus-plus)
add_executable(test
main.cc
)
target_link_libraries(test
redis++
)
//#include <sw/redis++/redis++.h>
#include <redis++.h>
#include <iostream>
int main()
{
auto redis = sw::redis::Redis("tcp://127.0.0.1:6379");
redis.set("key", "value");
auto val = redis.get("key");
if (val) {
std::cout << "Got: " << *val << std::endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment