FindTIFF.cmake 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #.rst:
  2. # FindTIFF
  3. # --------
  4. #
  5. # Find the TIFF library (libtiff).
  6. #
  7. # Imported targets
  8. # ^^^^^^^^^^^^^^^^
  9. #
  10. # This module defines the following :prop_tgt:`IMPORTED` targets:
  11. #
  12. # ``TIFF::TIFF``
  13. # The TIFF library, if found.
  14. #
  15. # Result variables
  16. # ^^^^^^^^^^^^^^^^
  17. #
  18. # This module will set the following variables in your project:
  19. #
  20. # ``TIFF_FOUND``
  21. # true if the TIFF headers and libraries were found
  22. # ``TIFF_INCLUDE_DIR``
  23. # the directory containing the TIFF headers
  24. # ``TIFF_INCLUDE_DIRS``
  25. # the directory containing the TIFF headers
  26. # ``TIFF_LIBRARIES``
  27. # TIFF libraries to be linked
  28. #
  29. # Cache variables
  30. # ^^^^^^^^^^^^^^^
  31. #
  32. # The following cache variables may also be set:
  33. #
  34. # ``TIFF_INCLUDE_DIR``
  35. # the directory containing the TIFF headers
  36. # ``TIFF_LIBRARY``
  37. # the path to the TIFF library
  38. #=============================================================================
  39. # Copyright 2002-2009 Kitware, Inc.
  40. # Copyright 2015 University of Dundee
  41. #
  42. # Distributed under the OSI-approved BSD License (the "License");
  43. # see accompanying file Copyright.txt for details.
  44. #
  45. # This software is distributed WITHOUT ANY WARRANTY; without even the
  46. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  47. # See the License for more information.
  48. #=============================================================================
  49. # (To distribute this file outside of CMake, substitute the full
  50. # License text for the above reference.)
  51. find_path(TIFF_INCLUDE_DIR tiff.h)
  52. set(TIFF_NAMES ${TIFF_NAMES} tiff libtiff tiff3 libtiff3)
  53. foreach(name ${TIFF_NAMES})
  54. list(APPEND TIFF_NAMES_DEBUG "${name}d")
  55. endforeach()
  56. if(NOT TIFF_LIBRARY)
  57. find_library(TIFF_LIBRARY_RELEASE NAMES ${TIFF_NAMES})
  58. find_library(TIFF_LIBRARY_DEBUG NAMES ${TIFF_NAMES_DEBUG})
  59. include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake)
  60. select_library_configurations(TIFF)
  61. mark_as_advanced(TIFF_LIBRARY_RELEASE TIFF_LIBRARY_DEBUG)
  62. endif()
  63. unset(TIFF_NAMES)
  64. unset(TIFF_NAMES_DEBUG)
  65. if(TIFF_INCLUDE_DIR AND EXISTS "${TIFF_INCLUDE_DIR}/tiffvers.h")
  66. file(STRINGS "${TIFF_INCLUDE_DIR}/tiffvers.h" tiff_version_str
  67. REGEX "^#define[\t ]+TIFFLIB_VERSION_STR[\t ]+\"LIBTIFF, Version .*")
  68. string(REGEX REPLACE "^#define[\t ]+TIFFLIB_VERSION_STR[\t ]+\"LIBTIFF, Version +([^ \\n]*).*"
  69. "\\1" TIFF_VERSION_STRING "${tiff_version_str}")
  70. unset(tiff_version_str)
  71. endif()
  72. # handle the QUIETLY and REQUIRED arguments and set TIFF_FOUND to TRUE if
  73. # all listed variables are TRUE
  74. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  75. FIND_PACKAGE_HANDLE_STANDARD_ARGS(TIFF
  76. REQUIRED_VARS TIFF_LIBRARY TIFF_INCLUDE_DIR
  77. VERSION_VAR TIFF_VERSION_STRING)
  78. if(TIFF_FOUND)
  79. set(TIFF_LIBRARIES ${TIFF_LIBRARY})
  80. set(TIFF_INCLUDE_DIRS "${TIFF_INCLUDE_DIR}")
  81. if(NOT TARGET TIFF::TIFF)
  82. add_library(TIFF::TIFF UNKNOWN IMPORTED)
  83. if(TIFF_INCLUDE_DIRS)
  84. set_target_properties(TIFF::TIFF PROPERTIES
  85. INTERFACE_INCLUDE_DIRECTORIES "${TIFF_INCLUDE_DIRS}")
  86. endif()
  87. if(EXISTS "${TIFF_LIBRARY}")
  88. set_target_properties(TIFF::TIFF PROPERTIES
  89. IMPORTED_LINK_INTERFACE_LANGUAGES "C"
  90. IMPORTED_LOCATION "${TIFF_LIBRARY}")
  91. endif()
  92. if(EXISTS "${TIFF_LIBRARY_DEBUG}")
  93. set_property(TARGET TIFF::TIFF APPEND PROPERTY
  94. IMPORTED_CONFIGURATIONS DEBUG)
  95. set_target_properties(TIFF::TIFF PROPERTIES
  96. IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG "C"
  97. IMPORTED_LOCATION_DEBUG "${TIFF_LIBRARY_DEBUG}")
  98. endif()
  99. if(EXISTS "${TIFF_LIBRARY_RELEASE}")
  100. set_property(TARGET TIFF::TIFF APPEND PROPERTY
  101. IMPORTED_CONFIGURATIONS RELEASE)
  102. set_target_properties(TIFF::TIFF PROPERTIES
  103. IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "C"
  104. IMPORTED_LOCATION_RELEASE "${TIFF_LIBRARY_RELEASE}")
  105. endif()
  106. endif()
  107. endif()
  108. mark_as_advanced(TIFF_INCLUDE_DIR TIFF_LIBRARY)