FindTIFF.cmake 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. # FindTIFF
  5. # --------
  6. #
  7. # Find the TIFF library (libtiff).
  8. #
  9. # Imported targets
  10. # ^^^^^^^^^^^^^^^^
  11. #
  12. # This module defines the following :prop_tgt:`IMPORTED` targets:
  13. #
  14. # ``TIFF::TIFF``
  15. # The TIFF library, if found.
  16. #
  17. # Result variables
  18. # ^^^^^^^^^^^^^^^^
  19. #
  20. # This module will set the following variables in your project:
  21. #
  22. # ``TIFF_FOUND``
  23. # true if the TIFF headers and libraries were found
  24. # ``TIFF_INCLUDE_DIR``
  25. # the directory containing the TIFF headers
  26. # ``TIFF_INCLUDE_DIRS``
  27. # the directory containing the TIFF headers
  28. # ``TIFF_LIBRARIES``
  29. # TIFF libraries to be linked
  30. #
  31. # Cache variables
  32. # ^^^^^^^^^^^^^^^
  33. #
  34. # The following cache variables may also be set:
  35. #
  36. # ``TIFF_INCLUDE_DIR``
  37. # the directory containing the TIFF headers
  38. # ``TIFF_LIBRARY``
  39. # the path to the TIFF library
  40. find_path(TIFF_INCLUDE_DIR tiff.h)
  41. set(TIFF_NAMES ${TIFF_NAMES} tiff libtiff tiff3 libtiff3)
  42. foreach(name ${TIFF_NAMES})
  43. list(APPEND TIFF_NAMES_DEBUG "${name}d")
  44. endforeach()
  45. if(NOT TIFF_LIBRARY)
  46. find_library(TIFF_LIBRARY_RELEASE NAMES ${TIFF_NAMES})
  47. find_library(TIFF_LIBRARY_DEBUG NAMES ${TIFF_NAMES_DEBUG})
  48. include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake)
  49. select_library_configurations(TIFF)
  50. mark_as_advanced(TIFF_LIBRARY_RELEASE TIFF_LIBRARY_DEBUG)
  51. endif()
  52. unset(TIFF_NAMES)
  53. unset(TIFF_NAMES_DEBUG)
  54. if(TIFF_INCLUDE_DIR AND EXISTS "${TIFF_INCLUDE_DIR}/tiffvers.h")
  55. file(STRINGS "${TIFF_INCLUDE_DIR}/tiffvers.h" tiff_version_str
  56. REGEX "^#define[\t ]+TIFFLIB_VERSION_STR[\t ]+\"LIBTIFF, Version .*")
  57. string(REGEX REPLACE "^#define[\t ]+TIFFLIB_VERSION_STR[\t ]+\"LIBTIFF, Version +([^ \\n]*).*"
  58. "\\1" TIFF_VERSION_STRING "${tiff_version_str}")
  59. unset(tiff_version_str)
  60. endif()
  61. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  62. FIND_PACKAGE_HANDLE_STANDARD_ARGS(TIFF
  63. REQUIRED_VARS TIFF_LIBRARY TIFF_INCLUDE_DIR
  64. VERSION_VAR TIFF_VERSION_STRING)
  65. if(TIFF_FOUND)
  66. set(TIFF_LIBRARIES ${TIFF_LIBRARY})
  67. set(TIFF_INCLUDE_DIRS "${TIFF_INCLUDE_DIR}")
  68. if(NOT TARGET TIFF::TIFF)
  69. add_library(TIFF::TIFF UNKNOWN IMPORTED)
  70. if(TIFF_INCLUDE_DIRS)
  71. set_target_properties(TIFF::TIFF PROPERTIES
  72. INTERFACE_INCLUDE_DIRECTORIES "${TIFF_INCLUDE_DIRS}")
  73. endif()
  74. if(EXISTS "${TIFF_LIBRARY}")
  75. set_target_properties(TIFF::TIFF PROPERTIES
  76. IMPORTED_LINK_INTERFACE_LANGUAGES "C"
  77. IMPORTED_LOCATION "${TIFF_LIBRARY}")
  78. endif()
  79. if(EXISTS "${TIFF_LIBRARY_RELEASE}")
  80. set_property(TARGET TIFF::TIFF APPEND PROPERTY
  81. IMPORTED_CONFIGURATIONS RELEASE)
  82. set_target_properties(TIFF::TIFF PROPERTIES
  83. IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "C"
  84. IMPORTED_LOCATION_RELEASE "${TIFF_LIBRARY_RELEASE}")
  85. endif()
  86. if(EXISTS "${TIFF_LIBRARY_DEBUG}")
  87. set_property(TARGET TIFF::TIFF APPEND PROPERTY
  88. IMPORTED_CONFIGURATIONS DEBUG)
  89. set_target_properties(TIFF::TIFF PROPERTIES
  90. IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG "C"
  91. IMPORTED_LOCATION_DEBUG "${TIFF_LIBRARY_DEBUG}")
  92. endif()
  93. endif()
  94. endif()
  95. mark_as_advanced(TIFF_INCLUDE_DIR TIFF_LIBRARY)