FindLibLZMA.cmake 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. # - Find LibLZMA
  2. # Find LibLZMA headers and library
  3. #
  4. # LIBLZMA_FOUND - True if liblzma is found.
  5. # LIBLZMA_INCLUDE_DIRS - Directory where liblzma headers are located.
  6. # LIBLZMA_LIBRARIES - Lzma libraries to link against.
  7. # LIBLZMA_HAS_AUTO_DECODER - True if lzma_auto_decoder() is found (required).
  8. # LIBLZMA_HAS_EASY_ENCODER - True if lzma_easy_encoder() is found (required).
  9. # LIBLZMA_HAS_LZMA_PRESET - True if lzma_lzma_preset() is found (required).
  10. # LIBLZMA_VERSION_MAJOR - The major version of lzma
  11. # LIBLZMA_VERSION_MINOR - The minor version of lzma
  12. # LIBLZMA_VERSION_PATCH - The patch version of lzma
  13. # LIBLZMA_VERSION_STRING - version number as a string (ex: "5.0.3")
  14. #=============================================================================
  15. # Copyright 2008 Per Øyvind Karlsen <[email protected]>
  16. # Copyright 2009 Alexander Neundorf <[email protected]>
  17. # Copyright 2009 Helio Chissini de Castro <[email protected]>
  18. # Copyright 2012 Mario Bensi <[email protected]>
  19. #
  20. # Distributed under the OSI-approved BSD License (the "License");
  21. # see accompanying file Copyright.txt for details.
  22. #
  23. # This software is distributed WITHOUT ANY WARRANTY; without even the
  24. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  25. # See the License for more information.
  26. #=============================================================================
  27. # (To distribute this file outside of CMake, substitute the full
  28. # License text for the above reference.)
  29. find_path(LIBLZMA_INCLUDE_DIR lzma.h )
  30. find_library(LIBLZMA_LIBRARY lzma)
  31. if(LIBLZMA_INCLUDE_DIR AND EXISTS "${LIBLZMA_INCLUDE_DIR}/lzma/version.h")
  32. file(READ "${LIBLZMA_INCLUDE_DIR}/lzma/version.h" LIBLZMA_HEADER_CONTENTS)
  33. string(REGEX REPLACE ".*#define LZMA_VERSION_MAJOR ([0-9]+).*" "\\1" LIBLZMA_VERSION_MAJOR "${LIBLZMA_HEADER_CONTENTS}")
  34. string(REGEX REPLACE ".*#define LZMA_VERSION_MINOR ([0-9]+).*" "\\1" LIBLZMA_VERSION_MINOR "${LIBLZMA_HEADER_CONTENTS}")
  35. string(REGEX REPLACE ".*#define LZMA_VERSION_PATCH ([0-9]+).*" "\\1" LIBLZMA_VERSION_PATCH "${LIBLZMA_HEADER_CONTENTS}")
  36. set(LIBLZMA_VERSION_STRING "${LIBLZMA_VERSION_MAJOR}.${LIBLZMA_VERSION_MINOR}.${LIBLZMA_VERSION_PATCH}")
  37. endif()
  38. # We're using new code known now as XZ, even library still been called LZMA
  39. # it can be found in http://tukaani.org/xz/
  40. # Avoid using old codebase
  41. if (LIBLZMA_LIBRARY)
  42. include(CheckLibraryExists)
  43. CHECK_LIBRARY_EXISTS(${LIBLZMA_LIBRARY} lzma_auto_decoder "" LIBLZMA_HAS_AUTO_DECODER)
  44. CHECK_LIBRARY_EXISTS(${LIBLZMA_LIBRARY} lzma_easy_encoder "" LIBLZMA_HAS_EASY_ENCODER)
  45. CHECK_LIBRARY_EXISTS(${LIBLZMA_LIBRARY} lzma_lzma_preset "" LIBLZMA_HAS_LZMA_PRESET)
  46. endif ()
  47. include(FindPackageHandleStandardArgs)
  48. FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibLZMA REQUIRED_VARS LIBLZMA_INCLUDE_DIR
  49. LIBLZMA_LIBRARY
  50. LIBLZMA_HAS_AUTO_DECODER
  51. LIBLZMA_HAS_EASY_ENCODER
  52. LIBLZMA_HAS_LZMA_PRESET
  53. VERSION_VAR LIBLZMA_VERSION_STRING
  54. )
  55. if (LIBLZMA_FOUND)
  56. set(LIBLZMA_LIBRARIES ${LIBLZMA_LIBRARY})
  57. set(LIBLZMA_INCLUDE_DIRS ${LIBLZMA_INCLUDE_DIR})
  58. endif ()
  59. mark_as_advanced( LIBLZMA_INCLUDE_DIR LIBLZMA_LIBRARY )