--- a/configure.cmake +++ b/configure.cmake @@ -135,10 +135,11 @@ IF(NOT LIBRT) MY_SEARCH_LIBS(clock_gettime rt LIBRT) ENDIF() + MY_SEARCH_LIBS(__atomic_load_8 atomic LIBATOMIC) FIND_PACKAGE(Threads) SET(CMAKE_REQUIRED_LIBRARIES - ${LIBM} ${LIBNSL} ${LIBBIND} ${LIBCRYPT} ${LIBSOCKET} ${LIBDL} ${CMAKE_THREAD_LIBS_INIT} ${LIBRT} ${LIBEXECINFO}) + ${LIBM} ${LIBNSL} ${LIBBIND} ${LIBCRYPT} ${LIBSOCKET} ${LIBDL} ${LIBATOMIC} ${CMAKE_THREAD_LIBS_INIT} ${LIBRT} ${LIBEXECINFO}) # Need explicit pthread for gcc -fsanitize=address IF(CMAKE_USE_PTHREADS_INIT AND CMAKE_C_FLAGS MATCHES "-fsanitize=") SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} pthread) @@ -919,14 +920,26 @@ return 0; }" HAVE_GCC_ATOMIC_BUILTINS) -CHECK_CXX_SOURCE_COMPILES(" + +SET(MAIN__ATOMIC_LOAD_N " int main() { long long int var= 1; long long int *ptr= &var; return (int)__atomic_load_n(ptr, __ATOMIC_SEQ_CST); -}" -HAVE_GCC_C11_ATOMICS) +}") +CHECK_CXX_SOURCE_COMPILES("${MAIN__ATOMIC_LOAD_N}" HAVE_GCC_C11_ATOMICS) +IF(HAVE_GCC_C11_ATOMICS AND HAVE_LIBATOMIC) + SET(SAVE_CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES}) + LIST(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES "${LIBATOMIC}") + CHECK_CXX_SOURCE_COMPILES("${MAIN__ATOMIC_LOAD_N}" HAVE_GCC_C11_INLINE_ATOMICS) + IF(HAVE_GCC_C11_INLINE_ATOMICS) + UNSET(HAVE_LIBATOMIC) + UNSET(LIBATOMIC) + ELSE() + SET(CMAKE_REQUIRED_LIBRARIES ${SAVE_CMAKE_REQUIRED_LIBRARIES}) + ENDIF() +ENDIF() IF(WITH_VALGRIND) SET(HAVE_valgrind 1) --- a/mysys/CMakeLists.txt +++ b/mysys/CMakeLists.txt @@ -75,7 +75,7 @@ ADD_CONVENIENCE_LIBRARY(mysys ${MYSYS_SOURCES}) TARGET_LINK_LIBRARIES(mysys dbug strings ${ZLIB_LIBRARY} - ${LIBNSL} ${LIBM} ${LIBRT} ${LIBDL} ${LIBSOCKET} ${LIBEXECINFO} ${CRC32_LIBRARY}) + ${LIBNSL} ${LIBM} ${LIBRT} ${LIBDL} ${LIBATOMIC} ${LIBSOCKET} ${LIBEXECINFO} ${CRC32_LIBRARY}) DTRACE_INSTRUMENT(mysys) IF(HAVE_BFD_H) --- a/storage/rocksdb/build_rocksdb.cmake +++ b/storage/rocksdb/build_rocksdb.cmake @@ -142,7 +142,7 @@ if(WIN32) set(SYSTEM_LIBS ${SYSTEM_LIBS} Shlwapi.lib Rpcrt4.lib) else() - set(SYSTEM_LIBS ${CMAKE_THREAD_LIBS_INIT} ${LIBRT}) + set(SYSTEM_LIBS ${LIBATOMIC} ${CMAKE_THREAD_LIBS_INIT} ${LIBRT}) endif() set(ROCKSDB_LIBS rocksdblib})