FindLibLZMA.cmake 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file Copyright.txt or https://cmake.org/licensing for details.
  3. #[=======================================================================[.rst:
  4. FindLibLZMA
  5. -----------
  6. Find LZMA compression algorithm headers and library.
  7. Imported Targets
  8. ^^^^^^^^^^^^^^^^
  9. This module defines :prop_tgt:`IMPORTED` target ``LibLZMA::LibLZMA``, if
  10. liblzma has been found.
  11. Result variables
  12. ^^^^^^^^^^^^^^^^
  13. This module will set the following variables in your project:
  14. ``LIBLZMA_FOUND``
  15. True if liblzma headers and library were found.
  16. ``LIBLZMA_INCLUDE_DIRS``
  17. Directory where liblzma headers are located.
  18. ``LIBLZMA_LIBRARIES``
  19. Lzma libraries to link against.
  20. ``LIBLZMA_HAS_AUTO_DECODER``
  21. True if lzma_auto_decoder() is found (required).
  22. ``LIBLZMA_HAS_EASY_ENCODER``
  23. True if lzma_easy_encoder() is found (required).
  24. ``LIBLZMA_HAS_LZMA_PRESET``
  25. True if lzma_lzma_preset() is found (required).
  26. ``LIBLZMA_VERSION_MAJOR``
  27. The major version of lzma
  28. ``LIBLZMA_VERSION_MINOR``
  29. The minor version of lzma
  30. ``LIBLZMA_VERSION_PATCH``
  31. The patch version of lzma
  32. ``LIBLZMA_VERSION_STRING``
  33. version number as a string (ex: "5.0.3")
  34. #]=======================================================================]
  35. find_path(LIBLZMA_INCLUDE_DIR lzma.h )
  36. if(NOT LIBLZMA_LIBRARY)
  37. find_library(LIBLZMA_LIBRARY_RELEASE NAMES lzma liblzma PATH_SUFFIXES lib)
  38. find_library(LIBLZMA_LIBRARY_DEBUG NAMES lzmad liblzmad PATH_SUFFIXES lib)
  39. include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake)
  40. select_library_configurations(LIBLZMA)
  41. else()
  42. file(TO_CMAKE_PATH "${LIBLZMA_LIBRARY}" LIBLZMA_LIBRARY)
  43. endif()
  44. if(LIBLZMA_INCLUDE_DIR AND EXISTS "${LIBLZMA_INCLUDE_DIR}/lzma/version.h")
  45. file(STRINGS "${LIBLZMA_INCLUDE_DIR}/lzma/version.h" LIBLZMA_HEADER_CONTENTS REGEX "#define LZMA_VERSION_[A-Z]+ [0-9]+")
  46. string(REGEX REPLACE ".*#define LZMA_VERSION_MAJOR ([0-9]+).*" "\\1" LIBLZMA_VERSION_MAJOR "${LIBLZMA_HEADER_CONTENTS}")
  47. string(REGEX REPLACE ".*#define LZMA_VERSION_MINOR ([0-9]+).*" "\\1" LIBLZMA_VERSION_MINOR "${LIBLZMA_HEADER_CONTENTS}")
  48. string(REGEX REPLACE ".*#define LZMA_VERSION_PATCH ([0-9]+).*" "\\1" LIBLZMA_VERSION_PATCH "${LIBLZMA_HEADER_CONTENTS}")
  49. set(LIBLZMA_VERSION_STRING "${LIBLZMA_VERSION_MAJOR}.${LIBLZMA_VERSION_MINOR}.${LIBLZMA_VERSION_PATCH}")
  50. unset(LIBLZMA_HEADER_CONTENTS)
  51. endif()
  52. # We're using new code known now as XZ, even library still been called LZMA
  53. # it can be found in http://tukaani.org/xz/
  54. # Avoid using old codebase
  55. if (LIBLZMA_LIBRARY)
  56. include(${CMAKE_CURRENT_LIST_DIR}/CheckLibraryExists.cmake)
  57. set(CMAKE_REQUIRED_QUIET_SAVE ${CMAKE_REQUIRED_QUIET})
  58. set(CMAKE_REQUIRED_QUIET ${LibLZMA_FIND_QUIETLY})
  59. if(NOT LIBLZMA_LIBRARY_RELEASE AND NOT LIBLZMA_LIBRARY_DEBUG)
  60. set(LIBLZMA_LIBRARY_check ${LIBLZMA_LIBRARY})
  61. elseif(LIBLZMA_LIBRARY_RELEASE)
  62. set(LIBLZMA_LIBRARY_check ${LIBLZMA_LIBRARY_RELEASE})
  63. elseif(LIBLZMA_LIBRARY_DEBUG)
  64. set(LIBLZMA_LIBRARY_check ${LIBLZMA_LIBRARY_DEBUG})
  65. endif()
  66. CHECK_LIBRARY_EXISTS(${LIBLZMA_LIBRARY_check} lzma_auto_decoder "" LIBLZMA_HAS_AUTO_DECODER)
  67. CHECK_LIBRARY_EXISTS(${LIBLZMA_LIBRARY_check} lzma_easy_encoder "" LIBLZMA_HAS_EASY_ENCODER)
  68. CHECK_LIBRARY_EXISTS(${LIBLZMA_LIBRARY_check} lzma_lzma_preset "" LIBLZMA_HAS_LZMA_PRESET)
  69. unset(LIBLZMA_LIBRARY_check)
  70. set(CMAKE_REQUIRED_QUIET ${CMAKE_REQUIRED_QUIET_SAVE})
  71. endif ()
  72. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  73. find_package_handle_standard_args(LibLZMA REQUIRED_VARS LIBLZMA_LIBRARY
  74. LIBLZMA_INCLUDE_DIR
  75. LIBLZMA_HAS_AUTO_DECODER
  76. LIBLZMA_HAS_EASY_ENCODER
  77. LIBLZMA_HAS_LZMA_PRESET
  78. VERSION_VAR LIBLZMA_VERSION_STRING
  79. )
  80. mark_as_advanced( LIBLZMA_INCLUDE_DIR LIBLZMA_LIBRARY )
  81. if (LIBLZMA_FOUND)
  82. set(LIBLZMA_LIBRARIES ${LIBLZMA_LIBRARY})
  83. set(LIBLZMA_INCLUDE_DIRS ${LIBLZMA_INCLUDE_DIR})
  84. if(NOT TARGET LibLZMA::LibLZMA)
  85. add_library(LibLZMA::LibLZMA UNKNOWN IMPORTED)
  86. set_target_properties(LibLZMA::LibLZMA PROPERTIES
  87. INTERFACE_INCLUDE_DIRECTORIES ${LIBLZMA_INCLUDE_DIR}
  88. IMPORTED_LINK_INTERFACE_LANGUAGES C)
  89. if(LIBLZMA_LIBRARY_RELEASE)
  90. set_property(TARGET LibLZMA::LibLZMA APPEND PROPERTY
  91. IMPORTED_CONFIGURATIONS RELEASE)
  92. set_target_properties(LibLZMA::LibLZMA PROPERTIES
  93. IMPORTED_LOCATION_RELEASE "${LIBLZMA_LIBRARY_RELEASE}")
  94. endif()
  95. if(LIBLZMA_LIBRARY_DEBUG)
  96. set_property(TARGET LibLZMA::LibLZMA APPEND PROPERTY
  97. IMPORTED_CONFIGURATIONS DEBUG)
  98. set_target_properties(LibLZMA::LibLZMA PROPERTIES
  99. IMPORTED_LOCATION_DEBUG "${LIBLZMA_LIBRARY_DEBUG}")
  100. endif()
  101. if(NOT LIBLZMA_LIBRARY_RELEASE AND NOT LIBLZMA_LIBRARY_DEBUG)
  102. set_target_properties(LibLZMA::LibLZMA PROPERTIES
  103. IMPORTED_LOCATION "${LIBLZMA_LIBRARY}")
  104. endif()
  105. endif()
  106. endif ()