mdbx: add workaround for old MSVC and/or old Windows SDK.

Resolves https://github.com/erthink/libmdbx/issues/265.

Change-Id: I295b5d9d5ecd670ccf258791bf87379a3ca17f21
This commit is contained in:
Leonid Yuriev 2022-01-31 23:29:03 +03:00
parent 1c409a38d3
commit 79e1cc3bbc
4 changed files with 62 additions and 28 deletions

View File

@ -365,7 +365,11 @@ endif()
if(NOT DEFINED MDBX_C_STANDARD) if(NOT DEFINED MDBX_C_STANDARD)
# MSVC >= 19.28 (Microsoft Visual Studio 16.8) is mad! # MSVC >= 19.28 (Microsoft Visual Studio 16.8) is mad!
# It unable process Windows SDK headers in the C11 mode! # It unable process Windows SDK headers in the C11 mode!
if(HAS_C11 LESS 0 OR (MSVC AND MSVC_VERSION GREATER 1927)) if(MSVC AND MSVC_VERSION GREATER 1927 AND NOT MSVC_VERSION GREATER 1929)
set(MDBX_C_STANDARD 99)
set(C_FALLBACK_11 OFF)
set(C_FALLBACK_GNU11 OFF)
elseif(HAS_C11 LESS 0 AND NOT C_FALLBACK_GNU11 AND NOT C_FALLBACK_11)
set(MDBX_C_STANDARD 99) set(MDBX_C_STANDARD 99)
else() else()
set(MDBX_C_STANDARD 11) set(MDBX_C_STANDARD 11)
@ -573,8 +577,10 @@ macro(target_setup_options TARGET)
set_target_properties(${TARGET} PROPERTIES set_target_properties(${TARGET} PROPERTIES
INTERPROCEDURAL_OPTIMIZATION $<BOOL:${INTERPROCEDURAL_OPTIMIZATION}>) INTERPROCEDURAL_OPTIMIZATION $<BOOL:${INTERPROCEDURAL_OPTIMIZATION}>)
endif() endif()
if(NOT C_FALLBACK_GNU11 AND NOT C_FALLBACK_11)
set_target_properties(${TARGET} PROPERTIES set_target_properties(${TARGET} PROPERTIES
C_STANDARD ${MDBX_C_STANDARD} C_STANDARD_REQUIRED ON) C_STANDARD ${MDBX_C_STANDARD} C_STANDARD_REQUIRED ON)
endif()
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)
@ -685,7 +691,7 @@ if(MDBX_BUILD_TOOLS)
foreach(TOOL mdbx_chk mdbx_copy mdbx_stat mdbx_dump mdbx_load mdbx_drop) foreach(TOOL mdbx_chk mdbx_copy mdbx_stat mdbx_dump mdbx_load mdbx_drop)
add_executable(${TOOL} mdbx.h ${MDBX_SOURCE_DIR}/${TOOL}.c ${WINGETOPT_SRC}) add_executable(${TOOL} mdbx.h ${MDBX_SOURCE_DIR}/${TOOL}.c ${WINGETOPT_SRC})
if(MDBX_C_STANDARD) if(NOT C_FALLBACK_GNU11 AND NOT C_FALLBACK_11)
set_target_properties(${TOOL} PROPERTIES set_target_properties(${TOOL} PROPERTIES
C_STANDARD ${MDBX_C_STANDARD} C_STANDARD_REQUIRED ON) C_STANDARD ${MDBX_C_STANDARD} C_STANDARD_REQUIRED ON)
endif() endif()

View File

@ -264,9 +264,24 @@ endif()
if(CMAKE_CXX_COMPILER_LOADED) if(CMAKE_CXX_COMPILER_LOADED)
list(FIND CMAKE_CXX_COMPILE_FEATURES cxx_std_11 HAS_CXX11) list(FIND CMAKE_CXX_COMPILE_FEATURES cxx_std_11 HAS_CXX11)
if(HAS_CXX11 LESS 0) if(HAS_CXX11 LESS 0)
check_compiler_flag("-std=gnu++11" CXX_FALLBACK_STDGNU11) check_cxx_compiler_flag("-std=gnu++11" CXX_FALLBACK_GNU11)
if(NOT CXX_FALLBACK_STDGNU11) if(NOT CXX_FALLBACK_GNU11)
check_compiler_flag("-std=c++11" CXX_FALLBACK_STD11) check_cxx_compiler_flag("-std=c++11" CXX_FALLBACK_11)
endif()
endif()
endif()
# Crutch for mad C compilers and/or CMake to enabling C11
if(CMAKE_C_COMPILER_LOADED)
list(FIND CMAKE_C_COMPILE_FEATURES c_std_11 HAS_C11)
if(HAS_C11 LESS 0)
if (MSVC)
check_c_compiler_flag("/std:c11" C_FALLBACK_11)
else()
check_c_compiler_flag("-std=gnu11" C_FALLBACK_GNU11)
if(NOT C_FALLBACK_GNU11)
check_c_compiler_flag("-std=c11" C_FALLBACK_11)
endif()
endif() endif()
endif() endif()
endif() endif()
@ -536,14 +551,24 @@ macro(setup_compile_flags)
if(CMAKE_CXX_COMPILER_LOADED) if(CMAKE_CXX_COMPILER_LOADED)
set(CXX_FLAGS ${INITIAL_CMAKE_CXX_FLAGS}) set(CXX_FLAGS ${INITIAL_CMAKE_CXX_FLAGS})
# Crutch for old C++ compilers and/or CMake to enabling C++11 # Crutch for old C++ compilers and/or CMake to enabling C++11
if(CXX_FALLBACK_STDGNU11) if(CXX_FALLBACK_GNU11)
add_compile_flags("CXX" "-std=gnu++11") add_compile_flags("CXX" "-std=gnu++11")
elseif(CXX_FALLBACK_STD11) elseif(CXX_FALLBACK_11)
add_compile_flags("CXX" "-std=c++11") add_compile_flags("CXX" "-std=c++11")
endif() endif()
endif() endif()
if(CMAKE_C_COMPILER_LOADED) if(CMAKE_C_COMPILER_LOADED)
set(C_FLAGS ${INITIAL_CMAKE_C_FLAGS}) set(C_FLAGS ${INITIAL_CMAKE_C_FLAGS})
# Crutch for mad C compilers and/or CMake to enabling C11
if(C_FALLBACK_GNU11)
add_compile_flags("C" "-std=gnu11")
elseif(C_FALLBACK_11)
if(MSVC)
add_compile_flags("C" "/std:c11")
else()
add_compile_flags("C" "-std=c11")
endif()
endif()
endif() endif()
set(EXE_LINKER_FLAGS ${INITIAL_CMAKE_EXE_LINKER_FLAGS}) set(EXE_LINKER_FLAGS ${INITIAL_CMAKE_EXE_LINKER_FLAGS})
set(SHARED_LINKER_FLAGS ${INITIAL_CMAKE_SHARED_LINKER_FLAGS}) set(SHARED_LINKER_FLAGS ${INITIAL_CMAKE_SHARED_LINKER_FLAGS})

