From fc2c43fa07e45e1ef0f77cbda6a240e7890ae5aa Mon Sep 17 00:00:00 2001 From: Manu-sh Date: Tue, 31 Aug 2021 16:51:04 +0200 Subject: [PATCH 1/8] Update client.cpp (#80) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit MY_PATH/cpp_redis-src/sources/core/client.cpp: In member function ‘void cpp_redis::client::sleep_before_next_reconnect_attempt()’: MY_PATH/cpp_redis-src/sources/core/client.cpp:347:21: error: ‘sleep_for’ is not a member of ‘std::this_thread’ 347 | std::this_thread::sleep_for(std::chrono::milliseconds(m_reconnect_interval_msecs)); --- sources/core/client.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/sources/core/client.cpp b/sources/core/client.cpp index 659c0498..233a19e2 100644 --- a/sources/core/client.cpp +++ b/sources/core/client.cpp @@ -23,6 +23,7 @@ #include #include #include +#include namespace cpp_redis { From ab5ea8638bc51e3d407b0045aceb5c5fd3218aa0 Mon Sep 17 00:00:00 2001 From: Zhichao Li <1072526820@qq.com> Date: Fri, 2 Sep 2022 15:14:58 +0800 Subject: [PATCH 2/8] fix example cc_binary:example_cpp_redis_client build failed (#93) * fix example cc_binary:example_cpp_redis_client build failed * Update WORKSPACE --- BUILD.bazel | 5 ++++- examples/cpp_redis_client.cpp | 5 ++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/BUILD.bazel b/BUILD.bazel index 54aafe4a..1d2ebd02 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -73,7 +73,10 @@ cc_binary( cc_binary( name = "example_cpp_redis_client", - srcs = ["examples/cpp_redis_client.cpp"], + srcs = [ + "examples/cpp_redis_client.cpp", + "examples/winsock_initializer.h" + ], # TODO (steple): For windows, link ws2_32 instead. linkopts = ["-lpthread"], deps = ["cpp_redis"], diff --git a/examples/cpp_redis_client.cpp b/examples/cpp_redis_client.cpp index 93b8e80a..096ec1d1 100644 --- a/examples/cpp_redis_client.cpp +++ b/examples/cpp_redis_client.cpp @@ -22,12 +22,11 @@ #include #include #include -#include "winsock_initializer.h" +#include "examples/winsock_initializer.h" #define ENABLE_SESSION = 1 -int -main(void) { +int main(void) { winsock_initializer winsock_init; //! Enable logging cpp_redis::active_logger = std::unique_ptr(new cpp_redis::logger); From 3bcded90ddd485dd6c6b7a9f2834f04184cdd131 Mon Sep 17 00:00:00 2001 From: Henrik Lindblom <1138921+lindblandro@users.noreply.github.com> Date: Sat, 15 Oct 2022 07:26:56 +0300 Subject: [PATCH 3/8] Cmake refactor (#52) * cmake: clean up CMakeLists.txt - Move project definition to the top and add VERSION - Remove obsolete variable PROJECT and use standard PROJECT_NAME - Require a more modern version of CMake - Use CMAKE_CXX_STANDARD instead of manually adding -std=c++11 - Only include ExternalProject if required * cmake: indent CMakeLists.txt according to best practices Rules from: https://community.kde.org/Policies/CMake_Coding_Style#Indentation Since rest of the codebase doesn't use tabs, CMake files shouldn't either. * cmake: make the main target a shared library CMake sets PIC automatically for shared libraries and modules. * cmake: set policy CMP0048 to NEW This enables PROJECT_* variables. * cmake: use add_compile_options() instead of CMAKE_CXX_FLAGS * cmake: move source handling to sources.cmake Don't add headers as direct dependencies to targets. Compilers can detect header dependencies and manage recompilation automatically. Use list(APPEND ...) in favor of the less explicit set(var ${var} ...). Downcase variable names to separate project local variables to CMake vars. * cmake use FindThreads.cmake to select thread implementation * cmake: downcase tacopie_* variables * cmake: remove reference to obsolete variable SOURCES * cmake: explicitly customize tacopie build Set configuration parameters before adding tacopie subdirectory to force wanted behavior. * cmake: document build parameters options * cmake: remove resetting BUILD_EXAMPLES * cmake: downcase install script file() calls * cmake: use googletest 1.10.0 from a submodule A common use case is to integrate libraries as git submodules and a single project might have multiple modules each with test dependencies to gtest. Usually the top level project configures gtest, propagating the target to it's submodules. This is preferable to the case where each submodule uses ExternalProject to build & install gtest in a custom location with possibly arbitrary target names (googletest, gtest, _gtest, etc.) as this can easily lead to multiple gtest builds. As a solution check if gtest (which is defined by googletest's build files) is an existing target to determine if project's own googletest submodule should be added to the build. Either way the subsequent add_subdirectory() tests will have a target "gtest" to link against. Various INTERFACE flags will take care of the rest. A further improvement is to add "${PROJECT_NAME}::" as a prefix to the tests. This helps when cpp_redis is a part of a larger project and (for any reason) developers want to run cpp_redis' tests only using "ctest -R cpp_redis". * cmake: remove matching conditions from endifs They make maintaining the file extremely frustrating as they break all the time. AFAIK the style if () endif () is rarely seen anymore. * cmake: add includes as public interface include directories * update tacopie submodule * cmake: move tacopie configuration above main target * cmake: use PROJECT_NAME when configuring project pkg-config file * cmake: add different include dirs depending on build/install state When building the include directories should be absolute paths, but obviously when installing / exporting the paths should be relative. * cmake: install via install(TARGETS) - add SOVERSION and RESOURCE properties The former results in a symlink during installation phase (on platforms that support such things) and the latter makes it easier to install extra stuff in install(TARGETS). - add EXPORT target name - remove unnecessary and harmful install(DIRECTORY) calls * update tacopie submodule Support for EXPORT_TARGET_NAME and better install support all around. * cmake: remove deprecated features Using tacopie from system libdir might be good feature to have, but the current implementation is buggy. Add it properly later using pkgconfig or CMake imports. * cmake: add install(EXPORT) The call will automatically install the project configuration as an importable file called lib/cpp_redis/cpp_redis.cmake. The file will configure installed targets as imports so that they can be used like regular CMake targets. * ci: travis: download a more recent cmake * ci: travis: allow existing deps dir * ci: travis: calculate md5sum in a portable way * ci: travis: disable md5 check and trust https certificate * ci: travis: export custom cmake dir in PATH * cmake: add guards against unknown policies Allow the configuration to go slightly further with older versions. * ci: travis: print cmake path & version * cmake: refactor project() call to support older versions Also move the cmake_minimum_required() at the top of the file as per cmake official recommendations. * ci: travis: fix cmake path settings for osx CMake's OSx tarball contents are different than on Linux. Handle those in travis. * ci: travis: fix syntax error in if clause * ci: travis: extract functionality into scripts Travis build file was getting harder to read. Extract the same steps into scripts. Most of the files need to be sourced as they conditionally set environment variables. * ci: travis: run pre-build configuration code from scripts * install-cmake.sh: remove stale variable references * ci: travis: print env before build * install-cmake.sh: simplify install dir handling Tar creates a directory called ${CMAKE_FILE}, just use that in ${CMAKE_INSTALL_DIR}. * ci: travis: list CMAKE_INSTALL_DIR contents * install-cmake: fix mkdir param After the last change CMAKE_INSTALL_DIR was defined in terms of CMAKE_DOWNLOAD_DIR. Co-authored-by: Henrik Lindblom Co-authored-by: Nick Atkins --- .gitmodules | 7 +- .travis.yml | 32 +++- CMakeLists.txt | 245 +++++++++++++--------------- googletest | 1 + scripts/install-cmake.sh | 30 ++++ scripts/install-osx-dependencies.sh | 5 + scripts/prepare.sh | 9 + scripts/start-redis.sh | 5 + sources.cmake | 23 +++ tacopie | 2 +- tests/CMakeLists.txt | 65 +++----- 11 files changed, 235 insertions(+), 189 deletions(-) create mode 160000 googletest create mode 100755 scripts/install-cmake.sh create mode 100755 scripts/install-osx-dependencies.sh create mode 100755 scripts/prepare.sh create mode 100755 scripts/start-redis.sh create mode 100644 sources.cmake diff --git a/.gitmodules b/.gitmodules index b3cd5e2a..9e923b3a 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "tacopie"] - path = tacopie - url = https://github.com/Cylix/tacopie.git + path = tacopie + url = https://github.com/lindblandro/tacopie.git +[submodule "googletest"] + path = googletest + url = https://github.com/google/googletest.git diff --git a/.travis.yml b/.travis.yml index 69775881..72bbf3dc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,14 +23,28 @@ addons: - clang before_install: - - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update; fi - - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install llvm; fi + - source scripts/prepare.sh install: - - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install ccache; fi - - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then export PATH="/usr/local/opt/ccache/libexec:$PATH"; fi - - if [[ "$TRAVIS_OS_NAME" != "osx" && "$CXX" = "g++" ]]; then export CXX="g++-4.8" CC="gcc-4.8"; fi - - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install redis; fi - - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then (redis-server&); fi - -script: mkdir build && cd build && cmake .. -DBUILD_TESTS=true -DBUILD_EXAMPLES=true && make && GTEST_COLOR=1 ctest -VV + - source scripts/install-osx-dependencies.sh + - source scripts/install-cmake.sh +before_script: + - source scripts/start-redis.sh + # create a build folder for the out-of-source build + - mkdir build + # switch to build directory + - cd build + # run cmake; here we assume that the project's + # top-level CMakeLists.txt is located at '..' + - ls ${CMAKE_INSTALL_DIR} + - ls ${CMAKE_INSTALL_DIR}/bin + - env + - which cmake + - cmake --version + - cmake .. -DBUILD_TESTS=true -DBUILD_EXAMPLES=true + +script: + # once CMake has done its job we just build using make as usual + - make + # if the project uses ctest we can run the tests like this + - GTEST_COLOR=1 ctest -VV diff --git a/CMakeLists.txt b/CMakeLists.txt index 3eb64968..96314d71 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,110 +20,90 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. +cmake_minimum_required(VERSION 3.13) + ### -# config +# project ### -cmake_minimum_required(VERSION 2.8.7) +if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.12) + cmake_policy(SET CMP0048 NEW) + project(cpp_redis + VERSION 4.4.0 + DESCRIPTION "Lightweight C++11 Redis Client" + HOMEPAGE_URL "https://github.com/cpp-redis/cpp_redis" + LANGUAGES CXX) +else () + # for cmake >= 3.0 + project(cpp_redis VERSION 4.4.0 LANGUAGES CXX) +endif () +if (POLICY CMP0077) + cmake_policy(SET CMP0077 NEW) +endif () + set(CMAKE_MACOSX_RPATH 1) -include(${CMAKE_ROOT}/Modules/ExternalProject.cmake) +set(CMAKE_CXX_STANDARD 11) +set(EXPORT_TARGET_NAME ${PROJECT_NAME} CACHE STRING "Name of the exported CMake target used in install(EXPORT)") ### # verbose make ### # set(CMAKE_VERBOSE_MAKEFILE TRUE) - -### -# project -### -set(PROJECT cpp_redis) -project(${PROJECT} CXX) - +include(sources.cmake) ### # compilation options ### if (MSVC) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W3 /O2 /bigobj") - - # was causing conflics with gtest build - string(REPLACE "/RTC1" "" CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG}) - - if ("${MSVC_RUNTIME_LIBRARY_CONFIG}" STREQUAL "") - set(MSVC_RUNTIME_LIBRARY_CONFIG "/MT") - endif () - - foreach (flag_var CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE) - if ("${MSVC_RUNTIME_LIBRARY_CONFIG}" STREQUAL "/MT") - string(REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}") - elseif ("${MSVC_RUNTIME_LIBRARY_CONFIG}" STREQUAL "/MD") - string(REPLACE "/MT" "/MD" ${flag_var} "${${flag_var}}") - else () - string(REPLACE "/MD" "${MSVC_RUNTIME_LIBRARY_CONFIG}" ${flag_var} "${${flag_var}}") - string(REPLACE "/MT" "${MSVC_RUNTIME_LIBRARY_CONFIG}" ${flag_var} "${${flag_var}}") - endif () - endforeach () - - add_definitions(-D_UNICODE) - add_definitions(-DUNICODE) - add_definitions(-DWIN32_LEAN_AND_MEAN) + add_compile_options(/W3 /O2 /bigobj) + + # was causing conflics with gtest build + string(REPLACE "/RTC1" "" CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG}) + + if ("${MSVC_RUNTIME_LIBRARY_CONFIG}" STREQUAL "") + set(MSVC_RUNTIME_LIBRARY_CONFIG "/MT") + endif () + + foreach (flag_var CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE) + if ("${MSVC_RUNTIME_LIBRARY_CONFIG}" STREQUAL "/MT") + string(REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}") + elseif ("${MSVC_RUNTIME_LIBRARY_CONFIG}" STREQUAL "/MD") + string(REPLACE "/MT" "/MD" ${flag_var} "${${flag_var}}") + else () + string(REPLACE "/MD" "${MSVC_RUNTIME_LIBRARY_CONFIG}" ${flag_var} "${${flag_var}}") + string(REPLACE "/MT" "${MSVC_RUNTIME_LIBRARY_CONFIG}" ${flag_var} "${${flag_var}}") + endif () + endforeach () + + add_definitions(-D_UNICODE) + add_definitions(-DUNICODE) + add_definitions(-DWIN32_LEAN_AND_MEAN) else () - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -W -Wall -Wextra -O3") + add_compile_options(-W -Wall -Wextra -O3) endif () - ### -# variables +# tacopie ### -find_path(TACOPIE_INCLUDE_DIR tacopie/tacopie PATHS ${PROJECT_SOURCE_DIR}/tacopie/includes/) -find_library(TACOPIE_LIBRARY tacopie) -set(CPP_REDIS_INCLUDES ${PROJECT_SOURCE_DIR}/includes) -set(DEPS_INCLUDES ${PROJECT_SOURCE_DIR}/deps/include) - -if (NOT USE_CUSTOM_TCP_CLIENT) - set(DEPS_INCLUDES ${DEPS_INCLUDES} ${TACOPIE_INCLUDE_DIR}) +if (NOT tacopie_library AND NOT USE_CUSTOM_TCP_CLIENT) + # requires CMP0077 set to NEW + set(BUILD_EXAMPLES OFF) + set(BUILD_TESTS OFF) + add_subdirectory(tacopie) + # TODO: add alias library endif () -set(DEPS_LIBRARIES ${PROJECT_SOURCE_DIR}/deps/lib) - - -### -# includes -### -include_directories(${CPP_REDIS_INCLUDES} ${DEPS_INCLUDES}) - - -### -# sources -### -set(SRC_DIRS "sources" - "sources/builders" - "sources/core" - "sources/misc" - "sources/network" - "includes/cpp_redis" - "includes/cpp_redis/builders" - "includes/cpp_redis/core" - "includes/cpp_redis/misc" - "includes/cpp_redis/network") +set(cpp_redis_includes ${CMAKE_CURRENT_LIST_DIR}/includes) +set(deps_includes ${CMAKE_CURRENT_LIST_DIR}/deps/include) -foreach (dir ${SRC_DIRS}) - # get directory sources and headers - file(GLOB s_${dir} "${dir}/*.cpp") - file(GLOB h_${dir} "${dir}/*.hpp") - file(GLOB i_${dir} "${dir}/*.ipp") +set(deps_libraries ${PROJECT_SOURCE_DIR}/deps/lib) - # set sources - set(SOURCES ${SOURCES} ${s_${dir}} ${h_${dir}} ${i_${dir}}) -endforeach () # filter tcp_client if no tacopie if (USE_CUSTOM_TCP_CLIENT) - file(GLOB tacopie_cpp "sources/network/tcp_client.cpp") - file(GLOB tacopie_h "includes/cpp_redis/network/tcp_client.hpp") - list(REMOVE_ITEM SOURCES ${tacopie_cpp} ${tacopie_h}) -endif (USE_CUSTOM_TCP_CLIENT) - + file(GLOB tacopie_cpp "sources/network/tcp_client.cpp") + list(REMOVE_ITEM ${cpp_redis_sources} ${tacopie_cpp}) +endif () ### # outputs @@ -136,88 +116,83 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) ### # pkg-config ### -configure_file("cpp_redis.pc.in" "${CMAKE_PKGCONFIG_OUTPUT_DIRECTORY}/cpp_redis.pc" @ONLY) +configure_file("${PROJECT_NAME}.pc.in" "${CMAKE_PKGCONFIG_OUTPUT_DIRECTORY}/${PROJECT_NAME}.pc" @ONLY) ### -# executable +# main target ### -add_library(${PROJECT} ${SOURCES}) -set_property(TARGET ${PROJECT} PROPERTY POSITION_INDEPENDENT_CODE ON) +add_library(${PROJECT_NAME} SHARED ${cpp_redis_sources}) -if (WIN32) - set_target_properties(${PROJECT} - PROPERTIES COMPILE_PDB_NAME ${PROJECT} - COMPILE_PDB_OUTPUT_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}) -endif (WIN32) +### +# includes +### +target_include_directories(${PROJECT_NAME} PUBLIC + $ + $) if (WIN32) - target_link_libraries(${PROJECT} ws2_32) -else () - target_link_libraries(${PROJECT} pthread) -endif (WIN32) + set_target_properties(${PROJECT_NAME} PROPERTIES + COMPILE_PDB_NAME ${PROJECT_NAME} + COMPILE_PDB_OUTPUT_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}) +endif () -if (TACOPIE_LIBRARY) - target_link_libraries(${PROJECT} ${TACOPIE_LIBRARY}) -else () - target_link_libraries(${PROJECT} tacopie) -endif (TACOPIE_LIBRARY) +set_target_properties(${PROJECT_NAME} PROPERTIES + SOVERSION ${PROJECT_VERSION} + RESOURCE ${CMAKE_PKGCONFIG_OUTPUT_DIRECTORY}/${PROJECT_NAME}.pc) + +find_package(Threads REQUIRED) +target_link_libraries(${PROJECT_NAME} PRIVATE Threads::Threads) +if (tacopie_library) + target_link_libraries(${PROJECT_NAME} PUBLIC ${tacopie_library}) +else () + target_link_libraries(${PROJECT_NAME} PUBLIC tacopie) +endif () -# __CPP_REDIS_READ_SIZE -if (READ_SIZE) - set_property(TARGET ${PROJECT} APPEND_STRING PROPERTY COMPILE_DEFINITIONS " __CPP_REDIS_READ_SIZE=${READ_SIZE}") -endif (READ_SIZE) +### +# parameters +### +set(READ_SIZE "4096" CACHE STRING "Number of bytes read from sockets") +if (READ_SIZE MATCHES "^[1-9]+") + target_compile_definitions(${PROJECT_NAME} PRIVATE __CPP_REDIS_READ_SIZE=${READ_SIZE}) +endif () -# __CPP_REDIS_LOGGING_ENABLED +option(LOGGING_ENABLED "If true enables logging calls to cpp_redis::level()" OFF) if (LOGGING_ENABLED) - set_property(TARGET ${PROJECT} APPEND_STRING PROPERTY COMPILE_DEFINITIONS " __CPP_REDIS_LOGGING_ENABLED=${LOGGING_ENABLED}") -endif (LOGGING_ENABLED) + target_compile_definitions(${PROJECT_NAME} PRIVATE __CPP_REDIS_LOGGING_ENABLED) +endif () -# __CPP_REDIS_USE_CUSTOM_TCP_CLIENT +option(USE_CUSTOM_TCP_CLIENT "If true user must provide a custom tcp_client_iface instance, otherwise uses tacopie" OFF) if (USE_CUSTOM_TCP_CLIENT) - set_property(TARGET ${PROJECT} APPEND_STRING PROPERTY COMPILE_DEFINITIONS " __CPP_REDIS_USE_CUSTOM_TCP_CLIENT=${USE_CUSTOM_TCP_CLIENT}") -endif (USE_CUSTOM_TCP_CLIENT) - + target_compile_definitions(${PROJECT_NAME} PRIVATE __CPP_REDIS_USE_CUSTOM_TCP_CLIENT) +endif () ### # install ### -# ensure lib and bin directories exist -install(CODE "FILE(MAKE_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})") -install(CODE "FILE(MAKE_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})") -# install cpp_redis -install(DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/ DESTINATION lib USE_SOURCE_PERMISSIONS) -install(DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ DESTINATION bin USE_SOURCE_PERMISSIONS) -install(DIRECTORY ${CPP_REDIS_INCLUDES}/ DESTINATION include USE_SOURCE_PERMISSIONS) +install(DIRECTORY ${cpp_redis_includes}/ DESTINATION include USE_SOURCE_PERMISSIONS) +include(GNUInstallDirs) +install(TARGETS ${PROJECT_NAME} EXPORT ${EXPORT_TARGET_NAME} + LIBRARY + RESOURCE DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) +install(EXPORT ${EXPORT_TARGET_NAME} DESTINATION lib/${PROJECT_NAME} EXPORT_LINK_INTERFACE_LIBRARIES) ### # examples ### if (BUILD_EXAMPLES) - add_subdirectory(examples) - # Reset variable to false to ensure tacopie does no build examples - set(BUILD_EXAMPLES false) -endif (BUILD_EXAMPLES) + add_subdirectory(examples) +endif () ### # tests ### if (BUILD_TESTS) - enable_testing() - add_subdirectory(tests) - ExternalProject_Add("googletest" - GIT_REPOSITORY "https://github.com/google/googletest.git" - CMAKE_ARGS "-DCMAKE_INSTALL_PREFIX=${PROJECT_SOURCE_DIR}/deps") - # Reset variable to false to ensure tacopie does no build tests - set(BUILD_TESTS false) -endif (BUILD_TESTS) - - -### -# tacopie -### -if (NOT TACOPIE_LIBRARY AND NOT USE_CUSTOM_TCP_CLIENT) - set(SOURCES) # reset the SOURCES var so that the tacopie project won't include the cpp_redis sources too - add_subdirectory(tacopie) -endif (NOT TACOPIE_LIBRARY AND NOT USE_CUSTOM_TCP_CLIENT) + enable_testing() + if (NOT TARGET gtest) + set(INSTALL_GTEST OFF) + add_subdirectory(googletest) + endif () + add_subdirectory(tests) +endif () diff --git a/googletest b/googletest new file mode 160000 index 00000000..703bd9ca --- /dev/null +++ b/googletest @@ -0,0 +1 @@ +Subproject commit 703bd9caab50b139428cea1aaff9974ebee5742e diff --git a/scripts/install-cmake.sh b/scripts/install-cmake.sh new file mode 100755 index 00000000..a37cd52a --- /dev/null +++ b/scripts/install-cmake.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env sh -x + +# this script needs to be sourced +CMAKE_DOWNLOAD_DIR="${TRAVIS_BUILD_DIR}/deps" +CMAKE_VERSION_MAJOR="3" +CMAKE_VERSION_MINOR="15" +CMAKE_VERSION_PATCH="3" +CMAKE_VERSION="${CMAKE_VERSION_MAJOR}.${CMAKE_VERSION_MINOR}.${CMAKE_VERSION_PATCH}" + +CMAKE_PLATFORM="Linux" +if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then + CMAKE_PLATFORM="Darwin"; +fi + +CMAKE_FILE="cmake-${CMAKE_VERSION}-${CMAKE_PLATFORM}-x86_64" +CMAKE_DIR="v${CMAKE_VERSION_MAJOR}.${CMAKE_VERSION_MINOR}" +CMAKE_FILE_URL="https://cmake.org/files/${CMAKE_DIR}/${CMAKE_FILE}.tar.gz" + +mkdir -p ${CMAKE_DOWNLOAD_DIR} + +cd ${CMAKE_DOWNLOAD_DIR} +travis_retry wget ${CMAKE_FILE_URL} +tar -xvf ${CMAKE_FILE}.tar.gz > /dev/null +CMAKE_INSTALL_DIR="${CMAKE_DOWNLOAD_DIR}/${CMAKE_FILE}" +if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then + CMAKE_INSTALL_DIR="${CMAKE_INSTALL_DIR}/CMake.app/Contents"; +fi +export PATH="${CMAKE_INSTALL_DIR}:${CMAKE_INSTALL_DIR}/bin:$PATH" + +cd - diff --git a/scripts/install-osx-dependencies.sh b/scripts/install-osx-dependencies.sh new file mode 100755 index 00000000..1030a7bc --- /dev/null +++ b/scripts/install-osx-dependencies.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env sh -x +if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then + brew update + brew install llvm ccache install redis +fi diff --git a/scripts/prepare.sh b/scripts/prepare.sh new file mode 100755 index 00000000..768bcd02 --- /dev/null +++ b/scripts/prepare.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env sh -x + +if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then + export PATH="/usr/local/opt/ccache/libexec:$PATH" +fi + +if [[ "$TRAVIS_OS_NAME" != "osx" && "$CXX" = "g++" ]]; then + export CXX="g++-4.8" CC="gcc-4.8" +fi diff --git a/scripts/start-redis.sh b/scripts/start-redis.sh new file mode 100755 index 00000000..936644c8 --- /dev/null +++ b/scripts/start-redis.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env sh -x + +if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then + (redis-server&); +fi diff --git a/sources.cmake b/sources.cmake new file mode 100644 index 00000000..743d1958 --- /dev/null +++ b/sources.cmake @@ -0,0 +1,23 @@ +set(cpp_redis_sources + sources/builders/array_builder.cpp + sources/builders/builders_factory.cpp + sources/builders/bulk_string_builder.cpp + sources/builders/error_builder.cpp + sources/builders/integer_builder.cpp + sources/builders/reply_builder.cpp + sources/builders/simple_string_builder.cpp + sources/core/client.cpp + sources/core/consumer.cpp + sources/core/reply.cpp + sources/core/sentinel.cpp + sources/core/subscriber.cpp + sources/core/types.cpp + sources/misc/dispatch_queue.cpp + sources/misc/logger.cpp + sources/network/redis_connection.cpp + sources/network/tcp_client.cpp + ) + +set(cpp_redis_includes + includes/cpp_redis + ) diff --git a/tacopie b/tacopie index 6b060c7f..0a13c7ad 160000 --- a/tacopie +++ b/tacopie @@ -1 +1 @@ -Subproject commit 6b060c7f7e158e60d634c14e412aa78d4041f237 +Subproject commit 0a13c7ad7e30f9c9c794ab3ad9863f6e284c5a94 diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 9ed03609..8f7cf6a8 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -20,49 +20,30 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. -### -# project -### -set(PROJECT cpp_redis_tests) -project(${PROJECT} CXX) - - -### -# compilation options -### -if(NOT WIN32) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") -endif(NOT WIN32) - - -### -# includes -### -include_directories(${DEPS_INCLUDES} ${CPP_REDIS_INCLUDES}) - - -### -# libraries -### -link_directories(${DEPS_LIBRARIES}) - - ### # executables ### -set(MAIN "sources/main.cpp") -set(DIRS "sources/spec" "sources/spec/**") -foreach(DIR ${DIRS}) - file(GLOB s_${DIR} "${DIR}/*.cpp") - foreach(SOURCE ${s_${DIR}}) - get_filename_component(TEST_NAME ${SOURCE} NAME_WE) - add_executable(${TEST_NAME} ${MAIN} ${SOURCE}) - target_link_libraries(${TEST_NAME} cpp_redis gtest) - if(WIN32) - target_link_libraries(${TEST_NAME} ws2_32) - else() - target_link_libraries(${TEST_NAME} pthread) - endif(WIN32) - add_test(NAME ${TEST_NAME}_tests COMMAND ${TEST_NAME}) - endforeach() +set(main "sources/main.cpp") + +macro(add_spec_test source) + get_filename_component(test_name ${source} NAME_WE) + add_executable(${test_name} ${main} ${source}) + target_link_libraries(${test_name} PRIVATE ${PROJECT_NAME} gtest Threads::Threads) + add_test(NAME ${PROJECT_NAME}::${test_name}_tests COMMAND ${test_name}) +endmacro() + +set(tests + sources/spec/builders/array_builder_spec.cpp + sources/spec/builders/integer_builder_spec.cpp + sources/spec/builders/builders_factory_spec.cpp + sources/spec/builders/reply_builder_spec.cpp + sources/spec/builders/bulk_string_builder_spec.cpp + sources/spec/builders/simple_string_builder_spec.cpp + sources/spec/builders/error_builder_spec.cpp + sources/spec/redis_client_spec.cpp + sources/spec/redis_subscriber_spec.cpp + sources/spec/reply_spec.cpp) + +foreach(test ${tests}) + add_spec_test(${test}) endforeach() From db208de61cd81ac8c1c50e71c580ec35277e86a1 Mon Sep 17 00:00:00 2001 From: Nick Atkins Date: Fri, 14 Oct 2022 23:28:13 -0500 Subject: [PATCH 4/8] Update .gitmodules --- .gitmodules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitmodules b/.gitmodules index 9e923b3a..06c05e70 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,6 @@ [submodule "tacopie"] path = tacopie - url = https://github.com/lindblandro/tacopie.git + url = https://github.com/cpp-redis/tacopie.git [submodule "googletest"] path = googletest url = https://github.com/google/googletest.git From 7247d676499d88e086dcc78b7a9b6987d1622417 Mon Sep 17 00:00:00 2001 From: Nick Atkins Date: Fri, 14 Oct 2022 23:34:41 -0500 Subject: [PATCH 5/8] Create dependabot.yml --- .github/dependabot.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 00000000..f99f0982 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,13 @@ +# To get started with Dependabot version updates, you'll need to specify which +# package ecosystems to update and where the package manifests are located. +# Please see the documentation for all configuration options: +# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates + +version: 2 +updates: + - package-ecosystem: "gitsubmodule" # See documentation for possible values + directory: "/" # Location of package manifests + schedule: + interval: "monthly" + reviewers: + - "cpp-redis/dev" From bd8160f50a2a4ff2a594693d3408f14d1e247534 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 14 Oct 2022 23:36:33 -0500 Subject: [PATCH 6/8] Bump tacopie from `0a13c7a` to `6a0cfca` (#102) Bumps [tacopie](https://github.com/cpp-redis/tacopie) from `0a13c7a` to `6a0cfca`. - [Release notes](https://github.com/cpp-redis/tacopie/releases) - [Commits](https://github.com/cpp-redis/tacopie/compare/0a13c7ad7e30f9c9c794ab3ad9863f6e284c5a94...6a0cfca305cb03dad91d680bff7b06fa8f4b7adc) --- updated-dependencies: - dependency-name: tacopie dependency-type: direct:production ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- tacopie | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tacopie b/tacopie index 0a13c7ad..6a0cfca3 160000 --- a/tacopie +++ b/tacopie @@ -1 +1 @@ -Subproject commit 0a13c7ad7e30f9c9c794ab3ad9863f6e284c5a94 +Subproject commit 6a0cfca305cb03dad91d680bff7b06fa8f4b7adc From a58bb7e67362e4b6b108d563bd04effd4122e0c2 Mon Sep 17 00:00:00 2001 From: avmukilan Date: Sat, 15 Oct 2022 00:44:09 -0400 Subject: [PATCH 7/8] Add count for XREVRANGE (#89) Co-authored-by: Nick Atkins --- sources/core/client.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/sources/core/client.cpp b/sources/core/client.cpp index 233a19e2..b600f209 100644 --- a/sources/core/client.cpp +++ b/sources/core/client.cpp @@ -2574,6 +2574,7 @@ namespace cpp_redis { client::xrevrange(const std::string &key, const range_options_t &range_args, const reply_callback_t &reply_callback) { std::vector cmd = {"XREVRANGE", key, range_args.Start, range_args.Stop}; if (range_args.Count > 0) { + cmd.emplace_back("COUNT"); cmd.emplace_back(std::to_string(range_args.Count)); } send(cmd, reply_callback); From 201d96c59a096a33de6c94e08eb92db737c2e967 Mon Sep 17 00:00:00 2001 From: Nick Atkins Date: Fri, 14 Oct 2022 23:49:35 -0500 Subject: [PATCH 8/8] format action --- .github/workflows/format.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 .github/workflows/format.yml diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml new file mode 100644 index 00000000..85b7b14d --- /dev/null +++ b/.github/workflows/format.yml @@ -0,0 +1,10 @@ +name: Clang Format Checker +on: [push, pull_request] +jobs: + clang-format-checking: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: RafikFarhad/clang-format-github-action@v2.1.0 + with: + sources: "src/**/*.h,src/**/*.c,test/**/*.c"