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 )
33
4- # Ensure functions/modules are available
54set (CASS_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR} )
65set (CASS_SRC_DIR "${CASS_ROOT_DIR} /src" )
76set (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)
127
13- CassInitProject(cassandra)
14- CassPolicies()
15- CassCheckPlatform()
8+ # Ensure functions/modules are available
9+ list (APPEND CMAKE_MODULE_PATH ${CASS_ROOT_DIR} /cmake)
1610
11+ set (CMAKE_EXPORT_COMPILE_COMMANDS TRUE )
1712set_property (GLOBAL PROPERTY USE_FOLDERS ON )
1813
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 ()
2325
2426#---------------
2527# Options
2628#---------------
2729
28- option (CASS_BUILD_DOCS "Build documentation" OFF )
2930option (CASS_BUILD_EXAMPLES "Build examples" OFF )
3031option (CASS_BUILD_INTEGRATION_TESTS "Build integration tests" OFF )
3132option (CASS_BUILD_SHARED "Build shared library" ON )
@@ -43,7 +44,6 @@ option(CASS_USE_LIBSSH2 "Use libssh2 for integration tests" OFF)
4344option (CASS_USE_OPENSSL "Use OpenSSL" ON )
4445option (CASS_USE_STATIC_LIBS "Link static libraries when building executables" OFF )
4546option (CASS_USE_STD_ATOMIC "Use C++11 atomics library" OFF )
46- option (CASS_USE_TCMALLOC "Use tcmalloc" OFF )
4747option (CASS_USE_ZLIB "Use zlib" ON )
4848option (CASS_USE_TIMERFD "Use timerfd (Linux only)" ON )
4949
@@ -60,12 +60,12 @@ if(CASS_BUILD_INTEGRATION_TESTS OR CASS_BUILD_UNIT_TESTS)
6060endif ()
6161
6262# 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 )
6464if (CASS_USE_STATIC_LIBS OR
6565 (WIN32 AND (CASS_BUILD_INTEGRATION_TESTS OR CASS_BUILD_UNIT_TESTS)))
6666 set (CASS_USE_STATIC_LIBS ON ) # Not all driver internals are exported for test executable (e.g. CASS_EXPORT)
6767 set (CASS_BUILD_STATIC ON )
68- set (PROJECT_LIB_NAME_TARGET ${PROJECT_LIB_NAME_STATIC} )
68+ set (PROJECT_LIB_NAME_TARGET cassandra_static )
6969endif ()
7070
7171# Ensure the driver is configured to build
@@ -77,131 +77,155 @@ if(CASS_DEBUG_CUSTOM_ALLOC AND CASS_USE_STATIC_LIBS)
7777 message (WARNING "Debugging the custom allocator while static linking the library can cause your application to fail" )
7878endif ()
7979
80- #---------------
80+ #------------------------
8181# Dependencies
82- #---------------
82+ #------------------------
8383
84- CassUseLibuv()
84+ include (Dependencies)
85+ include (ClangFormat)
8586
8687#------------------------
87- # Optional Dependencies
88+ # Project Version
8889#------------------------
89- CassOptionalDependencies()
9090
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]+|\" ([^\" ]+)\" )$" )
9493
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 ()
99103
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 ()
103108
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 ()
108121
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} " )
112123
113- # Assign the include directories
114- include_directories (${CASS_INCLUDES} )
124+ #------------------------
125+ # Determine atomic implementation
126+ #------------------------
115127
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 ()
121136 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 )
124144 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 )
127151 endif ()
128- CassConfigureShared("CASS" )
129- set_property (TARGET ${PROJECT_LIB_NAME} PROPERTY FOLDER "Driver/Cassandra" )
130152endif ()
131153
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" )
137169 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" )
140175 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 ()
143192 endif ()
144- CassConfigureStatic("CASS" )
193+ elseif ("${CMAKE_CXX_COMPILER_ID} " STREQUAL "MSVC" )
194+ add_definitions (/we4800)
145195
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 " )
150200 endif ()
151201
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} " )
153217endif ()
154218
155- #-----------------------------
156- # Unit and integration tests
157- #-----------------------------
158-
159- CassConfigureTests()
160-
161- #-----------
162- # Examples
163- #-----------
219+ #------------------------
220+ # Subdirectories
221+ #------------------------
164222
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)
168224
169225if (CASS_BUILD_EXAMPLES)
170- CassBuildExamples( " examples" )
226+ add_subdirectory ( examples)
171227endif ()
172228
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)
204231endif ()
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