blob: 98609b6b934829976004a37d201c0354ac845280 [file] [log] [blame]
Fabrice Fontaineb5f58322019-12-27 10:40:00 +01001From 9e82eb57870ec7c01734b44ed4bb994362004df3 Mon Sep 17 00:00:00 2001
2From: Fabrice Fontaine <fontaine.fabrice@gmail.com>
3Date: Fri, 27 Dec 2019 10:20:53 +0100
4Subject: [PATCH] CMakeLists.txt: check for atomic library
5
6On some architectures, atomic binutils are provided by the libatomic
7library from gcc. Linking with libatomic is therefore necessary,
8otherwise the build fails with:
9
10[100%] Linking CXX executable leveldbutil
11/home/fabrice/buildroot/output/host/opt/ext-toolchain/bin/../lib/gcc/sparc-buildroot-linux-uclibc/7.4.0/../../../../sparc-buildroot-linux-uclibc/bin/ld: libleveldb.a(env_posix.cc.o): in function `leveldb::(anonymous namespace)::Limiter::Acquire()':
12env_posix.cc:(.text+0x124): undefined reference to `__atomic_fetch_sub_4'
13
14This is often for example the case on sparcv8 32 bit.
15
16Fixes:
17 - http://autobuild.buildroot.org/results/01d5a50581ac9e9b46f40e6f9665f74897db5e6f
18
19Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
20[Upstream status: https://github.com/google/leveldb/pull/765]
21---
22 CMakeLists.txt | 4 ++++
23 1 file changed, 4 insertions(+)
24
25diff --git a/CMakeLists.txt b/CMakeLists.txt
26index be41ba4..9d6773f 100644
27--- a/CMakeLists.txt
28+++ b/CMakeLists.txt
29@@ -41,6 +41,7 @@ include(CheckIncludeFile)
30 check_include_file("unistd.h" HAVE_UNISTD_H)
31
32 include(CheckLibraryExists)
33+check_library_exists(atomic __atomic_fetch_add_4 "" HAVE_ATOMIC)
34 check_library_exists(crc32c crc32c_value "" HAVE_CRC32C)
35 check_library_exists(snappy snappy_compress "" HAVE_SNAPPY)
36 check_library_exists(tcmalloc malloc "" HAVE_TCMALLOC)
37@@ -270,6 +271,9 @@ if(HAVE_CLANG_THREAD_SAFETY)
38 -Werror -Wthread-safety)
39 endif(HAVE_CLANG_THREAD_SAFETY)
40
41+if(HAVE_ATOMIC)
42+ target_link_libraries(leveldb atomic)
43+endif(HAVE_ATOMIC)
44 if(HAVE_CRC32C)
45 target_link_libraries(leveldb crc32c)
46 endif(HAVE_CRC32C)
47--
482.24.0
49