| From aa658d96f59d0e29f0d9208b8fbb3cce42e57edc Mon Sep 17 00:00:00 2001 |
| From: =?UTF-8?q?Pawe=C5=82=20Bylica?= <chfast@gmail.com> |
| Date: Wed, 8 May 2019 10:42:03 +0200 |
| Subject: [PATCH] cmake: Use find_package() to find Snappy |
| |
| Upstream: https://github.com/google/leveldb/pull/686/commits/3e73a396a082efc76e065ae974fe18c3bb27219d |
| [Thomas: this commit allows to fix the detection of the snappy library |
| in static link configurations] |
| Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com> |
| [Fabrice : updated for 1.23] |
| Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com> |
| [Dario: make the patch to be applied with fuzz factor 0] |
| Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com> |
| --- |
| CMakeLists.txt | 12 ++++++++---- |
| cmake/FindSnappy.cmake | 31 +++++++++++++++++++++++++++++++ |
| 2 files changed, 39 insertions(+), 4 deletions(-) |
| create mode 100644 cmake/FindSnappy.cmake |
| |
| diff --git a/CMakeLists.txt b/CMakeLists.txt |
| index 436a9fe5513f..bbd179d3be59 100644 |
| --- a/CMakeLists.txt |
| +++ b/CMakeLists.txt |
| @@ -6,6 +6,9 @@ cmake_minimum_required(VERSION 3.9) |
| # Keep the version below in sync with the one in db.h |
| project(leveldb VERSION 1.23.0 LANGUAGES C CXX) |
| |
| +# Include local CMake modules. |
| +list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) |
| + |
| # C standard can be overridden when this is used as a sub-project. |
| if(NOT CMAKE_C_STANDARD) |
| # This project can use C11, but will gracefully decay down to C89. |
| @@ -34,13 +37,14 @@ option(LEVELDB_BUILD_TESTS "Build LevelDB's unit tests" ON) |
| option(LEVELDB_BUILD_BENCHMARKS "Build LevelDB's benchmarks" ON) |
| option(LEVELDB_INSTALL "Install LevelDB's header and library" ON) |
| |
| +find_package(Snappy) |
| + |
| include(CheckIncludeFile) |
| check_include_file("unistd.h" HAVE_UNISTD_H) |
| |
| include(CheckLibraryExists) |
| check_library_exists(atomic __atomic_fetch_add_4 "" HAVE_ATOMIC) |
| check_library_exists(crc32c crc32c_value "" HAVE_CRC32C) |
| -check_library_exists(snappy snappy_compress "" HAVE_SNAPPY) |
| check_library_exists(tcmalloc malloc "" HAVE_TCMALLOC) |
| |
| include(CheckCXXSymbolExists) |
| @@ -298,9 +302,9 @@ endif(HAVE_ATOMIC) |
| if(HAVE_CRC32C) |
| target_link_libraries(leveldb crc32c) |
| endif(HAVE_CRC32C) |
| -if(HAVE_SNAPPY) |
| - target_link_libraries(leveldb snappy) |
| -endif(HAVE_SNAPPY) |
| +if(TARGET Snappy::snappy) |
| + target_link_libraries(leveldb Snappy::snappy) |
| +endif() |
| if(HAVE_TCMALLOC) |
| target_link_libraries(leveldb tcmalloc) |
| endif(HAVE_TCMALLOC) |
| diff --git a/cmake/FindSnappy.cmake b/cmake/FindSnappy.cmake |
| new file mode 100644 |
| index 000000000000..88c1de98f228 |
| --- /dev/null |
| +++ b/cmake/FindSnappy.cmake |
| @@ -0,0 +1,31 @@ |
| +# Copyright 2019 The LevelDB Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. See the AUTHORS file for names of contributors. |
| + |
| +find_library(SNAPPY_LIBRARY |
| + NAMES snappy |
| + HINTS ${SNAPPY_ROOT_DIR}/lib |
| +) |
| + |
| +find_path(SNAPPY_INCLUDE_DIR |
| + NAMES snappy.h |
| + HINTS ${SNAPPY_ROOT_DIR}/include |
| +) |
| + |
| +include(FindPackageHandleStandardArgs) |
| +find_package_handle_standard_args(Snappy DEFAULT_MSG SNAPPY_LIBRARY SNAPPY_INCLUDE_DIR) |
| + |
| +mark_as_advanced(SNAPPY_LIBRARY SNAPPY_INCLUDE_DIR) |
| + |
| +if(SNAPPY_FOUND) |
| + set(HAVE_SNAPPY TRUE) # For compatibity with generating port_config.h. |
| + |
| + # Add imported targets. |
| + # Follow the package naming convetion 'Snappy::' from |
| + # https://github.com/google/snappy/blob/master/CMakeLists.txt#L211. |
| + add_library(Snappy::snappy UNKNOWN IMPORTED) |
| + set_target_properties(Snappy::snappy PROPERTIES |
| + IMPORTED_LOCATION ${SNAPPY_LIBRARY} |
| + INTERFACE_INCLUDE_DIRECTORIES ${SNAPPY_INCLUDE_DIR} |
| + ) |
| +endif() |
| -- |
| 2.43.0 |
| |