From 260655b4c294991fe03bf6ab8b6d722ccfc41d32 Mon Sep 17 00:00:00 2001 From: costan Date: Mon, 9 Apr 2018 16:41:02 -0700 Subject: [PATCH] Define LEVELDB_HAS_PORT_CONFIG_H for old compilers. The CMake-based build relies on __has_include, which is standardized in C++17. Unfortunately, __has_include is available without requiring --std=c++17 on all the compilers on CI, so this problem was not caught. Fixes https://github.com/google/leveldb/issues/572 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=192208842 --- CMakeLists.txt | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 271caa7..cc1022f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,6 +53,14 @@ int main() { return 0; } " HAVE_CLANG_THREAD_SAFETY) set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS}) +# Test whether C++17 __has_include is available. +check_cxx_source_compiles(" +#if defined(__has_include) && __has_include() +#include +#endif +int main() { std::string str; return 0; } +" HAVE_CXX17_HAS_INCLUDE) + set(LEVELDB_PUBLIC_INCLUDE_DIR "include/leveldb") set(LEVELDB_PORT_CONFIG_DIR "include/port") @@ -85,6 +93,12 @@ target_sources(leveldb_port_posix $ $ ) +if (NOT HAVE_CXX17_HAS_INCLUDE) + target_compile_definitions(leveldb_port_posix + PRIVATE + LEVELDB_HAS_PORT_CONFIG_H=1 + ) +endif(NOT HAVE_CXX17_HAS_INCLUDE) if(BUILD_SHARED_LIBS) set_property(TARGET leveldb_port_posix PROPERTY POSITION_INDEPENDENT_CODE ON) endif(BUILD_SHARED_LIBS) @@ -199,6 +213,13 @@ target_compile_definitions(leveldb # Used by port/port.h. LEVELDB_PLATFORM_POSIX=1 ) +if (NOT HAVE_CXX17_HAS_INCLUDE) + target_compile_definitions(leveldb + PRIVATE + LEVELDB_HAS_PORT_CONFIG_H=1 + ) +endif(NOT HAVE_CXX17_HAS_INCLUDE) + if(BUILD_SHARED_LIBS) target_compile_definitions(leveldb PUBLIC @@ -263,6 +284,12 @@ if(LEVELDB_BUILD_TESTS) PRIVATE LEVELDB_PLATFORM_POSIX=1 ) + if (NOT HAVE_CXX17_HAS_INCLUDE) + target_compile_definitions("${test_target_name}" + PRIVATE + LEVELDB_HAS_PORT_CONFIG_H=1 + ) + endif(NOT HAVE_CXX17_HAS_INCLUDE) add_test(NAME "${test_target_name}" COMMAND "${test_target_name}") endfunction(leveldb_test) @@ -336,6 +363,12 @@ if(LEVELDB_BUILD_BENCHMARKS) PRIVATE LEVELDB_PLATFORM_POSIX=1 ) + if (NOT HAVE_CXX17_HAS_INCLUDE) + target_compile_definitions("${bench_target_name}" + PRIVATE + LEVELDB_HAS_PORT_CONFIG_H=1 + ) + endif(NOT HAVE_CXX17_HAS_INCLUDE) endfunction(leveldb_benchmark) if(NOT BUILD_SHARED_LIBS)