mdbx: more/refine C++ crutches for mad MSVC compiler.

This commit is contained in:
Leonid Yuriev 2021-06-24 15:41:54 +03:00
parent 77a1f32e2a
commit cc6610f42c
2 changed files with 19 additions and 7 deletions

View File

@ -539,6 +539,13 @@ else()
message(STATUS "Use C${MDBX_C_STANDARD} for libmdbx but C++ portion is disabled") message(STATUS "Use C${MDBX_C_STANDARD} for libmdbx but C++ portion is disabled")
endif() 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) macro(target_setup_options TARGET)
if(DEFINED INTERPROCEDURAL_OPTIMIZATION) if(DEFINED INTERPROCEDURAL_OPTIMIZATION)
set_target_properties(${TARGET} PROPERTIES set_target_properties(${TARGET} PROPERTIES
@ -549,6 +556,9 @@ macro(target_setup_options TARGET)
if(MDBX_BUILD_CXX) if(MDBX_BUILD_CXX)
set_target_properties(${TARGET} PROPERTIES set_target_properties(${TARGET} PROPERTIES
CXX_STANDARD ${MDBX_CXX_STANDARD} CXX_STANDARD_REQUIRED ON) 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() endif()
if(CC_HAS_FASTMATH) if(CC_HAS_FASTMATH)
target_compile_options(${TARGET} PRIVATE "-ffast-math") target_compile_options(${TARGET} PRIVATE "-ffast-math")
@ -557,7 +567,7 @@ macro(target_setup_options TARGET)
target_compile_options(${TARGET} PRIVATE "-fvisibility=hidden") target_compile_options(${TARGET} PRIVATE "-fvisibility=hidden")
endif() endif()
if(BUILD_FOR_NATIVE_CPU AND CC_HAS_ARCH_NATIVE) 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() endif()
endmacro() endmacro()

View File

@ -14,12 +14,14 @@
#pragma once #pragma once
#if (!defined(__cplusplus) || __cplusplus < 201103L) && \ #if !defined(__cplusplus) || __cplusplus < 201103L
!(defined( \ #if !defined(_MSC_VER) || _MSC_VER < 1900
_MSC_VER) /* MSVC is mad and don't define __cplusplus properly */ \ #error "C++11 compiler or better is required"
&& _MSC_VER == 1900) #elif _MSC_VER >= 1910
#error "C++11 or better is required" #error \
#endif "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 #if (defined(_WIN32) || defined(_WIN64)) && MDBX_WITHOUT_MSVC_CRT
#error \ #error \