0004-cmake-Use-find_package-to-find-Snappy.patch 3.4 KB

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