summaryrefslogtreecommitdiff
blob: 0f7d522bc194d939d8971d7f1fa742553ec677fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
Original 10.1 patch Borrowed from Debian to make atomic detection easier
Modified for 10.3 by Brian Evans <grknight@gentoo.org>

From: Debian MySQL Maintainers <pkg-mysql-maint@lists.alioth.debian.org>
Date: Thu, 10 Aug 2017 20:40:29 +0200
Subject: c11_atomics

---
 configure.cmake               | 23 +++++++++++++++++++++--
 mysys/CMakeLists.txt          |  4 ++++
 sql/CMakeLists.txt            |  4 ++++
 5 files changed, 46 insertions(+), 4 deletions(-)

diff --git a/configure.cmake b/configure.cmake
index 0057c7f..43ad114 100644
--- a/configure.cmake
+++ b/configure.cmake
@@ -128,7 +128,7 @@ IF(UNIX)
   ENDIF()
   FIND_PACKAGE(Threads)
 
-  SET(CMAKE_REQUIRED_LIBRARIES 
+  LIST(APPEND CMAKE_REQUIRED_LIBRARIES
     ${LIBM} ${LIBNSL} ${LIBBIND} ${LIBCRYPT} ${LIBSOCKET} ${LIBDL} ${CMAKE_THREAD_LIBS_INIT} ${LIBRT} ${LIBEXECINFO})
   # Need explicit pthread for gcc -fsanitize=address
   IF(CMAKE_USE_PTHREADS_INIT AND CMAKE_C_FLAGS MATCHES "-fsanitize=")
@@ -1028,7 +1028,26 @@ ELSEIF(NOT WITH_ATOMIC_OPS)
   long long int *ptr= &var;
   return (int)__atomic_load_n(ptr, __ATOMIC_SEQ_CST);
 }"
-HAVE_GCC_C11_ATOMICS)
+HAVE_GCC_C11_ATOMICS_WITHOUT_LIBATOMIC)
+IF(HAVE_GCC_C11_ATOMICS_WITHOUT_LIBATOMIC)
+  SET(HAVE_GCC_C11_ATOMICS True)
+ELSE()
+  SET(OLD_CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
+  LIST(APPEND CMAKE_REQUIRED_LIBRARIES "atomic")
+  CHECK_CXX_SOURCE_COMPILES("
+  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_WITH_LIBATOMIC)
+  IF(HAVE_GCC_C11_ATOMICS_WITH_LIBATOMIC)
+    SET(HAVE_GCC_C11_ATOMICS True)
+  ELSE()
+    SET(CMAKE_REQUIRED_LIBRARIES ${OLD_CMAKE_REQUIRED_LIBRARIES})
+  ENDIF()
+ENDIF()

 IF(WITH_VALGRIND)
   SET(HAVE_valgrind 1)
diff --git a/mysys/CMakeLists.txt b/mysys/CMakeLists.txt
index eb7f75e..a9221d7 100644
--- a/mysys/CMakeLists.txt
+++ b/mysys/CMakeLists.txt
@@ -78,6 +78,10 @@ IF(HAVE_BFD_H)
   TARGET_LINK_LIBRARIES(mysys bfd)  
 ENDIF(HAVE_BFD_H)
 
+IF(HAVE_GCC_C11_ATOMICS_WITH_LIBATOMIC)
+  TARGET_LINK_LIBRARIES(mysys atomic)
+ENDIF()
+
 IF (WIN32)
   TARGET_LINK_LIBRARIES(mysys IPHLPAPI)  
 ENDIF(WIN32)
diff --git a/sql/CMakeLists.txt b/sql/CMakeLists.txt
index b4acac5..8247714 100644
--- a/sql/CMakeLists.txt
+++ b/sql/CMakeLists.txt
@@ -165,6 +165,10 @@ TARGET_LINK_LIBRARIES(sql ${MYSQLD_STATIC_PLUGIN_LIBS}
   ${SSL_LIBRARIES}
   ${LIBSYSTEMD})
 
+IF(HAVE_GCC_C11_ATOMICS_WITH_LIBATOMIC)
+  TARGET_LINK_LIBRARIES(sql atomic)
+ENDIF()
+
 IF(WIN32)
   SET(MYSQLD_SOURCE main.cc nt_servc.cc message.rc)
   TARGET_LINK_LIBRARIES(sql psapi)