FindBZip2.cmake 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. FindBZip2
  5. ---------
  6. Try to find BZip2
  7. IMPORTED Targets
  8. ^^^^^^^^^^^^^^^^
  9. This module defines :prop_tgt:`IMPORTED` target ``BZip2::BZip2``, if
  10. BZip2 has been found.
  11. Result Variables
  12. ^^^^^^^^^^^^^^^^
  13. This module defines the following variables:
  14. ``BZIP2_FOUND``
  15. system has BZip2
  16. ``BZIP2_INCLUDE_DIRS``
  17. the BZip2 include directories
  18. ``BZIP2_LIBRARIES``
  19. Link these to use BZip2
  20. ``BZIP2_NEED_PREFIX``
  21. this is set if the functions are prefixed with ``BZ2_``
  22. ``BZIP2_VERSION_STRING``
  23. the version of BZip2 found
  24. Cache variables
  25. ^^^^^^^^^^^^^^^
  26. The following cache variables may also be set:
  27. ``BZIP2_INCLUDE_DIR``
  28. the BZip2 include directory
  29. #]=======================================================================]
  30. set(_BZIP2_PATHS PATHS
  31. "[HKEY_LOCAL_MACHINE\\SOFTWARE\\GnuWin32\\Bzip2;InstallPath]"
  32. )
  33. find_path(BZIP2_INCLUDE_DIR bzlib.h ${_BZIP2_PATHS} PATH_SUFFIXES include)
  34. if (NOT BZIP2_LIBRARIES)
  35. find_library(BZIP2_LIBRARY_RELEASE NAMES bz2 bzip2 libbz2 libbzip2 ${_BZIP2_PATHS} PATH_SUFFIXES lib)
  36. find_library(BZIP2_LIBRARY_DEBUG NAMES bz2d bzip2d libbz2d libbzip2d ${_BZIP2_PATHS} PATH_SUFFIXES lib)
  37. include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake)
  38. SELECT_LIBRARY_CONFIGURATIONS(BZIP2)
  39. else ()
  40. file(TO_CMAKE_PATH "${BZIP2_LIBRARIES}" BZIP2_LIBRARIES)
  41. endif ()
  42. if (BZIP2_INCLUDE_DIR AND EXISTS "${BZIP2_INCLUDE_DIR}/bzlib.h")
  43. file(STRINGS "${BZIP2_INCLUDE_DIR}/bzlib.h" BZLIB_H REGEX "bzip2/libbzip2 version [0-9]+\\.[^ ]+ of [0-9]+ ")
  44. string(REGEX REPLACE ".* bzip2/libbzip2 version ([0-9]+\\.[^ ]+) of [0-9]+ .*" "\\1" BZIP2_VERSION_STRING "${BZLIB_H}")
  45. endif ()
  46. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  47. FIND_PACKAGE_HANDLE_STANDARD_ARGS(BZip2
  48. REQUIRED_VARS BZIP2_LIBRARIES BZIP2_INCLUDE_DIR
  49. VERSION_VAR BZIP2_VERSION_STRING)
  50. if (BZIP2_FOUND)
  51. set(BZIP2_INCLUDE_DIRS ${BZIP2_INCLUDE_DIR})
  52. include(${CMAKE_CURRENT_LIST_DIR}/CheckSymbolExists.cmake)
  53. include(${CMAKE_CURRENT_LIST_DIR}/CMakePushCheckState.cmake)
  54. cmake_push_check_state()
  55. set(CMAKE_REQUIRED_QUIET ${BZip2_FIND_QUIETLY})
  56. set(CMAKE_REQUIRED_INCLUDES ${BZIP2_INCLUDE_DIR})
  57. set(CMAKE_REQUIRED_LIBRARIES ${BZIP2_LIBRARIES})
  58. CHECK_SYMBOL_EXISTS(BZ2_bzCompressInit "bzlib.h" BZIP2_NEED_PREFIX)
  59. cmake_pop_check_state()
  60. if(NOT TARGET BZip2::BZip2)
  61. add_library(BZip2::BZip2 UNKNOWN IMPORTED)
  62. set_target_properties(BZip2::BZip2 PROPERTIES
  63. INTERFACE_INCLUDE_DIRECTORIES "${BZIP2_INCLUDE_DIRS}")
  64. if(BZIP2_LIBRARY_RELEASE)
  65. set_property(TARGET BZip2::BZip2 APPEND PROPERTY
  66. IMPORTED_CONFIGURATIONS RELEASE)
  67. set_target_properties(BZip2::BZip2 PROPERTIES
  68. IMPORTED_LOCATION_RELEASE "${BZIP2_LIBRARY_RELEASE}")
  69. endif()
  70. if(BZIP2_LIBRARY_DEBUG)
  71. set_property(TARGET BZip2::BZip2 APPEND PROPERTY
  72. IMPORTED_CONFIGURATIONS DEBUG)
  73. set_target_properties(BZip2::BZip2 PROPERTIES
  74. IMPORTED_LOCATION_DEBUG "${BZIP2_LIBRARY_DEBUG}")
  75. endif()
  76. if(NOT BZIP2_LIBRARY_RELEASE AND NOT BZIP2_LIBRARY_DEBUG)
  77. set_property(TARGET BZip2::BZip2 APPEND PROPERTY
  78. IMPORTED_LOCATION "${BZIP2_LIBRARY}")
  79. endif()
  80. endif()
  81. endif ()
  82. mark_as_advanced(BZIP2_INCLUDE_DIR)