Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C++20 compatibility #6697

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
af91b57
Fix implicit capture of ‘this’ via ‘[=]’ is deprecated in C++20
syoliver-se Mar 22, 2020
880549c
Allow to choose C++ version in cmake command line
syoliver-se Mar 22, 2020
4a1df6e
Fix deprecated copy warning in gcc 9
syoliver-se Apr 5, 2020
2756589
Minimal Rebuild is deprecated in visual studio since 2015 and is forb…
syoliver-se Apr 5, 2020
cea96d0
random_shuffle is deprecated in C++14 and removed in C++17
syoliver-se Apr 5, 2020
4e46260
Fix implicit this lambda capture deprecation
syoliver-se Apr 5, 2020
96f7359
Add implicit lambda capture in raw makefile
syoliver-se Apr 6, 2020
5962870
Add MSVC2019 to AppVeyor
syoliver-se Apr 6, 2020
d31e395
Add gcc-9 with c++11 and c++20 to travis
syoliver-se Apr 6, 2020
43eee91
Merge remote-tracking branch 'origin/master' into pr/6648
pdillinger Apr 10, 2020
87f3151
Reduce cmake variants built on each PR
pdillinger Apr 10, 2020
831fb29
Fix whitespace / noeol in CMakeLists.txt
pdillinger Apr 10, 2020
3de7ca9
Tweak so that no configuration change is needed
pdillinger Apr 10, 2020
c9e951e
Unified RandomShuffle
pdillinger Apr 13, 2020
756ea7f
Remove 'this' capture from folly import
pdillinger Apr 14, 2020
1b7b028
Remove an unnecessary capture spec
pdillinger Apr 14, 2020
dda5107
make format
pdillinger Apr 14, 2020
427a33d
Merge remote-tracking branch 'origin/master' into cxx20
pdillinger Apr 14, 2020
882a9d5
Fixup after merge
pdillinger Apr 14, 2020
c19c8ac
Better capture solution for Baton.h
pdillinger Apr 14, 2020
da5b61e
Actually, just use explicit capture
pdillinger Apr 14, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Allow to choose C++ version in cmake command line
  • Loading branch information
syoliver-se committed Apr 5, 2020
commit 880549c331e31cd8354eda880a0e84cbbe7b3cc1
59 changes: 34 additions & 25 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ else()
option(WITH_FOLLY_DISTRIBUTED_MUTEX "build with folly::DistributedMutex" OFF)
endif()

if( NOT DEFINED CMAKE_CXX_STANDARD )
set(CMAKE_CXX_STANDARD 11)
endif()

include(CMakeDependentOption)
CMAKE_DEPENDENT_OPTION(WITH_GFLAGS "build with GFlags" ON
"NOT MSVC;NOT MINGW" OFF)
Expand Down Expand Up @@ -191,7 +195,6 @@ else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-format -fno-asynchronous-unwind-tables")
add_definitions(-D_POSIX_C_SOURCE=1)
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-omit-frame-pointer")
include(CheckCXXCompilerFlag)
Expand Down Expand Up @@ -255,25 +258,6 @@ if(NOT MSVC)
set(CMAKE_REQUIRED_FLAGS "-msse4.2 -mpclmul")
endif()

