From cc6610f42c4d4a6fa2494eef5fe93942075bd340 Mon Sep 17 00:00:00 2001 From: Leonid Yuriev Date: Thu, 24 Jun 2021 15:41:54 +0300 Subject: [PATCH] mdbx: more/refine C++ crutches for mad MSVC compiler. --- CMakeLists.txt | 12 +++++++++++- mdbx.h++ | 14 ++++++++------ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0aad9f88..e74432b0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -539,6 +539,13 @@ else() message(STATUS "Use C${MDBX_C_STANDARD} for libmdbx but C++ portion is disabled") endif() +if(SUBPROJECT AND MSVC) + if(MSVC_VERSION LESS 1900) + message(FATAL_ERROR "At least \"Microsoft C/C++ Compiler\" version 19.0.24234.1 (Visual Studio 2015 Update 3) is required.") + endif() + add_compile_options("/utf-8") +endif() + macro(target_setup_options TARGET) if(DEFINED INTERPROCEDURAL_OPTIMIZATION) set_target_properties(${TARGET} PROPERTIES @@ -549,6 +556,9 @@ macro(target_setup_options TARGET) if(MDBX_BUILD_CXX) set_target_properties(${TARGET} PROPERTIES CXX_STANDARD ${MDBX_CXX_STANDARD} CXX_STANDARD_REQUIRED ON) + if(MSVC AND NOT MSVC_VERSION LESS 1910) + target_compile_options(${TARGET} INTERFACE "/Zc:__cplusplus") + endif() endif() if(CC_HAS_FASTMATH) target_compile_options(${TARGET} PRIVATE "-ffast-math") @@ -557,7 +567,7 @@ macro(target_setup_options TARGET) target_compile_options(${TARGET} PRIVATE "-fvisibility=hidden") endif() if(BUILD_FOR_NATIVE_CPU AND CC_HAS_ARCH_NATIVE) - target_compile_options(${TARGET} PUBLIC "-march=native") + target_compile_options(${TARGET} PRIVATE "-march=native") endif() endmacro() diff --git a/mdbx.h++ b/mdbx.h++ index fce43a41..c70e6fd4 100644 --- a/mdbx.h++ +++ b/mdbx.h++ @@ -14,12 +14,14 @@ #pragma once -#if (!defined(__cplusplus) || __cplusplus < 201103L) && \ - !(defined( \ - _MSC_VER) /* MSVC is mad and don't define __cplusplus properly */ \ - && _MSC_VER == 1900) -#error "C++11 or better is required" -#endif +#if !defined(__cplusplus) || __cplusplus < 201103L +#if !defined(_MSC_VER) || _MSC_VER < 1900 +#error "C++11 compiler or better is required" +#elif _MSC_VER >= 1910 +#error \ + "Please add ` /Zc:__cplusplus` to MSVC compiler options to enforce it conform ISO C++" +#endif /* MSVC is mad and don't define __cplusplus properly */ +#endif /* __cplusplus < 201103L */ #if (defined(_WIN32) || defined(_WIN64)) && MDBX_WITHOUT_MSVC_CRT #error \