forked from datastax/cpp-driver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
207 lines (172 loc) · 6.47 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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
cmake_minimum_required(VERSION 2.6.4)
set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE)
# Ensure functions/modules are available
set(CASS_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(CASS_SRC_DIR "${CASS_ROOT_DIR}/src")
set(CASS_INCLUDE_DIR "${CASS_ROOT_DIR}/include")
list(APPEND CMAKE_MODULE_PATH ${CASS_ROOT_DIR}/cmake/modules)
include(CppDriver)
include(ClangFormat)
CassInitProject(cassandra)
CassPolicies()
CassCheckPlatform()
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
#------------------------
# Project Version
#------------------------
CassProjectVersion("${CASS_INCLUDE_DIR}/cassandra.h" "CASS")
#---------------
# Options
#---------------
option(CASS_BUILD_DOCS "Build documentation" OFF)
option(CASS_BUILD_EXAMPLES "Build examples" OFF)
option(CASS_BUILD_INTEGRATION_TESTS "Build integration tests" OFF)
option(CASS_BUILD_SHARED "Build shared library" ON)
option(CASS_BUILD_STATIC "Build static library" OFF)
option(CASS_BUILD_TESTS "Build tests" OFF)
option(CASS_BUILD_UNIT_TESTS "Build unit tests" OFF)
option(CASS_DEBUG_CUSTOM_ALLOC "Debug custom allocator" OFF)
option(CASS_INSTALL_HEADER "Install header file" ON)
option(CASS_INSTALL_HEADER_IN_SUBDIR "Install header file under 'include/cassandra'" OFF)
option(CASS_INSTALL_PKG_CONFIG "Install pkg-config file(s)" ON)
option(CASS_MULTICORE_COMPILATION "Enable multicore compilation" ON)
option(CASS_USE_BOOST_ATOMIC "Use Boost atomics library" OFF)
option(CASS_USE_KERBEROS "Use Kerberos" OFF)
option(CASS_USE_LIBSSH2 "Use libssh2 for integration tests" OFF)
option(CASS_USE_OPENSSL "Use OpenSSL" ON)
option(CASS_USE_STATIC_LIBS "Link static libraries when building executables" OFF)
option(CASS_USE_STD_ATOMIC "Use C++11 atomics library" OFF)
option(CASS_USE_TCMALLOC "Use tcmalloc" OFF)
option(CASS_USE_ZLIB "Use zlib" ON)
option(CASS_USE_TIMERFD "Use timerfd (Linux only)" ON)
# Handle testing dependencies
if(CASS_BUILD_TESTS)
# Enable integration and unit tests
set(CASS_BUILD_INTEGRATION_TESTS ON)
set(CASS_BUILD_UNIT_TESTS ON)
endif()
if(CASS_BUILD_INTEGRATION_TESTS OR CASS_BUILD_UNIT_TESTS)
set(CASS_USE_OPENSSL ON) # Required for tests
set(CASS_USE_KERBEROS ON) # Required for tests
endif()
# Determine which driver target should be used as a dependency
set(PROJECT_LIB_NAME_TARGET ${PROJECT_LIB_NAME})
if(CASS_USE_STATIC_LIBS OR
(WIN32 AND (CASS_BUILD_INTEGRATION_TESTS OR CASS_BUILD_UNIT_TESTS)))
set(CASS_USE_STATIC_LIBS ON) # Not all driver internals are exported for test executable (e.g. CASS_EXPORT)
set(CASS_BUILD_STATIC ON)
set(PROJECT_LIB_NAME_TARGET ${PROJECT_LIB_NAME_STATIC})
endif()
# Ensure the driver is configured to build
if(NOT CASS_BUILD_SHARED AND NOT CASS_BUILD_STATIC)
message(FATAL_ERROR "Driver is not Configured to Build: Ensure shared and/or static library is enabled")
endif()
if(CASS_DEBUG_CUSTOM_ALLOC AND CASS_USE_STATIC_LIBS)
message(WARNING "Debugging the custom allocator while static linking the library can cause your application to fail")
endif()
#---------------
# Dependencies
#---------------
CassUseLibuv()
#------------------------
# Optional Dependencies
#------------------------
CassOptionalDependencies()
#----------------------
# Generating API docs
#----------------------
# Doxygen
if(CASS_BUILD_DOCS)
CassDoxygen()
endif()
#------------------------------
# Cassandra static and shared
#------------------------------
CassSetCompilerFlags()
CassAddIncludes()
CassFindSourceFiles()
CassConfigure()
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
# Assign the include directories
include_directories(${CASS_INCLUDES})
# Determine if the dynamic/shared library should be built
if(CASS_BUILD_SHARED)
add_library(${PROJECT_LIB_NAME} SHARED ${CASS_ALL_SOURCE_FILES})
if(CASS_USE_BOOST_ATOMIC AND BOOST_LIBRARY_NAME)
add_dependencies(${PROJECT_LIB_NAME} ${BOOST_LIBRARY_NAME})
endif()
if(LIBUV_LIBRARY_NAME)
add_dependencies(${PROJECT_LIB_NAME} ${LIBUV_LIBRARY_NAME})
endif()
if(OPENSSL_LIBRARY_NAME)
add_dependencies(${PROJECT_LIB_NAME} ${OPENSSL_LIBRARY_NAME})
endif()
CassConfigureShared("CASS")
set_property(TARGET ${PROJECT_LIB_NAME} PROPERTY FOLDER "Driver/Cassandra")
endif()
# Determine if the static library should be built
if(CASS_BUILD_STATIC)
add_library(${PROJECT_LIB_NAME_STATIC} STATIC ${CASS_ALL_SOURCE_FILES})
if(CASS_USE_BOOST_ATOMIC AND BOOST_LIBRARY_NAME)
add_dependencies(${PROJECT_LIB_NAME_STATIC} ${BOOST_LIBRARY_NAME})
endif()
if(LIBUV_LIBRARY_NAME)
add_dependencies(${PROJECT_LIB_NAME_STATIC} ${LIBUV_LIBRARY_NAME})
endif()
if(OPENSSL_LIBRARY_NAME)
add_dependencies(${PROJECT_LIB_NAME_STATIC} ${OPENSSL_LIBRARY_NAME})
endif()
CassConfigureStatic("CASS")
# Set pkg_config required libraries
set(PC_REQUIRED_LIBS "libuv")
if (CASS_USE_OPENSSL)
set(PC_REQUIRED_LIBS "${PC_REQUIRED_LIBS} openssl")
endif()
set_property(TARGET ${PROJECT_LIB_NAME_STATIC} PROPERTY FOLDER "Driver/Cassandra")
endif()
#-----------------------------
# Unit and integration tests
#-----------------------------
CassConfigureTests()
#-----------
# Examples
#-----------
# Determine example directories at cmake execution time.
# When a new example dir is added, the user just runs cmake again to pull it in;
# no need to update CMakeLists.txt!
if(CASS_BUILD_EXAMPLES)
CassBuildExamples("examples")
endif()
#-------------------------------------
# Installation information
#-------------------------------------
CassConfigureInstall(CASS cassandra)
#-------------------
# Uninstall target
#-------------------
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY)
add_custom_target(UNINSTALL
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
#-----------------------------------
# Build an RPM.
#-----------------------------------
set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION_STRING})
set(CPACK_GENERATOR "RPM")
set(CPACK_PACKAGE_NAME "cpp-cassandra-driver")
set(CPACK_PACKAGE_RELEASE 1)
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "C++ driver for Cassandra")
set(CPACK_PACKAGE_CONTACT "Michael Penick")
set(CPACK_PACKAGE_VENDOR "Datastax")
if(32BIT)
set(CPACK_RPM_PACKAGE_ARCHITECTURE i686)
else()
set(CPACK_RPM_PACKAGE_ARCHITECTURE x86_64)
endif()
set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${CPACK_PACKAGE_RELEASE}.${CPACK_RPM_PACKAGE_ARCHITECTURE}")
set(CPACK_RPM_PACKAGE_REQUIRES "libuv")
include(CPack)