Support rocksdb 11
rocksdb 11 needs C++20 for its headers and hands the database back from
DB::Open() and DB::OpenForReadOnly() as a unique_ptr instead of a raw pointer.
The newest standard the compiler knows is used now, and the two open calls go
through a macro that adapts to the rocksdb version, so 7, 10 and 11 all build.
Verified with rocksdb 7.8.3 (debian), 10.2.1 (fedora) and 11.0.4 (alpine,
musl): no warnings, ctest passes, and reading a database written by rocksdb
5.11 still gives identical results for 251 word ids.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Change-Id: If16e6aa2fbe8478f3260e358dce53b2dc5144d9d
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 6fccb26..84a14c4 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -3,8 +3,14 @@
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fno-rtti")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g")
-# RocksDB requires C++17 since version 7
-set(CMAKE_CXX_STANDARD 17)
+# RocksDB requires C++17 since version 7 and C++20 since version 11, so use the
+# newest standard the compiler knows. Nothing here depends on it, this only has
+# to satisfy the rocksdb headers.
+if ("cxx_std_20" IN_LIST CMAKE_CXX_COMPILE_FEATURES)
+ set(CMAKE_CXX_STANDARD 20)
+else()
+ set(CMAKE_CXX_STANDARD 17)
+endif()
set(CMAKE_CXX_STANDARD_REQUIRED ON)
include(GNUInstallDirs)