1*4882a593SmuzhiyunFrom 9e82eb57870ec7c01734b44ed4bb994362004df3 Mon Sep 17 00:00:00 2001
2*4882a593SmuzhiyunFrom: Fabrice Fontaine <fontaine.fabrice@gmail.com>
3*4882a593SmuzhiyunDate: Fri, 27 Dec 2019 10:20:53 +0100
4*4882a593SmuzhiyunSubject: [PATCH] CMakeLists.txt: check for atomic library
5*4882a593Smuzhiyun
6*4882a593SmuzhiyunOn some architectures, atomic binutils are provided by the libatomic
7*4882a593Smuzhiyunlibrary from gcc. Linking with libatomic is therefore necessary,
8*4882a593Smuzhiyunotherwise the build fails with:
9*4882a593Smuzhiyun
10*4882a593Smuzhiyun[100%] Linking CXX executable leveldbutil
11*4882a593Smuzhiyun/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()':
12*4882a593Smuzhiyunenv_posix.cc:(.text+0x124): undefined reference to `__atomic_fetch_sub_4'
13*4882a593Smuzhiyun
14*4882a593SmuzhiyunThis is often for example the case on sparcv8 32 bit.
15*4882a593Smuzhiyun
16*4882a593SmuzhiyunFixes:
17*4882a593Smuzhiyun - http://autobuild.buildroot.org/results/01d5a50581ac9e9b46f40e6f9665f74897db5e6f
18*4882a593Smuzhiyun
19*4882a593SmuzhiyunSigned-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
20*4882a593Smuzhiyun[Upstream status: https://github.com/google/leveldb/pull/765]
21*4882a593Smuzhiyun---
22*4882a593Smuzhiyun CMakeLists.txt | 4 ++++
23*4882a593Smuzhiyun 1 file changed, 4 insertions(+)
24*4882a593Smuzhiyun
25*4882a593Smuzhiyundiff --git a/CMakeLists.txt b/CMakeLists.txt
26*4882a593Smuzhiyunindex be41ba4..9d6773f 100644
27*4882a593Smuzhiyun--- a/CMakeLists.txt
28*4882a593Smuzhiyun+++ b/CMakeLists.txt
29*4882a593Smuzhiyun@@ -41,6 +41,7 @@ include(CheckIncludeFile)
30*4882a593Smuzhiyun check_include_file("unistd.h" HAVE_UNISTD_H)
31*4882a593Smuzhiyun
32*4882a593Smuzhiyun include(CheckLibraryExists)
33*4882a593Smuzhiyun+check_library_exists(atomic __atomic_fetch_add_4 "" HAVE_ATOMIC)
34*4882a593Smuzhiyun check_library_exists(crc32c crc32c_value "" HAVE_CRC32C)
35*4882a593Smuzhiyun check_library_exists(snappy snappy_compress "" HAVE_SNAPPY)
36*4882a593Smuzhiyun check_library_exists(tcmalloc malloc "" HAVE_TCMALLOC)
37*4882a593Smuzhiyun@@ -270,6 +271,9 @@ if(HAVE_CLANG_THREAD_SAFETY)
38*4882a593Smuzhiyun       -Werror -Wthread-safety)
39*4882a593Smuzhiyun endif(HAVE_CLANG_THREAD_SAFETY)
40*4882a593Smuzhiyun
41*4882a593Smuzhiyun+if(HAVE_ATOMIC)
42*4882a593Smuzhiyun+  target_link_libraries(leveldb atomic)
43*4882a593Smuzhiyun+endif(HAVE_ATOMIC)
44*4882a593Smuzhiyun if(HAVE_CRC32C)
45*4882a593Smuzhiyun   target_link_libraries(leveldb crc32c)
46*4882a593Smuzhiyun endif(HAVE_CRC32C)
47*4882a593Smuzhiyun--
48*4882a593Smuzhiyun2.24.0
49*4882a593Smuzhiyun
50