1
- cmake_minimum_required (VERSION 2.6.4 )
2
- set ( CMAKE_EXPORT_COMPILE_COMMANDS TRUE )
1
+ cmake_minimum_required (VERSION 2.8.12 )
2
+ project ( cassandra C CXX )
3
3
4
- # Ensure functions/modules are available
5
4
set (CASS_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR} )
6
5
set (CASS_SRC_DIR "${CASS_ROOT_DIR} /src" )
7
6
set (CASS_INCLUDE_DIR "${CASS_ROOT_DIR} /include" )
8
- list (APPEND CMAKE_MODULE_PATH ${CASS_ROOT_DIR} /cmake/modules )
9
-
10
- include (CppDriver )
11
- include (ClangFormat )
12
7
13
- CassInitProject (cassandra )
14
- CassPolicies ()
15
- CassCheckPlatform ()
8
+ # Ensure functions/modules are available
9
+ list (APPEND CMAKE_MODULE_PATH ${CASS_ROOT_DIR} /cmake )
16
10
11
+ set (CMAKE_EXPORT_COMPILE_COMMANDS TRUE )
17
12
set_property (GLOBAL PROPERTY USE_FOLDERS ON )
18
13
19
- #------------------------
20
- # Project Version
21
- #------------------------
22
- CassProjectVersion ("${CASS_INCLUDE_DIR} /cassandra.h" "CASS" )
14
+ #---------------
15
+ # Policies
16
+ #---------------
17
+
18
+ if (POLICY CMP0074 )
19
+ cmake_policy (SET CMP0074 NEW )
20
+ endif ()
21
+
22
+ if (POLICY CMP0054 )
23
+ cmake_policy (SET CMP0054 NEW )
24
+ endif ()
23
25
24
26
#---------------
25
27
# Options
26
28
#---------------
27
29
28
- option (CASS_BUILD_DOCS "Build documentation" OFF )
29
30
option (CASS_BUILD_EXAMPLES "Build examples" OFF )
30
31
option (CASS_BUILD_INTEGRATION_TESTS "Build integration tests" OFF )
31
32
option (CASS_BUILD_SHARED "Build shared library" ON )
@@ -43,7 +44,6 @@ option(CASS_USE_LIBSSH2 "Use libssh2 for integration tests" OFF)
43
44
option (CASS_USE_OPENSSL "Use OpenSSL" ON )
44
45
option (CASS_USE_STATIC_LIBS "Link static libraries when building executables" OFF )
45
46
option (CASS_USE_STD_ATOMIC "Use C++11 atomics library" OFF )
46
- option (CASS_USE_TCMALLOC "Use tcmalloc" OFF )
47
47
option (CASS_USE_ZLIB "Use zlib" ON )
48
48
option (CASS_USE_TIMERFD "Use timerfd (Linux only)" ON )
49
49
@@ -60,12 +60,12 @@ if(CASS_BUILD_INTEGRATION_TESTS OR CASS_BUILD_UNIT_TESTS)
60
60
endif ()
61
61
62
62
# Determine which driver target should be used as a dependency
63
- set (PROJECT_LIB_NAME_TARGET ${PROJECT_LIB_NAME} )
63
+ set (PROJECT_LIB_NAME_TARGET cassandra )
64
64
if (CASS_USE_STATIC_LIBS OR
65
65
(WIN32 AND (CASS_BUILD_INTEGRATION_TESTS OR CASS_BUILD_UNIT_TESTS )))
66
66
set (CASS_USE_STATIC_LIBS ON ) # Not all driver internals are exported for test executable (e.g. CASS_EXPORT)
67
67
set (CASS_BUILD_STATIC ON )
68
- set (PROJECT_LIB_NAME_TARGET ${PROJECT_LIB_NAME_STATIC} )
68
+ set (PROJECT_LIB_NAME_TARGET cassandra_static )
69
69
endif ()
70
70
71
71
# Ensure the driver is configured to build
@@ -77,131 +77,155 @@ if(CASS_DEBUG_CUSTOM_ALLOC AND CASS_USE_STATIC_LIBS)
77
77
message (WARNING "Debugging the custom allocator while static linking the library can cause your application to fail" )
78
78
endif ()
79
79
80
- #---------------
80
+ #------------------------
81
81
# Dependencies
82
- #---------------
82
+ #------------------------
83
83
84
- CassUseLibuv ()
84
+ include (Dependencies )
85
+ include (ClangFormat )
85
86
86
87
#------------------------
87
- # Optional Dependencies
88
+ # Project Version
88
89
#------------------------
89
- CassOptionalDependencies ()
90
90
91
- #----------------------
92
- # Generating API docs
93
- #----------------------
91
+ file (STRINGS "${CASS_INCLUDE_DIR} /cassandra.h" _VERSION_PARTS
92
+ REGEX "^#define[ \t ]+CASS_VERSION_(MAJOR|MINOR|PATCH|SUFFIX)[ \t ]+([0-9]+|\" ([^\" ]+)\" )$" )
94
93
95
- # Doxygen
96
- if (CASS_BUILD_DOCS )
97
- CassDoxygen ()
98
- endif ()
94
+ foreach (part MAJOR MINOR PATCH SUFFIX )
95
+ string (REGEX MATCH "CASS_VERSION_${part} [ \t ]+([0-9]+|\" ([^\" ]+)\" )"
96
+ PROJECT_VERSION_${part} ${_VERSION_PARTS} )
97
+ # Extract version numbers
98
+ if (PROJECT_VERSION_${part} )
99
+ string (REGEX REPLACE "CASS_VERSION_${part} [ \t ]+([0-9]+|\" ([^\" ]+)\" )" "\\ 1"
100
+ PROJECT_VERSION_${part} ${PROJECT_VERSION_${part}} )
101
+ endif ()
102
+ endforeach ()
99
103
100
- #------------------------------
101
- # Cassandra static and shared
102
- #------------------------------
104
+ # Verify version parts
105
+ if (NOT PROJECT_VERSION_MAJOR AND NOT PROJECT_VERSION_MINOR )
106
+ message (FATAL_ERROR "Unable to retrieve driver version from ${version_header_file} " )
107
+ endif ()
103
108
104
- CassSetCompilerFlags ()
105
- CassAddIncludes ()
106
- CassFindSourceFiles ()
107
- CassConfigure ()
109
+ set (PROJECT_VERSION_STRING
110
+ ${PROJECT_VERSION_MAJOR} .${PROJECT_VERSION_MINOR} )
111
+ if (NOT PROJECT_VERSION_PATCH STREQUAL "" )
112
+ set (PROJECT_VERSION_STRING
113
+ "${PROJECT_VERSION_STRING} .${PROJECT_VERSION_PATCH} " )
114
+ endif ()
115
+ if (NOT PROJECT_VERSION_SUFFIX STREQUAL "" )
116
+ string (REPLACE "\" " ""
117
+ PROJECT_VERSION_SUFFIX ${PROJECT_VERSION_SUFFIX} )
118
+ set (PROJECT_VERSION_STRING
119
+ "${PROJECT_VERSION_STRING} -${PROJECT_VERSION_SUFFIX} " )
120
+ endif ()
108
121
109
- set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR} )
110
- set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR} )
111
- set (CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR} )
122
+ message (STATUS "Driver version: ${PROJECT_VERSION_STRING} " )
112
123
113
- # Assign the include directories
114
- include_directories (${CASS_INCLUDES} )
124
+ #------------------------
125
+ # Determine atomic implementation
126
+ #------------------------
115
127
116
- # Determine if the dynamic/shared library should be built
117
- if (CASS_BUILD_SHARED )
118
- add_library (${PROJECT_LIB_NAME} SHARED ${CASS_ALL_SOURCE_FILES} )
119
- if (CASS_USE_BOOST_ATOMIC AND BOOST_LIBRARY_NAME )
120
- add_dependencies (${PROJECT_LIB_NAME} ${BOOST_LIBRARY_NAME} )
128
+ # Determine if std::atomic can be used for GCC, Clang, or MSVC
129
+ if ("${CMAKE_CXX_COMPILER_ID} " STREQUAL "GNU" )
130
+ if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX )
131
+ # Version determined from: https://gcc.gnu.org/wiki/Atomic/GCCMM
132
+ if (CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL "4.7" OR
133
+ CMAKE_CXX_COMPILER_VERSION VERSION_GREATER "4.7" )
134
+ set (CASS_USE_STD_ATOMIC ON )
135
+ endif ()
121
136
endif ()
122
- if (LIBUV_LIBRARY_NAME )
123
- add_dependencies (${PROJECT_LIB_NAME} ${LIBUV_LIBRARY_NAME} )
137
+ elseif ("${CMAKE_CXX_COMPILER_ID} " STREQUAL "Clang" )
138
+ # Version determined from: http://clang.llvm.org/cxx_status.html
139
+ # 3.2 includes the full C++11 memory model, but 3.1 had atomic
140
+ # support.
141
+ if (CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL "3.1" OR
142
+ CMAKE_CXX_COMPILER_VERSION VERSION_GREATER "3.1" )
143
+ set (CASS_USE_STD_ATOMIC ON )
124
144
endif ()
125
- if (OPENSSL_LIBRARY_NAME )
126
- add_dependencies (${PROJECT_LIB_NAME} ${OPENSSL_LIBRARY_NAME} )
145
+ elseif ("${CMAKE_CXX_COMPILER_ID} " STREQUAL "MSVC" )
146
+ # Version determined from https://msdn.microsoft.com/en-us/library/hh874894
147
+ # VS2012+/VS 11.0+/WindowsSDK v8.0+
148
+ if (MSVC_VERSION GREATER 1700 OR
149
+ MSVC_VERSION EQUAL 1700 )
150
+ set (CASS_USE_STD_ATOMIC ON )
127
151
endif ()
128
- CassConfigureShared ("CASS" )
129
- set_property (TARGET ${PROJECT_LIB_NAME} PROPERTY FOLDER "Driver/Cassandra" )
130
152
endif ()
131
153
132
- # Determine if the static library should be built
133
- if (CASS_BUILD_STATIC )
134
- add_library (${PROJECT_LIB_NAME_STATIC} STATIC ${CASS_ALL_SOURCE_FILES} )
135
- if (CASS_USE_BOOST_ATOMIC AND BOOST_LIBRARY_NAME )
136
- add_dependencies (${PROJECT_LIB_NAME_STATIC} ${BOOST_LIBRARY_NAME} )
154
+ if (CASS_USE_BOOST_ATOMIC )
155
+ message (STATUS "Using boost::atomic implementation for atomic operations" )
156
+ elseif (CASS_USE_STD_ATOMIC )
157
+ message (STATUS "Using std::atomic implementation for atomic operations" )
158
+ endif ()
159
+
160
+ #------------------------
161
+ # Top-level compiler flags
162
+ #------------------------
163
+
164
+ if ("${CMAKE_CXX_COMPILER_ID} " STREQUAL "Clang" OR
165
+ "${CMAKE_CXX_COMPILER_ID} " STREQUAL "GNU" )
166
+ # Enable C++11 support to use std::atomic
167
+ if (CASS_USE_STD_ATOMIC )
168
+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11" )
137
169
endif ()
138
- if (LIBUV_LIBRARY_NAME )
139
- add_dependencies (${PROJECT_LIB_NAME_STATIC} ${LIBUV_LIBRARY_NAME} )
170
+
171
+ # OpenSSL is deprecated on later versions of Mac OS X. The long-term solution
172
+ # is to provide a CommonCryto implementation.
173
+ if (APPLE AND CASS_USE_OPENSSL )
174
+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations" )
140
175
endif ()
141
- if (OPENSSL_LIBRARY_NAME )
142
- add_dependencies (${PROJECT_LIB_NAME_STATIC} ${OPENSSL_LIBRARY_NAME} )
176
+
177
+ if ("${CMAKE_CXX_COMPILER_ID} " STREQUAL "Clang" )
178
+ # Clang/Intel specific compiler options
179
+ # I disabled long-long warning because boost generates about 50 such warnings
180
+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic -Wextra -Wno-long-long -Wno-unused-parameter" )
181
+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-variadic-macros -Wno-zero-length-array" )
182
+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-local-typedef -Wno-unknown-warning-option" )
183
+ else ()
184
+ # GCC specific compiler options
185
+ # I disabled long-long warning because boost generates about 50 such warnings
186
+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic -Wextra -Wno-long-long -Wno-unused-parameter -Wno-variadic-macros" )
187
+
188
+ if (CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL "4.8" OR
189
+ CMAKE_CXX_COMPILER_VERSION VERSION_GREATER "4.8" )
190
+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-local-typedefs" )
191
+ endif ()
143
192
endif ()
144
- CassConfigureStatic ("CASS" )
193
+ elseif ("${CMAKE_CXX_COMPILER_ID} " STREQUAL "MSVC" )
194
+ add_definitions (/we4800 )
145
195
146
- # Set pkg_config required libraries
147
- set ( PC_REQUIRED_LIBS "libuv" )
148
- if ( CASS_USE_OPENSSL )
149
- set ( PC_REQUIRED_LIBS " ${PC_REQUIRED_LIBS} openssl " )
196
+ # Determine if multicore compilation should be enabled
197
+ if ( CASS_MULTICORE_COMPILATION )
198
+ # Default multicore compilation with effective processors (see https://msdn.microsoft.com/en-us/library/bb385193.aspx )
199
+ add_definitions ( "/MP " )
150
200
endif ()
151
201
152
- set_property (TARGET ${PROJECT_LIB_NAME_STATIC} PROPERTY FOLDER "Driver/Cassandra" )
202
+ # On Visual C++ -pedantic flag is not used,
203
+ # -fPIC is not used on Windows platform (all DLLs are
204
+ # relocable), -Wall generates about 30k stupid warnings
205
+ # that can hide useful ones.
206
+ # Create specific warning disable compiler flags
207
+ # TODO(mpenick): Fix these "possible loss of data" warnings
208
+ add_definitions (/wd4244 )
209
+ add_definitions (/wd4267 )
210
+
211
+ # Add preprocessor definitions for proper compilation
212
+ add_definitions (-D_CRT_SECURE_NO_WARNINGS ) # Remove warnings for not using safe functions (TODO: Fix codebase to be more secure for Visual Studio)
213
+ add_definitions (-DNOMINMAX ) # Does not define min/max macros
214
+ add_definitions (-D_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING ) # Remove warnings for TR1 deprecation (Visual Studio 15 2017); caused by sparsehash
215
+ else ()
216
+ message (FATAL_ERROR "Unsupported compiler: ${CMAKE_CXX_COMPILER_ID} " )
153
217
endif ()
154
218
155
- #-----------------------------
156
- # Unit and integration tests
157
- #-----------------------------
158
-
159
- CassConfigureTests ()
160
-
161
- #-----------
162
- # Examples
163
- #-----------
219
+ #------------------------
220
+ # Subdirectories
221
+ #------------------------
164
222
165
- # Determine example directories at cmake execution time.
166
- # When a new example dir is added, the user just runs cmake again to pull it in;
167
- # no need to update CMakeLists.txt!
223
+ add_subdirectory (src )
168
224
169
225
if (CASS_BUILD_EXAMPLES )
170
- CassBuildExamples ( " examples" )
226
+ add_subdirectory ( examples )
171
227
endif ()
172
228
173
- #-------------------------------------
174
- # Installation information
175
- #-------------------------------------
176
- CassConfigureInstall (CASS cassandra )
177
-
178
- #-------------------
179
- # Uninstall target
180
- #-------------------
181
-
182
- configure_file (
183
- "${CMAKE_CURRENT_SOURCE_DIR} /cmake_uninstall.cmake.in"
184
- "${CMAKE_CURRENT_BINARY_DIR} /cmake_uninstall.cmake"
185
- IMMEDIATE @ONLY )
186
-
187
- add_custom_target (UNINSTALL
188
- COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR} /cmake_uninstall.cmake )
189
-
190
- #-----------------------------------
191
- # Build an RPM.
192
- #-----------------------------------
193
- set (CPACK_PACKAGE_VERSION ${PROJECT_VERSION_STRING} )
194
- set (CPACK_GENERATOR "RPM" )
195
- set (CPACK_PACKAGE_NAME "cpp-cassandra-driver" )
196
- set (CPACK_PACKAGE_RELEASE 1 )
197
- set (CPACK_PACKAGE_DESCRIPTION_SUMMARY "C++ driver for Cassandra" )
198
- set (CPACK_PACKAGE_CONTACT "Michael Penick" )
199
- set (CPACK_PACKAGE_VENDOR "Datastax" )
200
- if (32BIT )
201
- set (CPACK_RPM_PACKAGE_ARCHITECTURE i686 )
202
- else ()
203
- set (CPACK_RPM_PACKAGE_ARCHITECTURE x86_64 )
229
+ if (CASS_BUILD_INTEGRATION_TESTS OR CASS_BUILD_UNIT_TESTS )
230
+ add_subdirectory (tests )
204
231
endif ()
205
- set (CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME} -${CPACK_PACKAGE_VERSION} -${CPACK_PACKAGE_RELEASE} .${CPACK_RPM_PACKAGE_ARCHITECTURE} " )
206
- set (CPACK_RPM_PACKAGE_REQUIRES "libuv" )
207
- include (CPack )
0 commit comments