Skip to content

Commit

Permalink
build: Fallback to C++11
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jul-stas committed Jul 30, 2020
1 parent 8dcb69e commit c41faa4
Show file tree
Hide file tree
Showing 13 changed files with 1,197 additions and 24 deletions.
13 changes: 6 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 2.8.12)
cmake_minimum_required(VERSION 3.1)
project(cassandra C CXX)

set(CASS_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR})
Expand Down Expand Up @@ -43,10 +43,12 @@ 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" ON)
option(CASS_USE_STD_ATOMIC "Use std::atomic library" ON)
option(CASS_USE_ZLIB "Use zlib" ON)
option(CASS_USE_TIMERFD "Use timerfd (Linux only)" ON)

set(CASS_CPP_STANDARD "11" CACHE STRING "C++ standard (11, 14, 17, etc.)")

# Handle testing dependencies
if(CASS_BUILD_TESTS)
# Enable integration and unit tests
Expand Down Expand Up @@ -161,10 +163,10 @@ endif()
# Top-level compiler flags
#------------------------

set (CMAKE_CXX_STANDARD ${CASS_CPP_STANDARD})

if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR
"${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
# Enable C++17 support by default
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")

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

# Enable C++17 support by default
add_definitions(/std:c++17)

# Determine if multicore compilation should be enabled
if(CASS_MULTICORE_COMPILATION)
# Default multicore compilation with effective processors (see https://msdn.microsoft.com/en-us/library/bb385193.aspx)
Expand Down
1 change: 1 addition & 0 deletions driver_config.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#cmakedefine HAVE_KERBEROS
#cmakedefine HAVE_OPENSSL
#cmakedefine HAVE_STD_ATOMIC
#cmakedefine CASS_CPP_STANDARD @CASS_CPP_STANDARD@
#cmakedefine HAVE_BOOST_ATOMIC
#cmakedefine HAVE_NOSIGPIPE
#cmakedefine HAVE_SIGTIMEDWAIT
Expand Down
File renamed without changes.
23 changes: 23 additions & 0 deletions examples/licenses/boost-1.0.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Boost Software License - Version 1.0 - August 17th, 2003

Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:

The copyright notices in the Software and this entire statement, including
the above license grant, this restriction and the following disclaimer,
must be included in all copies of the Software, in whole or in part, and
all derivative works of the Software, unless such copies or derivative
works are solely in the form of machine-executable object code generated by
a source language processor.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
9 changes: 9 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ else()
endif()
endif()

# Determine `optional` library to include
if(CMAKE_CXX_STANDARD LESS 17)
message(STATUS "Using akrzemi's `optional` implementation")
list(APPEND SOURCES optional/optional_akrzemi.hpp)
else()
message(STATUS "Using std::optional library")
list(APPEND SOURCES optional/optional_std.hpp)
endif()

add_subdirectory(third_party/curl)
add_subdirectory(third_party/hdr_histogram)
add_subdirectory(third_party/http-parser)
Expand Down
6 changes: 3 additions & 3 deletions src/connection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "socket.hpp"
#include "stream_manager.hpp"

#include <optional>
#include "optional.hpp"

namespace datastax { namespace internal { namespace core {

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

std::optional<int32_t> shard_id() const { return shard_id_opt_; }
CassOptional<int32_t> shard_id() const { return shard_id_opt_; }
void set_shard_id(int32_t shard_id) {
shard_id_opt_ = shard_id;
}
Expand Down Expand Up @@ -248,7 +248,7 @@ class Connection : public RefCounted<Connection> {
ProtocolVersion protocol_version_;
String keyspace_;

std::optional<int32_t> shard_id_opt_;
CassOptional<int32_t> shard_id_opt_;

unsigned int idle_timeout_secs_;
unsigned int heartbeat_interval_secs_;
Expand Down
6 changes: 3 additions & 3 deletions src/host.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

#include <math.h>
#include <stdint.h>
#include <optional>
#include "optional.hpp"

namespace datastax { namespace internal { namespace core {

Expand Down Expand Up @@ -126,7 +126,7 @@ class Host : public RefCounted<Host> {
dc_id_ = dc_id;
}

std::optional<ShardingInfo> sharding_info() const { return sharding_info_opt_; }
CassOptional<ShardingInfo> sharding_info() const { return sharding_info_opt_; }
void set_sharding_info(ShardingInfo si) {
sharding_info_opt_ = std::move(si);
}
Expand Down Expand Up @@ -219,7 +219,7 @@ class Host : public RefCounted<Host> {
Vector<String> tokens_;
Atomic<int32_t> connection_count_;
Atomic<int32_t> inflight_request_count_;
std::optional<ShardingInfo> sharding_info_opt_;
CassOptional<ShardingInfo> sharding_info_opt_;

ScopedPtr<LatencyTracker> latency_tracker_;

Expand Down
31 changes: 31 additions & 0 deletions src/optional.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright (C) 2020 ScyllaDB
*
* This file is part of Scylla.
*
* Scylla is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Scylla is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Scylla. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef DATASTAX_INTERNAL_OPTIONAL_HPP
#define DATASTAX_INTERNAL_OPTIONAL_HPP

#include "driver_config.hpp"

#if CASS_CPP_STANDARD >= 17
#include "optional/optional_std.hpp"
#else
#include "optional/optional_akrzemi.hpp"
#endif

#endif /* DATASTAX_INTERNAL_OPTIONAL_HPP */
Loading

0 comments on commit c41faa4

Please sign in to comment.