mirror of
https://github.com/isar/libmdbx.git
synced 2024-12-28 18:18:49 +08:00
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:
parent
1c409a38d3
commit
79e1cc3bbc
@ -365,7 +365,11 @@ endif()
|
||||
if(NOT DEFINED MDBX_C_STANDARD)
|
||||
# MSVC >= 19.28 (Microsoft Visual Studio 16.8) is mad!
|
||||
# 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)
|
||||
else()
|
||||
set(MDBX_C_STANDARD 11)
|
||||
@ -573,8 +577,10 @@ macro(target_setup_options TARGET)
|
||||
set_target_properties(${TARGET} PROPERTIES
|
||||
INTERPROCEDURAL_OPTIMIZATION $<BOOL:${INTERPROCEDURAL_OPTIMIZATION}>)
|
||||
endif()
|
||||
set_target_properties(${TARGET} PROPERTIES
|
||||
C_STANDARD ${MDBX_C_STANDARD} C_STANDARD_REQUIRED ON)
|
||||
if(NOT C_FALLBACK_GNU11 AND NOT C_FALLBACK_11)
|
||||
set_target_properties(${TARGET} PROPERTIES
|
||||
C_STANDARD ${MDBX_C_STANDARD} C_STANDARD_REQUIRED ON)
|
||||
endif()
|
||||
if(MDBX_BUILD_CXX)
|
||||
set_target_properties(${TARGET} PROPERTIES
|
||||
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)
|
||||
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
|
||||
C_STANDARD ${MDBX_C_STANDARD} C_STANDARD_REQUIRED ON)
|
||||
endif()
|
||||
|
@ -264,9 +264,24 @@ endif()
|
||||
if(CMAKE_CXX_COMPILER_LOADED)
|
||||
list(FIND CMAKE_CXX_COMPILE_FEATURES cxx_std_11 HAS_CXX11)
|
||||
if(HAS_CXX11 LESS 0)
|
||||
check_compiler_flag("-std=gnu++11" CXX_FALLBACK_STDGNU11)
|
||||
if(NOT CXX_FALLBACK_STDGNU11)
|
||||
check_compiler_flag("-std=c++11" CXX_FALLBACK_STD11)
|
||||
check_cxx_compiler_flag("-std=gnu++11" CXX_FALLBACK_GNU11)
|
||||
if(NOT CXX_FALLBACK_GNU11)
|
||||
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()
|
||||
@ -536,14 +551,24 @@ macro(setup_compile_flags)
|
||||
if(CMAKE_CXX_COMPILER_LOADED)
|
||||
set(CXX_FLAGS ${INITIAL_CMAKE_CXX_FLAGS})
|
||||
# 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")
|
||||
elseif(CXX_FALLBACK_STD11)
|
||||
elseif(CXX_FALLBACK_11)
|
||||
add_compile_flags("CXX" "-std=c++11")
|
||||
endif()
|
||||
endif()
|
||||
if(CMAKE_C_COMPILER_LOADED)
|
||||
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()
|
||||
set(EXE_LINKER_FLAGS ${INITIAL_CMAKE_EXE_LINKER_FLAGS})
|
||||
set(SHARED_LINKER_FLAGS ${INITIAL_CMAKE_SHARED_LINKER_FLAGS})
|
||||
|
@ -674,19 +674,19 @@ typedef struct MDBX_lockinfo {
|
||||
/* Marker to distinguish uniqueness of DB/CLK. */
|
||||
MDBX_atomic_uint64_t mti_bait_uniqueness;
|
||||
|
||||
alignas(MDBX_CACHELINE_SIZE) /* cacheline ---------------------------------*/
|
||||
MDBX_ALIGNAS(MDBX_CACHELINE_SIZE) /* cacheline ----------------------------*/
|
||||
|
||||
#if MDBX_ENABLE_PGOP_STAT
|
||||
/* Statistics of costly ops of all (running, completed and aborted)
|
||||
* transactions */
|
||||
MDBX_pgop_stat_t mti_pgop_stat;
|
||||
/* Statistics of costly ops of all (running, completed and aborted)
|
||||
* transactions */
|
||||
MDBX_pgop_stat_t mti_pgop_stat;
|
||||
#endif /* MDBX_ENABLE_PGOP_STAT*/
|
||||
|
||||
alignas(MDBX_CACHELINE_SIZE) /* cacheline ---------------------------------*/
|
||||
MDBX_ALIGNAS(MDBX_CACHELINE_SIZE) /* cacheline ----------------------------*/
|
||||
|
||||
/* Write transaction lock. */
|
||||
#if MDBX_LOCKING > 0
|
||||
mdbx_ipclock_t mti_wlock;
|
||||
mdbx_ipclock_t mti_wlock;
|
||||
#endif /* MDBX_LOCKING > 0 */
|
||||
|
||||
atomic_txnid_t mti_oldest_reader;
|
||||
@ -708,11 +708,11 @@ typedef struct MDBX_lockinfo {
|
||||
/* Shared anchor for tracking readahead edge and enabled/disabled status. */
|
||||
pgno_t mti_readahead_anchor;
|
||||
|
||||
alignas(MDBX_CACHELINE_SIZE) /* cacheline ---------------------------------*/
|
||||
MDBX_ALIGNAS(MDBX_CACHELINE_SIZE) /* cacheline ----------------------------*/
|
||||
|
||||
/* Readeaders registration lock. */
|
||||
#if MDBX_LOCKING > 0
|
||||
mdbx_ipclock_t mti_rlock;
|
||||
mdbx_ipclock_t mti_rlock;
|
||||
#endif /* MDBX_LOCKING > 0 */
|
||||
|
||||
/* The number of slots that have been used in the reader table.
|
||||
@ -723,8 +723,8 @@ typedef struct MDBX_lockinfo {
|
||||
|
||||
#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \
|
||||
(!defined(__cplusplus) && defined(_MSC_VER))
|
||||
alignas(MDBX_CACHELINE_SIZE) /* cacheline ---------------------------------*/
|
||||
MDBX_reader mti_readers[] /* dynamic size */;
|
||||
MDBX_ALIGNAS(MDBX_CACHELINE_SIZE) /* cacheline ----------------------------*/
|
||||
MDBX_reader mti_readers[] /* dynamic size */;
|
||||
#endif /* C99 */
|
||||
} MDBX_lockinfo;
|
||||
|
||||
|
21
src/osal.h
21
src/osal.h
@ -56,18 +56,21 @@
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
/* C11 stdalign.h */
|
||||
/* C11' alignas() */
|
||||
#if __has_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
|
||||
#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 */
|
||||
|
Loading…
x
Reference in New Issue
Block a user