summaryrefslogtreecommitdiff
path: root/debian/patches/atomic_config_test.diff
blob: 247c25430db27b6508c7ab4224dac4ac2e8650b9 (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
Description: improve configuration tests for librt and libatomic
Origin: upstream, https://github.com/annulen/webkit/commit/250709411c49550a
Last-Update: 2017-09-16

--- a/Source/WebKit2/CMakeLists.txt
+++ b/Source/WebKit2/CMakeLists.txt
@@ -1,3 +1,6 @@
+include(CheckCXXSourceCompiles)
+include(CheckFunctionExists)
+
 set(WebKit2_INCLUDE_DIRECTORIES
     "${JAVASCRIPTCORE_DIR}/llint"
     "${WEBKIT2_DIR}"
@@ -740,11 +743,33 @@
     WebKit2
 )
 
-# librt is needed for shm_open on Linux.
-find_library(LIBRT_LIBRARIES NAMES rt)
-mark_as_advanced(LIBRT_LIBRARIES)
-if (LIBRT_LIBRARIES)
-    list(APPEND WebKit2_LIBRARIES ${LIBRT_LIBRARIES})
+if (COMPILER_IS_GCC_OR_CLANG)
+    set(ATOMIC_TEST_SOURCE
+    "
+        #include <atomic>
+        int main() { std::atomic<int64_t> i(0); i++; return 0; }
+    "
+    )
+    check_cxx_source_compiles("${ATOMIC_TEST_SOURCE}" ATOMIC_INT64_IS_BUILTIN)
+    if (NOT ATOMIC_INT64_IS_BUILTIN)
+        set(CMAKE_REQUIRED_LIBRARIES atomic)
+        check_cxx_source_compiles("${ATOMIC_TEST_SOURCE}" ATOMIC_INT64_REQUIRES_LIBATOMIC)
+        if (ATOMIC_INT64_REQUIRES_LIBATOMIC)
+            list(APPEND WebKit2_LIBRARIES atomic)
+        endif ()
+        unset(CMAKE_REQUIRED_LIBRARIES)
+    endif ()
+endif ()
+
+if (UNIX)
+    check_function_exists(shm_open SHM_OPEN_EXISTS)
+    if (NOT SHM_OPEN_EXISTS)
+        set(CMAKE_REQUIRED_LIBRARIES rt)
+        check_function_exists(shm_open SHM_OPEN_REQUIRES_LIBRT)
+        if (SHM_OPEN_REQUIRES_LIBRT)
+            list(APPEND WebKit2_LIBRARIES rt)
+        endif ()
+    endif ()
 endif ()
 
 macro(ADD_WEBKIT2_PREFIX_HEADER _target)