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

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