forked from hmartiro/redox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
183 lines (132 loc) · 5.62 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
cmake_minimum_required(VERSION 2.8.4)
project(redox)
set(REDOX_VERSION_MAJOR 0)
set(REDOX_VERSION_MINOR 2)
set(REDOX_VERSION_PATCH 2)
set(REDOX_VERSION_STRING ${REDOX_VERSION_MAJOR}.${REDOX_VERSION_MINOR}.${REDOX_VERSION_PATCH})
option(lib "Build Redox as a dynamic library." ON)
option(static_lib "Build Redox as a static library." OFF)
option(tests "Build all tests." OFF)
option(examples "Build all examples." OFF)
# Use Release if no configuration specified
if(NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif(NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fPIC -Wall")
# Print out compiler commands
# set(CMAKE_VERBOSE_MAKEFILE ON)
# ---------------------------------------------------------
# Source files
# ---------------------------------------------------------
set(SRC_DIR ${CMAKE_SOURCE_DIR}/src)
set(INC_DIR ${CMAKE_SOURCE_DIR}/include)
set(SRC_CORE
${SRC_DIR}/client.cpp
${SRC_DIR}/command.cpp
${SRC_DIR}/subscriber.cpp)
set(INC_CORE
${INC_DIR}/redox/client.hpp
${INC_DIR}/redox/subscriber.hpp
${INC_DIR}/redox/command.hpp)
set(SRC_UTILS ${SRC_DIR}/utils/logger.cpp)
set(INC_UTILS ${INC_DIR}/redox/utils/logger.hpp)
set(INC_WRAPPER ${INC_DIR}/redox.hpp)
set(SRC_ALL ${SRC_CORE} ${SRC_UTILS})
set(INC_ALL ${INC_CORE} ${INC_UTILS} ${INC_WRAPPER})
include_directories(${INC_DIR})
include_directories(${INC_DIR}/redox)
# Dependent libraries - you may have to change
# pthread to whatever C++11 threads depends on
# for your platform
set(REDOX_LIB_DEPS ev pthread hiredis)
# ---------------------------------------------------------
# Library generation
# ---------------------------------------------------------
if (lib)
add_library(redox SHARED ${SRC_ALL} ${INC_CORE})
target_link_libraries(redox ${REDOX_LIB_DEPS})
set_target_properties(redox
PROPERTIES VERSION ${REDOX_VERSION_STRING}
SOVERSION ${REDOX_VERSION_MAJOR})
endif()
if (static_lib)
add_library(redox_static STATIC ${SRC_ALL})
target_link_libraries(redox_static ${REDOX_LIB_DEPS})
set_target_properties(redox_static
PROPERTIES VERSION ${REDOX_VERSION_STRING}
SOVERSION ${REDOX_VERSION_MAJOR})
endif()
# ---------------------------------------------------------
# Test suite
# ---------------------------------------------------------
if (tests)
enable_testing()
find_package(GTest REQUIRED)
add_executable(test_redox test/test.cpp)
target_include_directories(test_redox PUBLIC ${GTEST_INCLUDE_DIRS})
target_link_libraries(test_redox redox gtest)
# So that we can run 'make test'
add_test(test_redox test_redox)
endif()
# ---------------------------------------------------------
# Examples
# ---------------------------------------------------------
if (examples)
add_executable(basic examples/basic.cpp)
target_link_libraries(basic redox)
add_executable(basic_threaded examples/basic_threaded.cpp)
target_link_libraries(basic_threaded redox)
add_executable(lpush_benchmark examples/lpush_benchmark.cpp)
target_link_libraries(lpush_benchmark redox)
add_executable(speed_test_async examples/speed_test_async.cpp)
target_link_libraries(speed_test_async redox)
add_executable(speed_test_sync examples/speed_test_sync.cpp)
target_link_libraries(speed_test_sync redox)
add_executable(speed_test_async_multi examples/speed_test_async_multi.cpp)
target_link_libraries(speed_test_async_multi redox)
add_executable(data_types examples/data_types.cpp)
target_link_libraries(data_types redox)
add_executable(multi_client examples/multi-client.cpp)
target_link_libraries(multi_client redox)
add_executable(binary_data examples/binary_data.cpp)
target_link_libraries(binary_data redox)
add_executable(pub_sub examples/pub_sub.cpp)
target_link_libraries(pub_sub redox)
add_executable(speed_test_pubsub examples/speed_test_pubsub.cpp)
target_link_libraries(speed_test_pubsub redox)
add_executable(jitter_test examples/jitter_test.cpp)
target_link_libraries(jitter_test redox)
add_custom_target(examples)
add_dependencies(examples
basic basic_threaded lpush_benchmark speed_test_async speed_test_sync
speed_test_async_multi data_types multi_client binary_data pub_sub
speed_test_pubsub jitter_test
)
endif()
# ---------------------------------------------------------
# Install (sudo make install)
# ---------------------------------------------------------
set(CMAKE_INSTALL_PREFIX /usr/)
# Install the dynamic library to /usr/lib
install(TARGETS redox DESTINATION lib)
# Install the headers into /usr/include/redox
install(FILES ${INC_CORE} DESTINATION include/redox)
install(FILES ${INC_UTILS} DESTINATION include/redox/utils)
# Install the top-level header directly into /usr/include
install(FILES ${INC_WRAPPER} DESTINATION include)
# ---------------------------------------------------------
# Create system package (make package)
# ---------------------------------------------------------
# build a CPack driven installer package
include(InstallRequiredSystemLibraries)
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "C++11 client for Redis")
set(CPACK_PACKAGE_VENDOR "Hayk Martirosyan")
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Hayk Martirosyan <[email protected]>")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
#set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6 (>= 2.3.1-6), libgcc1 (>= 1:3.4.2-12)")
set(CPACK_PACKAGE_VERSION_MAJOR "${REDOX_VERSION_MAJOR}")
set(CPACK_PACKAGE_VERSION_MINOR "${REDOX_VERSION_MINOR}")
set(CPACK_PACKAGE_VERSION_PATCH "${REDOX_VERSION_PATCH}")
set(CPACK_GENERATOR "DEB")
include(CPack)