diff --git a/CMakeLists.txt b/CMakeLists.txt index 11f50fed..919eb57f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 $) 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() diff --git a/cmake/compiler.cmake b/cmake/compiler.cmake index 3a5c32d0..7607c5dc 100644 --- a/cmake/compiler.cmake +++ b/cmake/compiler.cmake @@ -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}) diff --git a/src/internals.h b/src/internals.h index e07a31b3..44e5ebe9 100644 --- a/src/internals.h +++ b/src/internals.h @@ -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; diff --git a/src/osal.h b/src/osal.h index b5121ef7..061e5033 100644 --- a/src/osal.h +++ b/src/osal.h @@ -56,18 +56,21 @@ #include #include -/* C11 stdalign.h */ +/* C11' alignas() */ #if __has_include() #include -#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 */