CHECK_CXX_SOURCE_COMPILES("

struct test {
int lambda() {
return [=]() { return value_; }();
}

int value_;
};

int main() {
test t;
t.lambda();
}
" HAVE_IMPLICIT_THIS_LAMBDA_CAPTURE)
if(HAVE_IMPLICIT_THIS_LAMBDA_CAPTURE)
add_definitions(-DROCKSDB_SUPPORT_IMPLICIT_THIS_LAMBDA_CAPTURE)
endif()

CHECK_CXX_SOURCE_COMPILES("
#include <cstdint>
#include <nmmintrin.h>
Expand Down Expand Up @@ -515,6 +499,32 @@ if(HAVE_AUXV_GETAUXVAL)
add_definitions(-DROCKSDB_AUXV_GETAUXVAL_PRESENT)
endif()

# Workaround to get c++ std version option coming from CMAKE_CXX_STANDARD for try_compile
include(CxxFlags)
get_cxx_std_flags(CMAKE_REQUIRED_FLAGS)

CHECK_CXX_SOURCE_COMPILES("
struct test {
int lambda() {
return [=]() { return value_; }();
}

int value_;
};

int main() {
test t;
t.lambda();
}
" HAVE_IMPLICIT_THIS_LAMBDA_CAPTURE
)

unset(CMAKE_REQUIRED_FLAGS)

if(HAVE_IMPLICIT_THIS_LAMBDA_CAPTURE)
add_definitions(-DROCKSDB_SUPPORT_IMPLICIT_THIS_LAMBDA_CAPTURE)
endif()

include_directories(${PROJECT_SOURCE_DIR})
include_directories(${PROJECT_SOURCE_DIR}/include)
include_directories(SYSTEM ${PROJECT_SOURCE_DIR}/third-party/gtest-1.8.1/fused-src)
Expand Down Expand Up @@ -868,7 +878,6 @@ if(ROCKSDB_BUILD_SHARED)
LINKER_LANGUAGE CXX
VERSION ${rocksdb_VERSION}
SOVERSION ${rocksdb_VERSION_MAJOR}
CXX_STANDARD 11
OUTPUT_NAME "rocksdb")
endif()
endif()
Expand Down Expand Up @@ -961,7 +970,7 @@ if(WITH_TESTS)
add_library(testharness STATIC
test_util/testharness.cc)
target_link_libraries(testharness gtest)

set(TESTS
cache/cache_test.cc
cache/lru_cache_test.cc
Expand Down Expand Up @@ -1145,7 +1154,7 @@ if(WITH_TESTS)
PROPERTIES EXCLUDE_FROM_DEFAULT_BUILD_RELEASE 1
EXCLUDE_FROM_DEFAULT_BUILD_MINRELEASE 1
EXCLUDE_FROM_DEFAULT_BUILD_RELWITHDEBINFO 1
)
)

foreach(sourcefile ${TESTS})
get_filename_component(exename ${sourcefile} NAME_WE)
Expand All @@ -1155,7 +1164,7 @@ if(WITH_TESTS)
EXCLUDE_FROM_DEFAULT_BUILD_MINRELEASE 1
EXCLUDE_FROM_DEFAULT_BUILD_RELWITHDEBINFO 1
OUTPUT_NAME ${exename}${ARTIFACT_SUFFIX}
)
)
target_link_libraries(${CMAKE_PROJECT_NAME}_${exename}${ARTIFACT_SUFFIX} testutillib${ARTIFACT_SUFFIX} testharness gtest ${ROCKSDB_LIB})
if(NOT "${exename}" MATCHES "db_sanity_test")
add_test(NAME ${exename} COMMAND ${exename}${ARTIFACT_SUFFIX})
Expand Down Expand Up @@ -1235,4 +1244,4 @@ if(WITH_TOOLS)
add_subdirectory(db_stress_tool)
add_custom_target(tools
DEPENDS ${tool_deps})
endif()
endif()
7 changes: 7 additions & 0 deletions cmake/modules/CxxFlags.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
macro(get_cxx_std_flags FLAGS_VARIABLE)
if( CMAKE_CXX_STANDARD_REQUIRED )
set(${FLAGS_VARIABLE} ${CMAKE_CXX${CMAKE_CXX_STANDARD}_STANDARD_COMPILE_OPTION})
else()
set(${FLAGS_VARIABLE} ${CMAKE_CXX${CMAKE_CXX_STANDARD}_EXTENSION_COMPILE_OPTION})
endif()
endmacro()
9 changes: 9 additions & 0 deletions third-party/folly/folly/synchronization/Baton.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,12 @@ class Baton {
bool tryWaitSlow(
const std::chrono::time_point<Clock, Duration>& deadline,
const WaitOptions& opt) noexcept {

#ifdef ROCKSDB_SUPPORT_IMPLICIT_THIS_LAMBDA_CAPTURE
switch (detail::spin_pause_until(deadline, opt, [=] { return ready(); })) {
#else
switch (detail::spin_pause_until(deadline, opt, [=, this] { return ready(); })) {
#endif
case detail::spin_result::success:
return true;
case detail::spin_result::timeout:
Expand All @@ -259,7 +264,11 @@ class Baton {
}

if (!MayBlock) {
#ifdef ROCKSDB_SUPPORT_IMPLICIT_THIS_LAMBDA_CAPTURE
switch (detail::spin_yield_until(deadline, [=] { return ready(); })) {
#else
switch (detail::spin_yield_until(deadline, [=, this] { return ready(); })) {
#endif
case detail::spin_result::success:
return true;
case detail::spin_result::timeout:
Expand Down