-
Notifications
You must be signed in to change notification settings - Fork 34
/
CMakeLists.txt
136 lines (109 loc) · 4.05 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
cmake_minimum_required(VERSION 3.12.0)
#-----------------------Options--------------------------------------
option (REDISCPP_PURE_CORE "[REDISCPP] Only pure core" OFF)
option (REDISCPP_HEADER_ONLY "[REDISCPP] Header only" OFF)
option (REDISCPP_EASY_ADDRESS_RESOLVE "[REDISCPP] Use easy address resolving" OFF)
option (REDISCPP_PACKAGE_TEST "[REDISCPP] Test installation" OFF)
#--------------------------------------------------------------------
mark_as_advanced(REDISCPP_PACKAGE_TEST)
project(redis-cpp
VERSION 1.0.0
LANGUAGES CXX
DESCRIPTION "redis-cpp - lightweight C++ client library for Redis"
)
set(PROJECT ${PROJECT_NAME})
string(TOLOWER "${PROJECT}" PROJECT_LC)
if (REDISCPP_PURE_CORE)
set (REDISCPP_DEFINES "${REDISCPP_DEFINES} -DREDISCPP_PURE_CORE")
endif()
if (REDISCPP_EASY_ADDRESS_RESOLVE)
set(REDISCPP_DEFINES, "${REDISCPP_DEFINES} -DREDISCPP_EASY_ADDRESS_RESOLVE")
endif()
set (CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/lib)
set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
set (CMAKE_CXX_EXTENSIONS OFF)
#---------------------------------------------------------
add_library (${PROJECT_LC}-ho INTERFACE)
add_library (${PROJECT_LC}::${PROJECT_LC}-ho ALIAS ${PROJECT_LC}-ho)
target_include_directories (${PROJECT_LC}-ho INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>
$<INSTALL_INTERFACE:include>
)
target_compile_definitions(${PROJECT_LC}-ho INTERFACE ${REDISCPP_DEFINES} REDISCPP_HEADER_ONLY)
target_compile_features(${PROJECT_LC}-ho INTERFACE cxx_std_17)
if (NOT REDISCPP_HEADER_ONLY)
add_library (${PROJECT_LC} STATIC src/redis-cpp/stream.cpp)
add_library (${PROJECT_LC}::${PROJECT_LC} ALIAS ${PROJECT_LC})
target_include_directories (${PROJECT_LC} PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>
$<INSTALL_INTERFACE:include>
)
target_compile_definitions(${PROJECT_LC} INTERFACE ${REDISCPP_DEFINES})
target_compile_features(${PROJECT_LC} PUBLIC cxx_std_17)
set_target_properties(${PROJECT_LC} PROPERTIES PUBLIC_CMAKE_POSITION_INDEPENDENT_CODE ON)
if (UNIX)
target_compile_options(${PROJECT_LC} PRIVATE -Wall -Wextra -W)
endif()
endif()
if (NOT REDISCPP_PURE_CORE)
find_package (Boost 1.67.0 REQUIRED COMPONENTS thread system iostreams)
target_link_libraries (${PROJECT_LC}-ho INTERFACE Boost::boost Boost::system Boost::thread Boost::iostreams)
if(NOT REDISCPP_HEADER_ONLY)
target_link_libraries (${PROJECT_LC} PUBLIC Boost::boost Boost::system Boost::thread Boost::iostreams)
endif()
endif()
# install
include (GNUInstallDirs)
include (CMakePackageConfigHelpers)
write_basic_package_version_file (
${CMAKE_CURRENT_BINARY_DIR}/generated/${PROJECT_LC}-config-version.cmake
COMPATIBILITY
SameMajorVersion
)
configure_package_config_file (
${CMAKE_CURRENT_SOURCE_DIR}/cmake/${PROJECT_LC}-config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/generated/${PROJECT_LC}-config.cmake
INSTALL_DESTINATION
${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_LC}
)
install (
DIRECTORY
${CMAKE_CURRENT_SOURCE_DIR}/include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FILES_MATCHING
PATTERN "*.hpp"
PATTERN "*.h"
)
install (
FILES
${CMAKE_CURRENT_BINARY_DIR}/generated/${PROJECT_LC}-config.cmake
${CMAKE_CURRENT_BINARY_DIR}/generated/${PROJECT_LC}-config-version.cmake
DESTINATION
${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_LC}
)
install (
TARGETS
${PROJECT_LC}-ho
EXPORT ${PROJECT_LC}-targets
)
if (NOT REDISCPP_HEADER_ONLY)
install (
TARGETS
${PROJECT_LC}
EXPORT ${PROJECT_LC}-targets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
endif()
install(
EXPORT ${PROJECT_LC}-targets
NAMESPACE ${PROJECT_LC}::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_LC}
)
# testing
if (REDISCPP_PACKAGE_TEST)
add_subdirectory(test/package/header_only)
if (NOT REDISCPP_HEADER_ONLY)
add_subdirectory(test/package/compiled)
endif()
endif()