xref: /OK3568_Linux_fs/buildroot/package/leveldb/0004-cmake-Use-find_package-to-find-Snappy.patch (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1From 450c1d88b3e1af34614294830b4dc0612d198d26 Mon Sep 17 00:00:00 2001
2From: =?UTF-8?q?Pawe=C5=82=20Bylica?= <chfast@gmail.com>
3Date: Wed, 8 May 2019 10:42:03 +0200
4Subject: [PATCH] cmake: Use find_package() to find Snappy
5
6Upstream: https://github.com/google/leveldb/pull/686/commits/3e73a396a082efc76e065ae974fe18c3bb27219d
7[Thomas: this commit allows to fix the detection of the snappy library
8in static link configurations]
9Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
10---
11 CMakeLists.txt         | 12 ++++++++----
12 cmake/FindSnappy.cmake | 31 +++++++++++++++++++++++++++++++
13 2 files changed, 39 insertions(+), 4 deletions(-)
14 create mode 100644 cmake/FindSnappy.cmake
15
16diff --git a/CMakeLists.txt b/CMakeLists.txt
17index 78fead6..2efccda 100644
18--- a/CMakeLists.txt
19+++ b/CMakeLists.txt
20@@ -6,6 +6,9 @@ cmake_minimum_required(VERSION 3.9)
21 # Keep the version below in sync with the one in db.h
22 project(leveldb VERSION 1.22.0 LANGUAGES C CXX)
23
24+# Include local CMake modules.
25+list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
26+
27 # This project can use C11, but will gracefully decay down to C89.
28 set(CMAKE_C_STANDARD 11)
29 set(CMAKE_C_STANDARD_REQUIRED OFF)
30@@ -31,13 +34,14 @@ option(LEVELDB_INSTALL "Install LevelDB's header and library" ON)
31 include(TestBigEndian)
32 test_big_endian(LEVELDB_IS_BIG_ENDIAN)
33
34+find_package(Snappy)
35+
36 include(CheckIncludeFile)
37 check_include_file("unistd.h" HAVE_UNISTD_H)
38
39 include(CheckLibraryExists)
40 check_library_exists(atomic __atomic_fetch_add_4 "" HAVE_ATOMIC)
41 check_library_exists(crc32c crc32c_value "" HAVE_CRC32C)
42-check_library_exists(snappy snappy_compress "" HAVE_SNAPPY)
43 check_library_exists(tcmalloc malloc "" HAVE_TCMALLOC)
44
45 include(CheckCXXSymbolExists)
46@@ -276,9 +280,9 @@ endif(HAVE_ATOMIC)
47 if(HAVE_CRC32C)
48   target_link_libraries(leveldb crc32c)
49 endif(HAVE_CRC32C)
50-if(HAVE_SNAPPY)
51-  target_link_libraries(leveldb snappy)
52-endif(HAVE_SNAPPY)
53+if(TARGET Snappy::snappy)
54+  target_link_libraries(leveldb Snappy::snappy)
55+endif()
56 if(HAVE_TCMALLOC)
57   target_link_libraries(leveldb tcmalloc)
58 endif(HAVE_TCMALLOC)
59diff --git a/cmake/FindSnappy.cmake b/cmake/FindSnappy.cmake
60new file mode 100644
61index 0000000..88c1de9
62--- /dev/null
63+++ b/cmake/FindSnappy.cmake
64@@ -0,0 +1,31 @@
65+# Copyright 2019 The LevelDB Authors. All rights reserved.
66+# Use of this source code is governed by a BSD-style license that can be
67+# found in the LICENSE file. See the AUTHORS file for names of contributors.
68+
69+find_library(SNAPPY_LIBRARY
70+    NAMES snappy
71+    HINTS ${SNAPPY_ROOT_DIR}/lib
72+)
73+
74+find_path(SNAPPY_INCLUDE_DIR
75+    NAMES snappy.h
76+    HINTS ${SNAPPY_ROOT_DIR}/include
77+)
78+
79+include(FindPackageHandleStandardArgs)
80+find_package_handle_standard_args(Snappy DEFAULT_MSG SNAPPY_LIBRARY SNAPPY_INCLUDE_DIR)
81+
82+mark_as_advanced(SNAPPY_LIBRARY SNAPPY_INCLUDE_DIR)
83+
84+if(SNAPPY_FOUND)
85+  set(HAVE_SNAPPY TRUE) # For compatibity with generating port_config.h.
86+
87+  # Add imported targets.
88+  # Follow the package naming convetion 'Snappy::' from
89+  # https://github.com/google/snappy/blob/master/CMakeLists.txt#L211.
90+  add_library(Snappy::snappy UNKNOWN IMPORTED)
91+  set_target_properties(Snappy::snappy PROPERTIES
92+      IMPORTED_LOCATION ${SNAPPY_LIBRARY}
93+      INTERFACE_INCLUDE_DIRECTORIES ${SNAPPY_INCLUDE_DIR}
94+  )
95+endif()
96--
972.26.2
98
99