From 52b92c92b39788188c9d9e20f1a0e8ab61ad0076 Mon Sep 17 00:00:00 2001 From: psalvaggio Date: Fri, 20 Oct 2017 12:15:59 -0400 Subject: [PATCH] Upgrade to target-based CMake. Added option for shared libraries. (#46) --- CMakeLists.txt | 144 ++++++++++----------- appveyor.yml | 2 +- benchmarks/CMakeLists.txt | 54 ++------ cmake/Dependencies.cmake | 21 ++++ cmake/Install.cmake | 28 +++++ cmake/Utils.cmake | 146 ++++++++++++++++++++++ cmake/config/Config.cmake.in | 33 +++++ examples/CMakeLists.txt | 49 ++------ examples/sync_pipeline.cpp | 1 + src/CMakeLists.txt | 1 + src/redisclient/CMakeLists.txt | 46 +++++++ src/redisclient/impl/pipeline.cpp | 6 +- src/redisclient/impl/redisasyncclient.cpp | 2 +- src/redisclient/impl/redisclientimpl.h | 6 +- src/redisclient/impl/redisparser.cpp | 2 +- src/redisclient/impl/redissyncclient.cpp | 4 +- src/redisclient/impl/redisvalue.cpp | 2 +- src/redisclient/pipeline.h | 2 +- src/redisclient/redisasyncclient.h | 4 +- src/redisclient/redisparser.h | 2 +- src/redisclient/redissyncclient.h | 4 +- src/redisclient/redisvalue.h | 2 +- tests/CMakeLists.txt | 2 + 23 files changed, 381 insertions(+), 182 deletions(-) create mode 100644 cmake/Dependencies.cmake create mode 100644 cmake/Install.cmake create mode 100644 cmake/Utils.cmake create mode 100644 cmake/config/Config.cmake.in create mode 100644 src/CMakeLists.txt create mode 100644 src/redisclient/CMakeLists.txt create mode 100644 tests/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 951c9b4..6fed0a9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,92 +1,74 @@ -cmake_minimum_required(VERSION 2.6) - -PROJECT(RedisClient) - -OPTION(ADDRESS_SANITIZER "Enable address sanitizer" OFF) -OPTION(BENCHMARK "Build benmarks" OFF) - -if(NOT CMAKE_BUILD_TYPE) - message(STATUS "No build type selected, default to Release") - set(CMAKE_BUILD_TYPE "Release") +# CMake script for RedisClient +############################################################ + +cmake_minimum_required(VERSION 3.1) + +# Project and Versioning +project(RedisClient) +set(VERSION_MAJOR 0 CACHE STRING "Project major version number.") +set(VERSION_MINOR 5 CACHE STRING "Project minor version number.") +set(VERSION_PATCH 0 CACHE STRING "Project patch version number.") +set(VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}) +mark_as_advanced(VERSION_MAJOR VERSION_MINOR VERSION_PATCH VERSION) + +# Include utility functions +include(cmake/Utils.cmake) + +# Set the C++11 standard +set(CMAKE_CXX_STANDARD 11) + +# Build options +option(ADDRESS_SANITIZER "Enable address sanitizer" OFF) +option(BENCHMARK "Build benmarks" OFF) +option(BUILD_SHARED_LIBS "Whether to build shared libraries" ON) +option(BUILD_TEST "Whether to build the unit tests" ON) +option(BUILD_EXAMPLES "Whether to build the examples" ON) +option(HEADER_ONLY "Whether to build in header-only mode" OFF) + +# Default to Release mode +if (NOT CMAKE_BUILD_TYPE) + message(STATUS "No build type selected, default to Release") + set(CMAKE_BUILD_TYPE "Release") endif() -if(ADDRESS_SANITIZER) - message(STATUS "Build with address-sanitizer") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address") - set(CMAKE_LD_FLAGS "-fsanitize=address") +# Optionally add the address sanitizer +if (ADDRESS_SANITIZER) + message(STATUS "Build with address-sanitizer") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address") + set(CMAKE_LD_FLAGS "-fsanitize=address") endif() -if(MSVC) - ADD_DEFINITIONS(-DBOOST_ALL_NO_LIB) +if (MSVC) + add_definitions(-DBOOST_ALL_NO_LIB) endif() -if(NOT Boost_USE_STATIC_LIBS) - ADD_DEFINITIONS(-DBOOST_ALL_DYN_LINK) +if (NOT Boost_USE_STATIC_LIBS) + add_definitions(-DBOOST_ALL_DYN_LINK) endif() -FIND_PACKAGE(Boost COMPONENTS system program_options unit_test_framework date_time REQUIRED) - -LINK_DIRECTORIES(${Boost_LIBRARY_DIRS}) - -IF(MSVC) - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W3") - SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /Od -DDEBUG ") - SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /O2 -DNDEBUG") -ELSE() - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -W -Wall -Wextra -fPIC -pthread -std=c++11") - SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -g3 -DDEBUG ") - SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -g3 -DNDEBUG") -ENDIF() - -SET(SOURCES - ${CMAKE_CURRENT_SOURCE_DIR}/src/redisclient/impl/redisvalue.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/src/redisclient/impl/redissyncclient.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/src/redisclient/impl/redisparser.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/src/redisclient/impl/redisclientimpl.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/src/redisclient/impl/redisasyncclient.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/src/redisclient/impl/pipeline.cpp -) - -SET(HEADERS - ${CMAKE_CURRENT_SOURCE_DIR}/src/redisclient/config.h - ${CMAKE_CURRENT_SOURCE_DIR}/src/redisclient/version.h - ${CMAKE_CURRENT_SOURCE_DIR}/src/redisclient/redisvalue.h - ${CMAKE_CURRENT_SOURCE_DIR}/src/redisclient/redissyncclient.h - ${CMAKE_CURRENT_SOURCE_DIR}/src/redisclient/redisparser.h - ${CMAKE_CURRENT_SOURCE_DIR}/src/redisclient/redisbuffer.h - ${CMAKE_CURRENT_SOURCE_DIR}/src/redisclient/redisasyncclient.h - ${CMAKE_CURRENT_SOURCE_DIR}/src/redisclient/pipeline.h - ${CMAKE_CURRENT_SOURCE_DIR}/src/redisclient/impl/redisclientimpl.h -) - -INCLUDE_DIRECTORIES( - ${CMAKE_CURRENT_BINARY_DIR} - ${CMAKE_CURRENT_SOURCE_DIR}/src - ${Boost_INCLUDE_DIRS} -) - -ADD_EXECUTABLE(parsertest tests/parsertest.cpp ${SOURCES} ${HEADERS}) -ADD_EXECUTABLE(redisvaluetest tests/redisvaluetest.cpp ${SOURCES} ${HEADERS}) -ADD_LIBRARY(redisclient STATIC ${HEADERS} ${SOURCES}) - -SET(TESTS - parsertest - redisvaluetest -) - -FOREACH(TEST ${TESTS}) - TARGET_LINK_LIBRARIES(${TEST} ${Boost_SYSTEM_LIBRARY} ${Boost_DATE_TIME_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) -ENDFOREACH() - - -INSTALL(DIRECTORY ${CMAKE_SOURCE_DIR}/src DESTINATION include) - -ADD_SUBDIRECTORY(examples) -if(ADDRESS_SANITIZER) - ADD_SUBDIRECTORY(benchmarks) +# Find all of our dependencies +include(cmake/Dependencies.cmake) + +if (MSVC) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W3") + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /Od -DDEBUG ") + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /O2 -DNDEBUG") +else() + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -W -Wall -Wextra -pthread") + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -g3 -DDEBUG ") + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -DNDEBUG") endif() -INCLUDE(CTest) -ADD_TEST(ParserTest parsertest) -ADD_TEST(RedisValueTest redisvaluetest) +add_subdirectory(src) +if (BUILD_EXAMPLES) + add_subdirectory(examples) +endif() +if (BUILD_TEST) + enable_testing() + add_subdirectory(tests) +endif() +if (BENCHMARK) + add_subdirectory(benchmarks) +endif() +include(cmake/Install.cmake) diff --git a/appveyor.yml b/appveyor.yml index 8ebdf2b..44011cd 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -43,7 +43,7 @@ build_script: $env:CMAKE_GENERATOR_NAME="Visual Studio 14 2015 Win64" $env:BOOST_LIBRARYDIR=$env:BOOST_LIBRARYDIR_WIN64 } - - cmd: cmake -G "%CMAKE_GENERATOR_NAME%" -DCMAKE_BUILD_TYPE=%configuration% -DBOOST_ROOT="%BOOST_ROOT%" -DBOOST_LIBRARYDIR="%BOOST_LIBRARYDIR%" -DBoost_USE_STATIC_LIBS="ON" .. + - cmd: cmake -G "%CMAKE_GENERATOR_NAME%" -DCMAKE_BUILD_TYPE=%configuration% -DBOOST_ROOT="%BOOST_ROOT%" -DBOOST_LIBRARYDIR="%BOOST_LIBRARYDIR%" -DBoost_USE_STATIC_LIBS="ON" -DBUILD_SHARED_LIBS=OFF .. - cmd: cmake --build . -- /verbosity:detailed #test_script: diff --git a/benchmarks/CMakeLists.txt b/benchmarks/CMakeLists.txt index 930a733..9a3f083 100644 --- a/benchmarks/CMakeLists.txt +++ b/benchmarks/CMakeLists.txt @@ -1,47 +1,13 @@ - -SET(REDISCLIENT_SOURCES - ${CMAKE_CURRENT_SOURCE_DIR}/../src/redisclient/impl/redisvalue.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/../src/redisclient/impl/redissyncclient.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/../src/redisclient/impl/redisparser.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/../src/redisclient/impl/redisclientimpl.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/../src/redisclient/impl/redisasyncclient.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/../src/redisclient/config.h - ${CMAKE_CURRENT_SOURCE_DIR}/../src/redisclient/version.h - ${CMAKE_CURRENT_SOURCE_DIR}/../src/redisclient/redisvalue.h - ${CMAKE_CURRENT_SOURCE_DIR}/../src/redisclient/redissyncclient.h - ${CMAKE_CURRENT_SOURCE_DIR}/../src/redisclient/redisparser.h - ${CMAKE_CURRENT_SOURCE_DIR}/../src/redisclient/redisbuffer.h - ${CMAKE_CURRENT_SOURCE_DIR}/../src/redisclient/redisasyncclient.h - ${CMAKE_CURRENT_SOURCE_DIR}/../src/redisclient/impl/redisclientimpl.h -) - -INCLUDE_DIRECTORIES( - ${Boost_INCLUDE_DIRS} - ${CMAKE_SOURCE_DIR}/src/ -) - -SET(BENCHMARKS +set(BENCHMARKS redis-parser-benchmark.cpp ) -FOREACH(FILE ${REDISCLIENT_SOURCES}) - SET_SOURCE_FILES_PROPERTIES(${FILE} PROPERTIES HEADER_FILE_ONLY TRUE) -ENDFOREACH() - -FOREACH(BENCHMARK ${BENCHMARKS}) - GET_FILENAME_COMPONENT(EXECUTABLE ${BENCHMARK} NAME_WE) - ADD_EXECUTABLE(${EXECUTABLE} ${BENCHMARK} ${REDISCLIENT_SOURCES}) - TARGET_LINK_LIBRARIES(${EXECUTABLE} - ${Boost_SYSTEM_LIBRARY} -# ${Boost_DATE_TIME_LIBRARY} -# ${Boost_TIMER_LIBRARY} - -lbenchmark - -lprofiler - ) -ENDFOREACH(BENCHMARK) - -#TARGET_LINK_LIBRARIES(benchmark -# ${Boost_PROGRAM_OPTIONS_LIBRARY} -# ${Boost_DATE_TIME_LIBRARY} -#) - +foreach(BENCHMARK ${BENCHMARKS}) + get_filename_component(EXECUTABLE ${BENCHMARK} NAME_WE) + add_executable(${EXECUTABLE} ${BENCHMARK}) + target_link_libraries(${EXECUTABLE} + RedisClient + -lbenchmark + -lprofiler + ) +endforeach() diff --git a/cmake/Dependencies.cmake b/cmake/Dependencies.cmake new file mode 100644 index 0000000..20bb5bb --- /dev/null +++ b/cmake/Dependencies.cmake @@ -0,0 +1,21 @@ +# CMake script for finding dependencies. This file is included two times, once +# by the main CMake script for the project, for finding dependencies at build +# time, and once by the package's installed config script, for finding public +# dependencies. A variable, called ${CMAKE_PROJECT_NAME}Install is defined by +# the installed config script and can be used by this script to differentiate +# between the two cases + +# Find Boost, users of the library only need system (for error_code), our +# examples use the other components +set(boost_components system) +if (NOT RedisClientInstall) + set(boost_components ${boost_components} + program_options + unit_test_framework + date_time) +endif() + +find_package(Boost + COMPONENTS + ${boost_components} + REQUIRED) diff --git a/cmake/Install.cmake b/cmake/Install.cmake new file mode 100644 index 0000000..777c543 --- /dev/null +++ b/cmake/Install.cmake @@ -0,0 +1,28 @@ +set(INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/include) +set(LIB_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/${INSTALL_LIB_DIR}) + +include(CMakePackageConfigHelpers) + +configure_package_config_file(cmake/config/Config.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}Config.cmake + INSTALL_DESTINATION share/${CMAKE_PROJECT_NAME} + PATH_VARS INCLUDE_INSTALL_DIR LIB_INSTALL_DIR) + +write_basic_package_version_file( + ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}ConfigVersion.cmake + VERSION ${VERSION} + COMPATIBILITY AnyNewerVersion) + +install(EXPORT ${CMAKE_PROJECT_NAME}-targets + FILE ${CMAKE_PROJECT_NAME}Targets.cmake + NAMESPACE ${CMAKE_PROJECT_NAME}:: + DESTINATION share/${CMAKE_PROJECT_NAME}) + +install(FILES + ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}Config.cmake + ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}ConfigVersion.cmake + DESTINATION share/${CMAKE_PROJECT_NAME}) + +install(FILES ${CMAKE_SOURCE_DIR}/cmake/Dependencies.cmake + RENAME ${CMAKE_PROJECT_NAME}Dependencies.cmake + DESTINATION share/${CMAKE_PROJECT_NAME}) diff --git a/cmake/Utils.cmake b/cmake/Utils.cmake new file mode 100644 index 0000000..59e4541 --- /dev/null +++ b/cmake/Utils.cmake @@ -0,0 +1,146 @@ +# Gets the install path for libraries +function(GetInstallLibDir output) + get_property(LIB64 GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS) + if ("${LIB64}" STREQUAL "TRUE") + set(LIBSUFFIX 64) + else() + set(LIBSUFFIX "") + endif() + set(${output} lib${LIBSUFFIX} PARENT_SCOPE) +endfunction() + +# Function for installing headers +# +# Arguments: +# HEADERS The headers to install +function(RedisClientInstallHeaders) + set(options) + set(oneValueArgs) + set(multiValueArgs HEADERS) + cmake_parse_arguments(RedisClientInstallHeaders + "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + + # Install the headers (and sources because of the header-only mode) + file(RELATIVE_PATH module_path ${CMAKE_SOURCE_DIR}/src + ${CMAKE_CURRENT_SOURCE_DIR}) + foreach (HDR ${RedisClientInstallHeaders_HEADERS}) + get_filename_component(path_within_module ${HDR} DIRECTORY) + if (path_within_module STREQUAL "") + install(FILES ${HDR} + COMPONENT Development + DESTINATION include/${module_path}) + else() + install(FILES ${HDR} + COMPONENT Development + DESTINATION include/${module_path}/${path_within_module}) + endif() + endforeach() +endfunction() + +# Function for adding a RedisClient library to the build process +# +# Arguments: +# LIB_NAME Name for the library +# SOURCES Named parameter for the source files that go into the library +# HEADERS Named parameter for the headers that go into the library +# WITH_INSTALL Whether this is a library that should be installed +function(RedisClientLibrary LIB_NAME) + set(options WITH_INSTALL) + set(oneValueArgs) + set(multiValueArgs SOURCES HEADERS) + cmake_parse_arguments(RedisClientLibrary "${options}" "${oneValueArgs}" + "${multiValueArgs}" ${ARGN}) + + if (NOT DEFINED LIB_NAME) + message(FATAL_ERROR "RedisClientLibrary(): LIB_NAME not defined") + endif() + + add_library(${LIB_NAME} ${RedisClientLibrary_SOURCES} + ${RedisClientLibrary_HEADERS}) + target_include_directories(${LIB_NAME} PUBLIC + $ + $ + ) + + if (BUILD_SHARED_LIBS) + set_target_properties(${LIB_NAME} PROPERTIES + VERSION ${VERSION} + SOVERSION ${VERSION_MAJOR}.${VERSION_MINOR}) + target_link_libraries(${LIB_NAME} PRIVATE ${CMAKE_DL_LIBS}) + endif() + + # Define install for the library + if (RedisClientLibrary_WITH_INSTALL) + # Install the library + GetInstallLibDir(INSTALL_LIB_DIR) + install(TARGETS ${LIB_NAME} + EXPORT ${CMAKE_PROJECT_NAME}-targets + COMPONENT Libraries + DESTINATION ${INSTALL_LIB_DIR} + LIBRARY NAMELINK_SKIP) + if (BUILD_SHARED_LIBS) + install(TARGETS ${LIB_NAME} + EXPORT ${CMAKE_PROJECT_NAME}-targets LIBRARY + DESTINATION ${INSTALL_LIB_DIR} + COMPONENT Development + NAMELINK_ONLY) + endif() + + # Install the headers (and sources because of the header-only mode) + RedisClientInstallHeaders(HEADERS ${RedisClientLibrary_HEADERS}) + endif() +endfunction() + +# Function for adding a header-only RedisClient library to the build process +# +# Arguments: +# LIB_NAME Name for the library +# SOURCES Named parameter for the source files that go into the library +# HEADERS Named parameter for the headers that go into the library +# WITH_INSTALL Whether this is a library that should be installed +function(RedisClientHeaderLibrary LIB_NAME) + set(options WITH_INSTALL) + set(oneValueArgs) + set(multiValueArgs HEADERS) + cmake_parse_arguments(RedisClientHeaderLibrary "${options}" "${oneValueArgs}" + "${multiValueArgs}" ${ARGN}) + + if (NOT DEFINED LIB_NAME) + message(FATAL_ERROR "RedisClientHeaderLibrary(): LIB_NAME not defined") + endif() + + add_library(${LIB_NAME} INTERFACE) + target_include_directories(${LIB_NAME} INTERFACE + $ + $ + ) + + if (RedisClientHeaderLibrary_WITH_INSTALL) + install(TARGETS ${LIB_NAME} + EXPORT ${CMAKE_PROJECT_NAME}-targets + COMPONENT Libraries) + RedisClientInstallHeaders(HEADERS ${RedisClientHeaderLibrary_HEADERS}) + endif() +endfunction() + +# Adds a test for the RedisClientLibrary +# +# Arguments: +# TEST_NAME Name of the test executable +# SOURCES List of source files to compile into the test +# DEPENDENCIES Dependencies (other than RedisClient and the boost unit testing +# framework) to link into the test +function(RedisClientTest TEST_NAME) + set(options) + set(oneValueArgs SHEET) + set(multiValueArgs SOURCES DEPENDENCIES) + cmake_parse_arguments(RedisClientTest "${options}" "${oneValueArgs}" + "${multiValueArgs}" ${ARGN}) + + add_executable(${TEST_NAME} ${RedisClientTest_SOURCES}) + + target_include_directories(${TEST_NAME} PUBLIC ${BOOST_INCLUDE_DIRS}) + target_link_libraries(${TEST_NAME} RedisClient ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) + + add_test(NAME ${TEST_NAME} COMMAND ${TEST_NAME}) +endfunction() diff --git a/cmake/config/Config.cmake.in b/cmake/config/Config.cmake.in new file mode 100644 index 0000000..366ef90 --- /dev/null +++ b/cmake/config/Config.cmake.in @@ -0,0 +1,33 @@ +# Config file for the @CMAKE_PROJECT_NAME@ package +# +# Usage from an external project: +# In your CMakeLists.txt, add these lines: +# +# find_package(@CMAKE_PROJECT_NAME@ REQUIRED) +# include_directories(${@CMAKE_PROJECT_NAME@_INCLUDE_DIRS}) +# link_directories(${@CMAKE_PROJECT_NAME@_LIBRARY_DIRS}) +# target_link_libraries(MY_TARGET_NAME ${@CMAKE_PROJECT_NAME@_LIBRARIES}) +# +# This file defines the following variables +# -@CMAKE_PROJECT_NAME@_INCLUDE_DIRS :Include directories for @CMAKE_PROJECT_NAME@ +# -@CMAKE_PROJECT_NAME@_LIBRARIES :Libraries to link against +# -@CMAKE_PROJECT_NAME@_LIBRARY_DIRS :Directories to add for libraries +# -@CMAKE_PROJECT_NAME@_FOUND :Found status + +set(@CMAKE_PROJECT_NAME@Install ON) +include(${CMAKE_CURRENT_LIST_DIR}/@CMAKE_PROJECT_NAME@Dependencies.cmake) + +# Our library dependencies (contains definitions for IMPORTED targets) +include(${CMAKE_CURRENT_LIST_DIR}/@CMAKE_PROJECT_NAME@Targets.cmake) + +@PACKAGE_INIT@ + +set_and_check(@CMAKE_PROJECT_NAME@_INCLUDE_DIRS "@PACKAGE_INCLUDE_INSTALL_DIR@") +set_and_check(@CMAKE_PROJECT_NAME@_LIB_DIR "@PACKAGE_LIB_INSTALL_DIR@") +check_required_components(@CMAKE_PROJECT_NAME@) + +# Set found status +set(@CMAKE_PROJECT_NAME@_FOUND TRUE) +set(@CMAKE_PROJECT_NAME@_INCLUDE_DIRS ${@CMAKE_PROJECT_NAME@_INCLUDE_DIRS} ${INCLUDE_DIRS}) +set(@CMAKE_PROJECT_NAME@_LIBRARY_DIRS ${@CMAKE_PROJECT_NAME@_LIB_DIR} ${LIBRARY_DIRS}) +set(@CMAKE_PROJECT_NAME@_LIBRARIES ${@CMAKE_PROJECT_NAME@_LIBS_LIST}) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index cf9d112..3f54b12 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,49 +1,22 @@ - -SET(REDISCLIENT_SOURCES - ${CMAKE_CURRENT_SOURCE_DIR}/../src/redisclient/impl/redisvalue.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/../src/redisclient/impl/redissyncclient.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/../src/redisclient/impl/redisparser.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/../src/redisclient/impl/redisclientimpl.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/../src/redisclient/impl/redisasyncclient.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/../src/redisclient/impl/pipeline.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/../src/redisclient/config.h - ${CMAKE_CURRENT_SOURCE_DIR}/../src/redisclient/version.h - ${CMAKE_CURRENT_SOURCE_DIR}/../src/redisclient/redisvalue.h - ${CMAKE_CURRENT_SOURCE_DIR}/../src/redisclient/redissyncclient.h - ${CMAKE_CURRENT_SOURCE_DIR}/../src/redisclient/redisparser.h - ${CMAKE_CURRENT_SOURCE_DIR}/../src/redisclient/redisbuffer.h - ${CMAKE_CURRENT_SOURCE_DIR}/../src/redisclient/redisasyncclient.h - ${CMAKE_CURRENT_SOURCE_DIR}/../src/redisclient/pipeline.h - ${CMAKE_CURRENT_SOURCE_DIR}/../src/redisclient/impl/redisclientimpl.h -) - -INCLUDE_DIRECTORIES( - ${Boost_INCLUDE_DIRS} - ${CMAKE_SOURCE_DIR}/src/ -) - -SET(EXAMPLES +set(EXAMPLES async_pubsub2.cpp async_pubsub.cpp async_set_get2.cpp async_set_get.cpp - sync_set_get.cpp sync_pipeline.cpp + sync_set_get.cpp benchmark.cpp ) -FOREACH(FILE ${REDISCLIENT_SOURCES}) - SET_SOURCE_FILES_PROPERTIES(${FILE} PROPERTIES HEADER_FILE_ONLY TRUE) -ENDFOREACH() +foreach(EXAMPLE ${EXAMPLES}) + get_filename_component(EXECUTABLE ${EXAMPLE} NAME_WE) + add_executable(${EXECUTABLE} ${EXAMPLE}) + target_link_libraries(${EXECUTABLE} + RedisClient + ${Boost_DATE_TIME_LIBRARY}) +endforeach() -FOREACH(EXAMPLE ${EXAMPLES}) - GET_FILENAME_COMPONENT(EXECUTABLE ${EXAMPLE} NAME_WE) - ADD_EXECUTABLE(${EXECUTABLE} ${EXAMPLE} ${REDISCLIENT_SOURCES}) - TARGET_LINK_LIBRARIES(${EXECUTABLE} ${Boost_SYSTEM_LIBRARY} ${Boost_DATE_TIME_LIBRARY}) -ENDFOREACH(EXAMPLE) - -TARGET_LINK_LIBRARIES(benchmark +target_link_libraries(benchmark + RedisClient ${Boost_PROGRAM_OPTIONS_LIBRARY} - ${Boost_DATE_TIME_LIBRARY} ) - diff --git a/examples/sync_pipeline.cpp b/examples/sync_pipeline.cpp index 982d337..d592d74 100644 --- a/examples/sync_pipeline.cpp +++ b/examples/sync_pipeline.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include int main(int, char **) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..af85b2e --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(redisclient) diff --git a/src/redisclient/CMakeLists.txt b/src/redisclient/CMakeLists.txt new file mode 100644 index 0000000..0f9b348 --- /dev/null +++ b/src/redisclient/CMakeLists.txt @@ -0,0 +1,46 @@ +set(hdrs config.h + pipeline.h + redisasyncclient.h + redisbuffer.h + redisparser.h + redissyncclient.h + redisvalue.h + version.h + impl/redisclientimpl.h) +set(srcs impl/pipeline.cpp + impl/redisasyncclient.cpp + impl/redisclientimpl.cpp + impl/redisparser.cpp + impl/redissyncclient.cpp + impl/redisvalue.cpp) + +if (HEADER_ONLY) + RedisClientHeaderLibrary(RedisClient HEADERS ${hdrs} ${srcs} WITH_INSTALL) + target_compile_definitions(RedisClient + INTERFACE + REDIS_CLIENT_HEADER_ONLY + ) + target_include_directories(RedisClient + INTERFACE + ${Boost_INCLUDE_DIRS} + ) + target_link_libraries(RedisClient + INTERFACE + ${Boost_SYSTEM_LIBRARY} + ) +else() + RedisClientLibrary(RedisClient SOURCES ${srcs} HEADERS ${hdrs} WITH_INSTALL) + target_compile_definitions(RedisClient + PUBLIC + REDIS_CLIENT_SEPARATED_COMPILATION + ) + target_include_directories(RedisClient + PUBLIC + ${Boost_INCLUDE_DIRS} + ) + target_link_libraries(RedisClient + PUBLIC + ${Boost_SYSTEM_LIBRARY} + ) +endif() + diff --git a/src/redisclient/impl/pipeline.cpp b/src/redisclient/impl/pipeline.cpp index f925f24..4e531e9 100644 --- a/src/redisclient/impl/pipeline.cpp +++ b/src/redisclient/impl/pipeline.cpp @@ -6,9 +6,9 @@ #ifndef REDISCLIENT_PIPELINE_CPP #define REDISCLIENT_PIPELINE_CPP -#include "../pipeline.h" -#include "../redisvalue.h" -#include "../redissyncclient.h" +#include "redisclient/pipeline.h" +#include "redisclient/redisvalue.h" +#include "redisclient/redissyncclient.h" namespace redisclient { diff --git a/src/redisclient/impl/redisasyncclient.cpp b/src/redisclient/impl/redisasyncclient.cpp index d07af52..fbb451a 100644 --- a/src/redisclient/impl/redisasyncclient.cpp +++ b/src/redisclient/impl/redisasyncclient.cpp @@ -9,7 +9,7 @@ #include #include -#include "../redisasyncclient.h" +#include "redisclient/redisasyncclient.h" namespace redisclient { diff --git a/src/redisclient/impl/redisclientimpl.h b/src/redisclient/impl/redisclientimpl.h index cb57b88..f2435dc 100644 --- a/src/redisclient/impl/redisclientimpl.h +++ b/src/redisclient/impl/redisclientimpl.h @@ -20,9 +20,9 @@ #include #include -#include "../redisparser.h" -#include "../redisbuffer.h" -#include "../config.h" +#include "redisclient/redisparser.h" +#include "redisclient/redisbuffer.h" +#include "redisclient/config.h" namespace redisclient { diff --git a/src/redisclient/impl/redisparser.cpp b/src/redisclient/impl/redisparser.cpp index a49e9a3..3b3cf29 100644 --- a/src/redisclient/impl/redisparser.cpp +++ b/src/redisclient/impl/redisparser.cpp @@ -9,7 +9,7 @@ #include #include -#include "../redisparser.h" +#include "redisclient/redisparser.h" namespace redisclient { diff --git a/src/redisclient/impl/redissyncclient.cpp b/src/redisclient/impl/redissyncclient.cpp index 1146dc5..fa4c501 100644 --- a/src/redisclient/impl/redissyncclient.cpp +++ b/src/redisclient/impl/redissyncclient.cpp @@ -9,8 +9,8 @@ #include #include -#include "../redissyncclient.h" -#include "../pipeline.h" +#include "redisclient/redissyncclient.h" +#include "redisclient/pipeline.h" namespace redisclient { diff --git a/src/redisclient/impl/redisvalue.cpp b/src/redisclient/impl/redisvalue.cpp index 861b9f0..3e8fe0c 100644 --- a/src/redisclient/impl/redisvalue.cpp +++ b/src/redisclient/impl/redisvalue.cpp @@ -8,7 +8,7 @@ #include -#include "../redisvalue.h" +#include "redisclient/redisvalue.h" namespace redisclient { diff --git a/src/redisclient/pipeline.h b/src/redisclient/pipeline.h index 5f57ff1..6f6a16d 100644 --- a/src/redisclient/pipeline.h +++ b/src/redisclient/pipeline.h @@ -51,6 +51,6 @@ class Pipeline } #ifdef REDIS_CLIENT_HEADER_ONLY -#include "impl/pipeline.cpp" +#include "redisclient/impl/pipeline.cpp" #endif diff --git a/src/redisclient/redisasyncclient.h b/src/redisclient/redisasyncclient.h index 7607f73..11c1f30 100644 --- a/src/redisclient/redisasyncclient.h +++ b/src/redisclient/redisasyncclient.h @@ -14,7 +14,7 @@ #include #include -#include "impl/redisclientimpl.h" +#include "redisclient/impl/redisclientimpl.h" #include "redisvalue.h" #include "redisbuffer.h" #include "config.h" @@ -135,7 +135,7 @@ class RedisAsyncClient : boost::noncopyable { } #ifdef REDIS_CLIENT_HEADER_ONLY -#include "impl/redisasyncclient.cpp" +#include "redisclient/impl/redisasyncclient.cpp" #endif #endif // REDISASYNCCLIENT_REDISCLIENT_H diff --git a/src/redisclient/redisparser.h b/src/redisclient/redisparser.h index 1212ecf..40841fa 100644 --- a/src/redisclient/redisparser.h +++ b/src/redisclient/redisparser.h @@ -89,7 +89,7 @@ class RedisParser } #ifdef REDIS_CLIENT_HEADER_ONLY -#include "impl/redisparser.cpp" +#include "redisclient/impl/redisparser.cpp" #endif #endif // REDISCLIENT_REDISPARSER_H diff --git a/src/redisclient/redissyncclient.h b/src/redisclient/redissyncclient.h index 5fe654d..7f5368d 100644 --- a/src/redisclient/redissyncclient.h +++ b/src/redisclient/redissyncclient.h @@ -13,7 +13,7 @@ #include #include -#include "impl/redisclientimpl.h" +#include "redisclient/impl/redisclientimpl.h" #include "redisbuffer.h" #include "redisvalue.h" #include "config.h" @@ -74,7 +74,7 @@ class RedisSyncClient : boost::noncopyable { } #ifdef REDIS_CLIENT_HEADER_ONLY -#include "impl/redissyncclient.cpp" +#include "redisclient/impl/redissyncclient.cpp" #endif #endif // REDISSYNCCLIENT_REDISCLIENT_H diff --git a/src/redisclient/redisvalue.h b/src/redisclient/redisvalue.h index 1d0d633..6e58a22 100644 --- a/src/redisclient/redisvalue.h +++ b/src/redisclient/redisvalue.h @@ -114,7 +114,7 @@ bool RedisValue::typeEq() const } #ifdef REDIS_CLIENT_HEADER_ONLY -#include "impl/redisvalue.cpp" +#include "redisclient/impl/redisvalue.cpp" #endif #endif // REDISCLIENT_REDISVALUE_H diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000..1b64b31 --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,2 @@ +RedisClientTest(ParserTest SOURCES parsertest.cpp) +RedisClientTest(RedisValueTest SOURCES redisvaluetest.cpp)