-
Notifications
You must be signed in to change notification settings - Fork 351
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrite CMakeLists.txt with modern cmake (#188)
- Loading branch information
Showing
5 changed files
with
221 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,130 +1,210 @@ | ||
if (APPLE) | ||
cmake_minimum_required(VERSION 3.0.0) | ||
else() | ||
cmake_minimum_required(VERSION 2.8.0) | ||
endif() | ||
|
||
set(REDIS_PLUS_PLUS_VERSION "1.2.1") | ||
cmake_minimum_required(VERSION 3.1) | ||
|
||
set(REDIS_PLUS_PLUS_VERSION "1.2.3") | ||
message(STATUS "redis-plus-plus version: ${REDIS_PLUS_PLUS_VERSION}") | ||
|
||
if (${CMAKE_VERSION} VERSION_LESS "3.0.0") | ||
project(redis++) | ||
else() | ||
cmake_policy(SET CMP0048 NEW) | ||
project(redis++ VERSION ${REDIS_PLUS_PLUS_VERSION}) | ||
endif() | ||
project(redis++ LANGUAGES CXX VERSION ${REDIS_PLUS_PLUS_VERSION}) | ||
|
||
if (NOT DEFINED REDIS_PLUS_PLUS_CXX_STANDARD) | ||
set(REDIS_PLUS_PLUS_CXX_STANDARD 11) | ||
set(REDIS_PLUS_PLUS_DEFAULT_BUILD_TYPE "Release") | ||
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) | ||
set(CMAKE_BUILD_TYPE ${REDIS_PLUS_PLUS_DEFAULT_BUILD_TYPE} CACHE STRING "Set build type" FORCE) | ||
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "RelWithDebInfo" "MinSizeRel") | ||
endif() | ||
message(STATUS "redis-plus-plus build type: ${CMAKE_BUILD_TYPE}") | ||
|
||
message(STATUS "The CXX standard is c++${REDIS_PLUS_PLUS_CXX_STANDARD}") | ||
|
||
if (NOT WIN32) | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++${REDIS_PLUS_PLUS_CXX_STANDARD} -Wall -W -Werror") | ||
set(REDIS_PLUS_PLUS_DEFAULT_CXX_STANDARD 11) | ||
if(NOT REDIS_PLUS_PLUS_CXX_STANDARD) | ||
set(REDIS_PLUS_PLUS_CXX_STANDARD ${REDIS_PLUS_PLUS_DEFAULT_CXX_STANDARD} CACHE STRING "Set CXX standard" FORCE) | ||
set_property(CACHE REDIS_PLUS_PLUS_CXX_STANDARD PROPERTY STRINGS "11" "14" "17" "20") | ||
endif() | ||
message(STATUS "redis-plus-plus build with CXX standard: c++${REDIS_PLUS_PLUS_CXX_STANDARD}") | ||
|
||
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) | ||
|
||
set(PROJECT_SOURCE_DIR ${PROJECT_SOURCE_DIR}/src/sw/redis++) | ||
if(NOT WIN32) | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++${REDIS_PLUS_PLUS_CXX_STANDARD}") | ||
endif() | ||
|
||
file(GLOB PROJECT_SOURCE_FILES "${PROJECT_SOURCE_DIR}/*.cpp") | ||
set(REDIS_PLUS_PLUS_SOURCE_DIR src/sw/redis++) | ||
|
||
set(REDIS_PLUS_PLUS_SOURCES | ||
"${REDIS_PLUS_PLUS_SOURCE_DIR}/command.cpp" | ||
"${REDIS_PLUS_PLUS_SOURCE_DIR}/command_options.cpp" | ||
"${REDIS_PLUS_PLUS_SOURCE_DIR}/connection.cpp" | ||
"${REDIS_PLUS_PLUS_SOURCE_DIR}/connection_pool.cpp" | ||
"${REDIS_PLUS_PLUS_SOURCE_DIR}/crc16.cpp" | ||
"${REDIS_PLUS_PLUS_SOURCE_DIR}/errors.cpp" | ||
"${REDIS_PLUS_PLUS_SOURCE_DIR}/pipeline.cpp" | ||
"${REDIS_PLUS_PLUS_SOURCE_DIR}/redis.cpp" | ||
"${REDIS_PLUS_PLUS_SOURCE_DIR}/redis_cluster.cpp" | ||
"${REDIS_PLUS_PLUS_SOURCE_DIR}/reply.cpp" | ||
"${REDIS_PLUS_PLUS_SOURCE_DIR}/sentinel.cpp" | ||
"${REDIS_PLUS_PLUS_SOURCE_DIR}/shards.cpp" | ||
"${REDIS_PLUS_PLUS_SOURCE_DIR}/shards_pool.cpp" | ||
"${REDIS_PLUS_PLUS_SOURCE_DIR}/subscriber.cpp" | ||
"${REDIS_PLUS_PLUS_SOURCE_DIR}/transaction.cpp" | ||
) | ||
|
||
# TLS support | ||
option(REDIS_PLUS_PLUS_USE_TLS "Build with TLS support" OFF) | ||
message(STATUS "redis-plus-plus TLS support: ${REDIS_PLUS_PLUS_USE_TLS}") | ||
|
||
if(REDIS_PLUS_PLUS_USE_TLS) | ||
set(TLS_SUB_DIR "${REDIS_PLUS_PLUS_SOURCE_DIR}/tls") | ||
|
||
if (REDIS_PLUS_PLUS_USE_TLS) | ||
message(STATUS "Build with TLS support") | ||
list(APPEND REDIS_PLUS_PLUS_SOURCES "${TLS_SUB_DIR}/tls.cpp") | ||
|
||
set(TLS_SUB_DIR "${PROJECT_SOURCE_DIR}/tls") | ||
set(REDIS_PLUS_PLUS_DEPENDS "hiredis,hiredis_ssl") | ||
else() | ||
set(TLS_SUB_DIR "${PROJECT_SOURCE_DIR}/no_tls") | ||
endif() | ||
set(TLS_SUB_DIR "${REDIS_PLUS_PLUS_SOURCE_DIR}/no_tls") | ||
|
||
file(GLOB TLS_SOURCE_FILES "${TLS_SUB_DIR}/*.cpp") | ||
set(REDIS_PLUS_PLUS_DEPENDS "hiredis") | ||
endif() | ||
|
||
# hiredis dependency | ||
find_path(HIREDIS_HEADER hiredis) | ||
find_library(HIREDIS_LIB hiredis) | ||
find_package(hiredis QUIET) | ||
if(hiredis_FOUND) | ||
list(APPEND REDIS_PLUS_PLUS_HIREDIS_LIBS hiredis::hiredis) | ||
|
||
if(REDIS_PLUS_PLUS_USE_TLS) | ||
find_package(hiredis_ssl REQUIRED) | ||
list(APPEND REDIS_PLUS_PLUS_HIREDIS_LIBS hiredis::hiredis_ssl) | ||
endif() | ||
else() | ||
find_path(HIREDIS_HEADER hiredis REQUIRED) | ||
find_library(HIREDIS_LIB hiredis REQUIRED) | ||
list(APPEND REDIS_PLUS_PLUS_HIREDIS_LIBS ${HIREDIS_LIB}) | ||
|
||
if(REDIS_PLUS_PLUS_USE_TLS) | ||
find_library(HIREDIS_TLS_LIB hiredis_ssl REQUIRED) | ||
list(APPEND REDIS_PLUS_PLUS_HIREDIS_LIBS ${HIREDIS_TLS_LIB}) | ||
endif() | ||
endif() | ||
|
||
# Build static library | ||
option(REDIS_PLUS_PLUS_BUILD_STATIC "Build static library" ON) | ||
message(STATUS "redis-plus-plus build static library: ${REDIS_PLUS_PLUS_BUILD_STATIC}") | ||
|
||
if(REDIS_PLUS_PLUS_BUILD_STATIC) | ||
set(STATIC_LIB redis++_static) | ||
|
||
if (REDIS_PLUS_PLUS_BUILD_STATIC) | ||
set(STATIC_LIB redis-plus-plus-static) | ||
add_library(${STATIC_LIB} STATIC ${REDIS_PLUS_PLUS_SOURCES}) | ||
|
||
add_library(${STATIC_LIB} STATIC ${PROJECT_SOURCE_FILES} ${TLS_SOURCE_FILES}) | ||
list(APPEND REDIS_PLUS_PLUS_TARGETS ${STATIC_LIB}) | ||
|
||
target_include_directories(${STATIC_LIB} PUBLIC ${PROJECT_SOURCE_DIR} ${TLS_SUB_DIR}) | ||
target_include_directories(${STATIC_LIB} PUBLIC ${HIREDIS_HEADER}) | ||
target_include_directories(${STATIC_LIB} PUBLIC | ||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/${REDIS_PLUS_PLUS_SOURCE_DIR}> | ||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/${TLS_SUB_DIR}> | ||
$<INSTALL_INTERFACE:include>) | ||
|
||
if(hiredis_FOUND) | ||
target_link_libraries(${STATIC_LIB} PUBLIC ${REDIS_PLUS_PLUS_HIREDIS_LIBS}) | ||
else() | ||
target_include_directories(${STATIC_LIB} PUBLIC $<BUILD_INTERFACE:${HIREDIS_HEADER}>) | ||
endif() | ||
|
||
if (WIN32) | ||
target_compile_definitions(${STATIC_LIB} PRIVATE NOMINMAX) | ||
set_target_properties(${STATIC_LIB} PROPERTIES CXX_STANDARD ${REDIS_PLUS_PLUS_CXX_STANDARD} CXX_EXTENSIONS OFF) | ||
set_target_properties(${STATIC_LIB} PROPERTIES OUTPUT_NAME ${PROJECT_NAME}_static) | ||
set_target_properties(${STATIC_LIB} PROPERTIES CXX_STANDARD ${REDIS_PLUS_PLUS_CXX_STANDARD}) | ||
set_target_properties(${STATIC_LIB} PROPERTIES OUTPUT_NAME redis++_static) | ||
else() | ||
set_target_properties(${STATIC_LIB} PROPERTIES OUTPUT_NAME ${PROJECT_NAME}) | ||
target_compile_options(${STATIC_LIB} PRIVATE "-Wall" "-W" "-Werror") | ||
set_target_properties(${STATIC_LIB} PROPERTIES OUTPUT_NAME redis++) | ||
endif() | ||
|
||
set_target_properties(${STATIC_LIB} PROPERTIES CLEAN_DIRECT_OUTPUT 1) | ||
set_target_properties(${STATIC_LIB} PROPERTIES POSITION_INDEPENDENT_CODE ON) | ||
set_target_properties(${STATIC_LIB} PROPERTIES CXX_EXTENSIONS OFF) | ||
|
||
option(REDIS_PLUS_PLUS_BUILD_STATIC_WITH_PIC "Build static library with position independent code" ON) | ||
message(STATUS "redis-plus-plus build static library with position independent code: ${REDIS_PLUS_PLUS_BUILD_STATIC_WITH_PIC}") | ||
|
||
if(REDIS_PLUS_PLUS_BUILD_STATIC_WITH_PIC) | ||
set_target_properties(${STATIC_LIB} PROPERTIES POSITION_INDEPENDENT_CODE ON) | ||
endif() | ||
endif() | ||
|
||
# Build shared library | ||
option(REDIS_PLUS_PLUS_BUILD_SHARED "Build shared library" ON) | ||
message(STATUS "redis-plus-plus build shared library: ${REDIS_PLUS_PLUS_BUILD_SHARED}") | ||
|
||
if (REDIS_PLUS_PLUS_BUILD_SHARED) | ||
set(SHARED_LIB redis-plus-plus-shared) | ||
if(REDIS_PLUS_PLUS_BUILD_SHARED) | ||
set(SHARED_LIB redis++) | ||
|
||
add_library(${SHARED_LIB} SHARED ${PROJECT_SOURCE_FILES} ${TLS_SOURCE_FILES}) | ||
add_library(${SHARED_LIB} SHARED ${REDIS_PLUS_PLUS_SOURCES}) | ||
|
||
target_include_directories(${SHARED_LIB} PUBLIC ${PROJECT_SOURCE_DIR} ${TLS_SUB_DIR}) | ||
target_include_directories(${SHARED_LIB} PUBLIC ${HIREDIS_HEADER}) | ||
list(APPEND REDIS_PLUS_PLUS_TARGETS ${SHARED_LIB}) | ||
|
||
if (WIN32) | ||
target_compile_definitions(${SHARED_LIB} PRIVATE NOMINMAX) | ||
set_target_properties(${SHARED_LIB} PROPERTIES CXX_STANDARD ${REDIS_PLUS_PLUS_CXX_STANDARD} CXX_EXTENSIONS OFF) | ||
set_target_properties(${SHARED_LIB} PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS TRUE) | ||
endif() | ||
target_include_directories(${SHARED_LIB} PUBLIC | ||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/${REDIS_PLUS_PLUS_SOURCE_DIR}> | ||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/${TLS_SUB_DIR}> | ||
$<INSTALL_INTERFACE:include>) | ||
|
||
target_link_libraries(${SHARED_LIB} ${HIREDIS_LIB}) | ||
if(hiredis_FOUND) | ||
target_link_libraries(${SHARED_LIB} PUBLIC ${REDIS_PLUS_PLUS_HIREDIS_LIBS}) | ||
else() | ||
target_include_directories(${SHARED_LIB} PUBLIC $<BUILD_INTERFACE:${HIREDIS_HEADER}>) | ||
target_link_libraries(${SHARED_LIB} PUBLIC ${REDIS_PLUS_PLUS_HIREDIS_LIBS}) | ||
endif() | ||
|
||
if (REDIS_PLUS_PLUS_USE_TLS) | ||
find_library(HIREDIS_TLS_LIB hiredis_ssl) | ||
target_link_libraries(${SHARED_LIB} ${HIREDIS_TLS_LIB}) | ||
if(WIN32) | ||
target_compile_definitions(${SHARED_LIB} PRIVATE NOMINMAX) | ||
set_target_properties(${SHARED_LIB} PROPERTIES CXX_STANDARD ${REDIS_PLUS_PLUS_CXX_STANDARD}) | ||
set_target_properties(${SHARED_LIB} PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS TRUE) | ||
else() | ||
target_compile_options(${SHARED_LIB} PRIVATE "-Wall" "-W" "-Werror") | ||
endif() | ||
|
||
set_target_properties(${SHARED_LIB} PROPERTIES OUTPUT_NAME ${PROJECT_NAME}) | ||
set_target_properties(${SHARED_LIB} PROPERTIES OUTPUT_NAME redis++) | ||
set_target_properties(${SHARED_LIB} PROPERTIES CLEAN_DIRECT_OUTPUT 1) | ||
set_target_properties(${SHARED_LIB} PROPERTIES CXX_EXTENSIONS OFF) | ||
set_target_properties(${SHARED_LIB} PROPERTIES POSITION_INDEPENDENT_CODE ON) | ||
set_target_properties(${SHARED_LIB} PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION_MAJOR}) | ||
endif() | ||
|
||
option(REDIS_PLUS_PLUS_BUILD_TEST "Build tests for redis++" ON) | ||
message(STATUS "redis-plus-plus build test: ${REDIS_PLUS_PLUS_BUILD_TEST}") | ||
|
||
if (REDIS_PLUS_PLUS_BUILD_TEST) | ||
if(REDIS_PLUS_PLUS_BUILD_TEST) | ||
add_subdirectory(test) | ||
endif() | ||
|
||
# Install static lib. | ||
if (REDIS_PLUS_PLUS_BUILD_STATIC) | ||
install(TARGETS ${STATIC_LIB} | ||
ARCHIVE DESTINATION lib) | ||
endif() | ||
install(TARGETS ${REDIS_PLUS_PLUS_TARGETS} | ||
EXPORT redis++-targets | ||
LIBRARY DESTINATION lib | ||
ARCHIVE DESTINATION lib | ||
RUNTIME DESTINATION bin | ||
INCLUDES DESTINATION include) | ||
|
||
# Install shared lib. | ||
if (REDIS_PLUS_PLUS_BUILD_SHARED) | ||
if (WIN32) | ||
install(TARGETS ${SHARED_LIB} | ||
RUNTIME DESTINATION bin | ||
ARCHIVE DESTINATION lib) | ||
else() | ||
install(TARGETS ${SHARED_LIB} | ||
LIBRARY DESTINATION lib) | ||
endif() | ||
endif() | ||
set(REDIS_PLUS_PLUS_CMAKE_DESTINATION share/cmake/redis++) | ||
|
||
install(EXPORT redis++-targets | ||
FILE redis++-targets.cmake | ||
NAMESPACE redis++:: | ||
DESTINATION ${REDIS_PLUS_PLUS_CMAKE_DESTINATION}) | ||
|
||
# Install headers. | ||
set(HEADER_PATH "sw/redis++") | ||
file(GLOB HEADERS "${PROJECT_SOURCE_DIR}/*.h*" "${TLS_SUB_DIR}/*.h") | ||
file(GLOB HEADERS "${REDIS_PLUS_PLUS_SOURCE_DIR}/*.h*" "${TLS_SUB_DIR}/*.h") | ||
install(FILES ${HEADERS} DESTINATION ${CMAKE_INSTALL_PREFIX}/include/${HEADER_PATH}) | ||
|
||
include(CMakePackageConfigHelpers) | ||
|
||
write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/cmake/redis++-config-version.cmake" | ||
VERSION ${PROJECT_VERSION} | ||
COMPATIBILITY AnyNewerVersion) | ||
|
||
configure_package_config_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/redis++-config.cmake.in" | ||
"${CMAKE_CURRENT_BINARY_DIR}/cmake/redis++-config.cmake" | ||
INSTALL_DESTINATION ${REDIS_PLUS_PLUS_CMAKE_DESTINATION}) | ||
|
||
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/cmake/redis++-config.cmake" | ||
"${CMAKE_CURRENT_BINARY_DIR}/cmake/redis++-config-version.cmake" | ||
DESTINATION ${REDIS_PLUS_PLUS_CMAKE_DESTINATION}) | ||
|
||
export(EXPORT redis++-targets | ||
FILE "${CMAKE_CURRENT_BINARY_DIR}/cmake/redis++-targets.cmake" | ||
NAMESPACE redis++::) | ||
|
||
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/redis++.pc.in" | ||
"${CMAKE_CURRENT_BINARY_DIR}/cmake/redis++.pc" @ONLY) | ||
|
||
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/cmake/redis++.pc" | ||
DESTINATION "lib/pkgconfig") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
@PACKAGE_INIT@ | ||
|
||
include(CMakeFindDependencyMacro) | ||
|
||
string(REPLACE "," ";" REDIS_PLUS_PLUS_DEPENDS_LIST @REDIS_PLUS_PLUS_DEPENDS@) | ||
foreach(REDIS_PLUS_PLUS_DEP ${REDIS_PLUS_PLUS_DEPENDS_LIST}) | ||
find_dependency(${REDIS_PLUS_PLUS_DEP} REQUIRED) | ||
endforeach() | ||
|
||
include("${CMAKE_CURRENT_LIST_DIR}/redis++-targets.cmake") | ||
|
||
check_required_components(redis++) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
prefix=@CMAKE_INSTALL_PREFIX@ | ||
exec_prefix=${prefix} | ||
libdir=${exec_prefix}/lib | ||
includedir=${prefix}/include | ||
|
||
Name: redis++ | ||
Description: This is a Redis client, based on hiredis and written in C++11. It supports scritpting, pub/sub, pipeline, transaction, Redis Cluster, Redis Sentinel, connection pool, ACL, SSL and thread safety. | ||
Version: @PROJECT_VERSION@ | ||
URL: https://github.com/sewenew/redis-plus-plus | ||
Requires: @REDIS_PLUS_PLUS_DEPENDS@ | ||
Cflags: -I${includedir} | ||
Libs: -L${libdir} -lredis++ |
Oops, something went wrong.