blob: 169986130c08eed777293cb807e35388f3c04b86 [file] [log] [blame]
Brad Bishop19323692019-04-05 15:28:33 -04001Author: Vicențiu Ciorbaru <vicentiu@mariadb.org>
2Date: Fri Dec 21 19:14:04 2018 +0200
3
4 Link with libatomic to enable C11 atomics support
5
6 Some architectures (mips) require libatomic to support proper
7 atomic operations. Check first if support is available without
8 linking, otherwise use the library.
9
10Upstream-Status: Pending
11Signed-off-by: Khem Raj <raj.khem@gmail.com>
12
13--- a/configure.cmake
14+++ b/configure.cmake
15@@ -926,7 +926,25 @@ int main()
16 long long int *ptr= &var;
17 return (int)__atomic_load_n(ptr, __ATOMIC_SEQ_CST);
18 }"
19-HAVE_GCC_C11_ATOMICS)
20+HAVE_GCC_C11_ATOMICS_WITHOUT_LIBATOMIC)
21+IF (HAVE_GCC_C11_ATOMICS_WITHOUT_LIBATOMIC)
22+ SET(HAVE_GCC_C11_ATOMICS True)
23+ELSE()
24+ SET(OLD_CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
25+ LIST(APPEND CMAKE_REQUIRED_LIBRARIES "atomic")
26+ CHECK_CXX_SOURCE_COMPILES("
27+ int main()
28+ {
29+ long long int var= 1;
30+ long long int *ptr= &var;
31+ return (int)__atomic_load_n(ptr, __ATOMIC_SEQ_CST);
32+ }"
33+ HAVE_GCC_C11_ATOMICS_WITH_LIBATOMIC)
34+ IF(HAVE_GCC_C11_ATOMICS_WITH_LIBATOMIC)
35+ SET(HAVE_GCC_C11_ATOMICS True)
36+ ENDIF()
37+ SET(CMAKE_REQUIRED_LIBRARIES ${OLD_CMAKE_REQUIRED_LIBRARIES})
38+ENDIF()
39
40 IF(WITH_VALGRIND)
41 SET(HAVE_valgrind 1)
42--- a/mysys/CMakeLists.txt
43+++ b/mysys/CMakeLists.txt
44@@ -78,6 +78,10 @@ TARGET_LINK_LIBRARIES(mysys dbug strings
45 ${LIBNSL} ${LIBM} ${LIBRT} ${LIBDL} ${LIBSOCKET} ${LIBEXECINFO} ${CRC32_LIBRARY})
46 DTRACE_INSTRUMENT(mysys)
47
48+IF (HAVE_GCC_C11_ATOMICS_WITH_LIBATOMIC)
49+ TARGET_LINK_LIBRARIES(mysys atomic)
50+ENDIF()
51+
52 IF(HAVE_BFD_H)
53 TARGET_LINK_LIBRARIES(mysys bfd)
54 ENDIF(HAVE_BFD_H)
55--- a/sql/CMakeLists.txt
56+++ b/sql/CMakeLists.txt
57@@ -178,6 +178,10 @@ ELSE()
58 SET(MYSQLD_SOURCE main.cc ${DTRACE_PROBES_ALL})
59 ENDIF()
60
61+IF (HAVE_GCC_C11_ATOMICS_WITH_LIBATOMIC)
62+ TARGET_LINK_LIBRARIES(sql atomic)
63+ENDIF()
64+
65
66 IF(MSVC AND NOT WITHOUT_DYNAMIC_PLUGINS)
67