Skip to content

Commit c41faa4

Browse files
committed
build: Fallback to C++11
This required minor syntactic fixes and replacing std::optional with a 3rd party implementation (by Andrzej Krzemienski). The selection of `optional` is done on the basis of C++ standard version, e.g.: cmake -DCASS_CPP_STANDARD=17 .. will use std::optional, while `-DCASS_CPP_STANDARD=11` will fall back to 3rd party impl.
1 parent 8dcb69e commit c41faa4

File tree

13 files changed

+1197
-24
lines changed

13 files changed

+1197
-24
lines changed

CMakeLists.txt

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 2.8.12)
1+
cmake_minimum_required(VERSION 3.1)
22
project(cassandra C CXX)
33

44
set(CASS_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR})
@@ -43,10 +43,12 @@ option(CASS_USE_KERBEROS "Use Kerberos" OFF)
4343
option(CASS_USE_LIBSSH2 "Use libssh2 for integration tests" OFF)
4444
option(CASS_USE_OPENSSL "Use OpenSSL" ON)
4545
option(CASS_USE_STATIC_LIBS "Link static libraries when building executables" OFF)
46-
option(CASS_USE_STD_ATOMIC "Use C++11 atomics library" ON)
46+
option(CASS_USE_STD_ATOMIC "Use std::atomic library" ON)
4747
option(CASS_USE_ZLIB "Use zlib" ON)
4848
option(CASS_USE_TIMERFD "Use timerfd (Linux only)" ON)
4949

50+
set(CASS_CPP_STANDARD "11" CACHE STRING "C++ standard (11, 14, 17, etc.)")
51+
5052
# Handle testing dependencies
5153
if(CASS_BUILD_TESTS)
5254
# Enable integration and unit tests
@@ -161,10 +163,10 @@ endif()
161163
# Top-level compiler flags
162164
#------------------------
163165

166+
set (CMAKE_CXX_STANDARD ${CASS_CPP_STANDARD})
167+
164168
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR
165169
"${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
166-
# Enable C++17 support by default
167-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
168170

169171
# OpenSSL is deprecated on later versions of Mac OS X. The long-term solution
170172
# is to provide a CommonCryto implementation.
@@ -191,9 +193,6 @@ if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR
191193
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
192194
add_definitions(/we4800)
193195

194-
# Enable C++17 support by default
195-
add_definitions(/std:c++17)
196-
197196
# Determine if multicore compilation should be enabled
198197
if(CASS_MULTICORE_COMPILATION)
199198
# Default multicore compilation with effective processors (see https://msdn.microsoft.com/en-us/library/bb385193.aspx)

driver_config.hpp.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#cmakedefine HAVE_KERBEROS
55
#cmakedefine HAVE_OPENSSL
66
#cmakedefine HAVE_STD_ATOMIC
7+
#cmakedefine CASS_CPP_STANDARD @CASS_CPP_STANDARD@
78
#cmakedefine HAVE_BOOST_ATOMIC
89
#cmakedefine HAVE_NOSIGPIPE
910
#cmakedefine HAVE_SIGTIMEDWAIT
File renamed without changes.

examples/licenses/boost-1.0.txt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Boost Software License - Version 1.0 - August 17th, 2003
2+
3+
Permission is hereby granted, free of charge, to any person or organization
4+
obtaining a copy of the software and accompanying documentation covered by
5+
this license (the "Software") to use, reproduce, display, distribute,
6+
execute, and transmit the Software, and to prepare derivative works of the
7+
Software, and to permit third-parties to whom the Software is furnished to
8+
do so, all subject to the following:
9+
10+
The copyright notices in the Software and this entire statement, including
11+
the above license grant, this restriction and the following disclaimer,
12+
must be included in all copies of the Software, in whole or in part, and
13+
all derivative works of the Software, unless such copies or derivative
14+
works are solely in the form of machine-executable object code generated by
15+
a source language processor.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
20+
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
21+
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
22+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23+
DEALINGS IN THE SOFTWARE.

src/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ else()
3636
endif()
3737
endif()
3838

39+
# Determine `optional` library to include
40+
if(CMAKE_CXX_STANDARD LESS 17)
41+
message(STATUS "Using akrzemi's `optional` implementation")
42+
list(APPEND SOURCES optional/optional_akrzemi.hpp)
43+
else()
44+
message(STATUS "Using std::optional library")
45+
list(APPEND SOURCES optional/optional_std.hpp)
46+
endif()
47+
3948
add_subdirectory(third_party/curl)
4049
add_subdirectory(third_party/hdr_histogram)
4150
add_subdirectory(third_party/http-parser)

src/connection.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include "socket.hpp"
2323
#include "stream_manager.hpp"
2424

25-
#include <optional>
25+
#include "optional.hpp"
2626

2727
namespace datastax { namespace internal { namespace core {
2828

@@ -197,7 +197,7 @@ class Connection : public RefCounted<Connection> {
197197
*/
198198
void set_listener(ConnectionListener* listener = NULL);
199199

200-
std::optional<int32_t> shard_id() const { return shard_id_opt_; }
200+
CassOptional<int32_t> shard_id() const { return shard_id_opt_; }
201201
void set_shard_id(int32_t shard_id) {
202202
shard_id_opt_ = shard_id;
203203
}
@@ -248,7 +248,7 @@ class Connection : public RefCounted<Connection> {
248248
ProtocolVersion protocol_version_;
249249
String keyspace_;
250250

251-
std::optional<int32_t> shard_id_opt_;
251+
CassOptional<int32_t> shard_id_opt_;
252252

253253
unsigned int idle_timeout_secs_;
254254
unsigned int heartbeat_interval_secs_;

src/host.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
#include <math.h>
3535
#include <stdint.h>
36-
#include <optional>
36+
#include "optional.hpp"
3737

3838
namespace datastax { namespace internal { namespace core {
3939

@@ -126,7 +126,7 @@ class Host : public RefCounted<Host> {
126126
dc_id_ = dc_id;
127127
}
128128

129-
std::optional<ShardingInfo> sharding_info() const { return sharding_info_opt_; }
129+
CassOptional<ShardingInfo> sharding_info() const { return sharding_info_opt_; }
130130
void set_sharding_info(ShardingInfo si) {
131131
sharding_info_opt_ = std::move(si);
132132
}
@@ -219,7 +219,7 @@ class Host : public RefCounted<Host> {
219219
Vector<String> tokens_;
220220
Atomic<int32_t> connection_count_;
221221
Atomic<int32_t> inflight_request_count_;
222-
std::optional<ShardingInfo> sharding_info_opt_;
222+
CassOptional<ShardingInfo> sharding_info_opt_;
223223

224224
ScopedPtr<LatencyTracker> latency_tracker_;
225225

src/optional.hpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright (C) 2020 ScyllaDB
3+
*
4+
* This file is part of Scylla.
5+
*
6+
* Scylla is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU Affero General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* Scylla is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with Scylla. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
20+
#ifndef DATASTAX_INTERNAL_OPTIONAL_HPP
21+
#define DATASTAX_INTERNAL_OPTIONAL_HPP
22+
23+
#include "driver_config.hpp"
24+
25+
#if CASS_CPP_STANDARD >= 17
26+
#include "optional/optional_std.hpp"
27+
#else
28+
#include "optional/optional_akrzemi.hpp"
29+
#endif
30+
31+
#endif /* DATASTAX_INTERNAL_OPTIONAL_HPP */

0 commit comments

Comments
 (0)