FindLibLZMA.cmake 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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(STRINGS "${LIBLZMA_INCLUDE_DIR}/lzma/version.h" LIBLZMA_HEADER_CONTENTS REGEX "#define LZMA_VERSION_[A-Z]+ [0-9]+")
  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. unset(LIBLZMA_HEADER_CONTENTS)
  38. endif()
  39. # We're using new code known now as XZ, even library still been called LZMA
  40. # it can be found in http://tukaani.org/xz/
  41. # Avoid using old codebase
  42. if (LIBLZMA_LIBRARY)
  43. include(CheckLibraryExists)
  44. CHECK_LIBRARY_EXISTS(${LIBLZMA_LIBRARY} lzma_auto_decoder "" LIBLZMA_HAS_AUTO_DECODER)
  45. CHECK_LIBRARY_EXISTS(${LIBLZMA_LIBRARY} lzma_easy_encoder "" LIBLZMA_HAS_EASY_ENCODER)
  46. CHECK_LIBRARY_EXISTS(${LIBLZMA_LIBRARY} lzma_lzma_preset "" LIBLZMA_HAS_LZMA_PRESET)
  47. endif ()
  48. include(FindPackageHandleStandardArgs)
  49. FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibLZMA REQUIRED_VARS LIBLZMA_INCLUDE_DIR
  50. LIBLZMA_LIBRARY
  51. LIBLZMA_HAS_AUTO_DECODER
  52. LIBLZMA_HAS_EASY_ENCODER
  53. LIBLZMA_HAS_LZMA_PRESET
  54. VERSION_VAR LIBLZMA_VERSION_STRING
  55. )
  56. if (LIBLZMA_FOUND)
  57. set(LIBLZMA_LIBRARIES ${LIBLZMA_LIBRARY})
  58. set(LIBLZMA_INCLUDE_DIRS ${LIBLZMA_INCLUDE_DIR})
  59. endif ()
  60. mark_as_advanced( LIBLZMA_INCLUDE_DIR LIBLZMA_LIBRARY )