FindTIFF.cmake 3.4 KB

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