View File

@ -674,7 +674,7 @@ typedef struct MDBX_lockinfo {
/* Marker to distinguish uniqueness of DB/CLK. */ /* Marker to distinguish uniqueness of DB/CLK. */
MDBX_atomic_uint64_t mti_bait_uniqueness; MDBX_atomic_uint64_t mti_bait_uniqueness;
alignas(MDBX_CACHELINE_SIZE) /* cacheline ---------------------------------*/ MDBX_ALIGNAS(MDBX_CACHELINE_SIZE) /* cacheline ----------------------------*/
#if MDBX_ENABLE_PGOP_STAT #if MDBX_ENABLE_PGOP_STAT
/* Statistics of costly ops of all (running, completed and aborted) /* Statistics of costly ops of all (running, completed and aborted)
@ -682,7 +682,7 @@ typedef struct MDBX_lockinfo {
MDBX_pgop_stat_t mti_pgop_stat; MDBX_pgop_stat_t mti_pgop_stat;
#endif /* MDBX_ENABLE_PGOP_STAT*/ #endif /* MDBX_ENABLE_PGOP_STAT*/
alignas(MDBX_CACHELINE_SIZE) /* cacheline ---------------------------------*/ MDBX_ALIGNAS(MDBX_CACHELINE_SIZE) /* cacheline ----------------------------*/
/* Write transaction lock. */ /* Write transaction lock. */
#if MDBX_LOCKING > 0 #if MDBX_LOCKING > 0
@ -708,7 +708,7 @@ typedef struct MDBX_lockinfo {
/* Shared anchor for tracking readahead edge and enabled/disabled status. */ /* Shared anchor for tracking readahead edge and enabled/disabled status. */
pgno_t mti_readahead_anchor; pgno_t mti_readahead_anchor;
alignas(MDBX_CACHELINE_SIZE) /* cacheline ---------------------------------*/ MDBX_ALIGNAS(MDBX_CACHELINE_SIZE) /* cacheline ----------------------------*/
/* Readeaders registration lock. */ /* Readeaders registration lock. */
#if MDBX_LOCKING > 0 #if MDBX_LOCKING > 0
@ -723,7 +723,7 @@ typedef struct MDBX_lockinfo {
#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \ #if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \
(!defined(__cplusplus) && defined(_MSC_VER)) (!defined(__cplusplus) && defined(_MSC_VER))
alignas(MDBX_CACHELINE_SIZE) /* cacheline ---------------------------------*/ MDBX_ALIGNAS(MDBX_CACHELINE_SIZE) /* cacheline ----------------------------*/
MDBX_reader mti_readers[] /* dynamic size */; MDBX_reader mti_readers[] /* dynamic size */;
#endif /* C99 */ #endif /* C99 */
} MDBX_lockinfo; } MDBX_lockinfo;

View File

@ -56,18 +56,21 @@
#include <string.h> #include <string.h>
#include <time.h> #include <time.h>
/* C11 stdalign.h */ /* C11' alignas() */
#if __has_include(<stdalign.h>) #if __has_include(<stdalign.h>)
#include <stdalign.h> #include <stdalign.h>
#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
#define alignas(N) _Alignas(N)
#elif defined(_MSC_VER)
#define alignas(N) __declspec(align(N))
#elif __has_attribute(__aligned__) || defined(__GNUC__)
#define alignas(N) __attribute__((__aligned__(N)))
#else
#error "FIXME: Required _alignas() or equivalent."
#endif #endif
#if defined(alignas) || defined(__cplusplus)
#define MDBX_ALIGNAS(N) alignas(N)
#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
#define MDBX_ALIGNAS(N) _Alignas(N)
#elif defined(_MSC_VER)
#define MDBX_ALIGNAS(N) __declspec(align(N))
#elif __has_attribute(__aligned__) || defined(__GNUC__)
#define MDBX_ALIGNAS(N) __attribute__((__aligned__(N)))
#else
#error "FIXME: Required alignas() or equivalent."
#endif /* MDBX_ALIGNAS */
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
/* Systems includes */ /* Systems includes */