forked from sewenew/redis-plus-plus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
130 lines (97 loc) · 4.11 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
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")
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()
if (NOT DEFINED REDIS_PLUS_PLUS_CXX_STANDARD)
set(REDIS_PLUS_PLUS_CXX_STANDARD 11)
endif()
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")
endif()
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(PROJECT_SOURCE_DIR ${PROJECT_SOURCE_DIR}/src/sw/redis++)
file(GLOB PROJECT_SOURCE_FILES "${PROJECT_SOURCE_DIR}/*.cpp")
# TLS support
option(REDIS_PLUS_PLUS_USE_TLS "Build with TLS support" OFF)
if (REDIS_PLUS_PLUS_USE_TLS)
message(STATUS "Build with TLS support")
set(TLS_SUB_DIR "${PROJECT_SOURCE_DIR}/tls")
else()
set(TLS_SUB_DIR "${PROJECT_SOURCE_DIR}/no_tls")
endif()
file(GLOB TLS_SOURCE_FILES "${TLS_SUB_DIR}/*.cpp")
# hiredis dependency
find_path(HIREDIS_HEADER hiredis)
find_library(HIREDIS_LIB hiredis)
# Build static library
option(REDIS_PLUS_PLUS_BUILD_STATIC "Build static library" ON)
if (REDIS_PLUS_PLUS_BUILD_STATIC)
set(STATIC_LIB redis-plus-plus-static)
add_library(${STATIC_LIB} STATIC ${PROJECT_SOURCE_FILES} ${TLS_SOURCE_FILES})
target_include_directories(${STATIC_LIB} PUBLIC ${PROJECT_SOURCE_DIR} ${TLS_SUB_DIR})
target_include_directories(${STATIC_LIB} PUBLIC ${HIREDIS_HEADER})
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)
else()
set_target_properties(${STATIC_LIB} PROPERTIES OUTPUT_NAME ${PROJECT_NAME})
endif()
set_target_properties(${STATIC_LIB} PROPERTIES CLEAN_DIRECT_OUTPUT 1)
set_target_properties(${STATIC_LIB} PROPERTIES POSITION_INDEPENDENT_CODE ON)
endif()
# Build shared library
option(REDIS_PLUS_PLUS_BUILD_SHARED "Build shared library" ON)
if (REDIS_PLUS_PLUS_BUILD_SHARED)
set(SHARED_LIB redis-plus-plus-shared)
add_library(${SHARED_LIB} SHARED ${PROJECT_SOURCE_FILES} ${TLS_SOURCE_FILES})
target_include_directories(${SHARED_LIB} PUBLIC ${PROJECT_SOURCE_DIR} ${TLS_SUB_DIR})
target_include_directories(${SHARED_LIB} PUBLIC ${HIREDIS_HEADER})
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_link_libraries(${SHARED_LIB} ${HIREDIS_LIB})
if (REDIS_PLUS_PLUS_USE_TLS)
find_library(HIREDIS_TLS_LIB hiredis_ssl)
target_link_libraries(${SHARED_LIB} ${HIREDIS_TLS_LIB})
endif()
set_target_properties(${SHARED_LIB} PROPERTIES OUTPUT_NAME ${PROJECT_NAME})
set_target_properties(${SHARED_LIB} PROPERTIES CLEAN_DIRECT_OUTPUT 1)
set_target_properties(${SHARED_LIB} PROPERTIES POSITION_INDEPENDENT_CODE ON)
endif()
option(REDIS_PLUS_PLUS_BUILD_TEST "Build tests for redis++" ON)
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 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()
# Install headers.
set(HEADER_PATH "sw/redis++")
file(GLOB HEADERS "${PROJECT_SOURCE_DIR}/*.h*" "${TLS_SUB_DIR}/*.h")
install(FILES ${HEADERS} DESTINATION ${CMAKE_INSTALL_PREFIX}/include/${HEADER_PATH})