FindJPEG.cmake 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. FindJPEG
  5. --------
  6. Find the Joint Photographic Experts Group (JPEG) library (``libjpeg``)
  7. Imported targets
  8. ^^^^^^^^^^^^^^^^
  9. This module defines the following :prop_tgt:`IMPORTED` targets:
  10. ``JPEG::JPEG``
  11. The JPEG library, if found.
  12. Result variables
  13. ^^^^^^^^^^^^^^^^
  14. This module will set the following variables in your project:
  15. ``JPEG_FOUND``
  16. If false, do not try to use JPEG.
  17. ``JPEG_INCLUDE_DIRS``
  18. where to find jpeglib.h, etc.
  19. ``JPEG_LIBRARIES``
  20. the libraries needed to use JPEG.
  21. ``JPEG_VERSION``
  22. the version of the JPEG library found
  23. Cache variables
  24. ^^^^^^^^^^^^^^^
  25. The following cache variables may also be set:
  26. ``JPEG_INCLUDE_DIRS``
  27. where to find jpeglib.h, etc.
  28. ``JPEG_LIBRARY_RELEASE``
  29. where to find the JPEG library (optimized).
  30. ``JPEG_LIBRARY_DEBUG``
  31. where to find the JPEG library (debug).
  32. Obsolete variables
  33. ^^^^^^^^^^^^^^^^^^
  34. ``JPEG_INCLUDE_DIR``
  35. where to find jpeglib.h, etc. (same as JPEG_INCLUDE_DIRS)
  36. ``JPEG_LIBRARY``
  37. where to find the JPEG library.
  38. #]=======================================================================]
  39. find_path(JPEG_INCLUDE_DIR jpeglib.h)
  40. set(jpeg_names ${JPEG_NAMES} jpeg jpeg-static libjpeg libjpeg-static)
  41. foreach(name ${jpeg_names})
  42. list(APPEND jpeg_names_debug "${name}d")
  43. endforeach()
  44. if(NOT JPEG_LIBRARY)
  45. find_library(JPEG_LIBRARY_RELEASE NAMES ${jpeg_names})
  46. find_library(JPEG_LIBRARY_DEBUG NAMES ${jpeg_names_debug})
  47. include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake)
  48. select_library_configurations(JPEG)
  49. mark_as_advanced(JPEG_LIBRARY_RELEASE JPEG_LIBRARY_DEBUG)
  50. endif()
  51. unset(jpeg_names)
  52. unset(jpeg_names_debug)
  53. if(JPEG_INCLUDE_DIR)
  54. file(GLOB _JPEG_CONFIG_HEADERS_FEDORA "${JPEG_INCLUDE_DIR}/jconfig*.h")
  55. file(GLOB _JPEG_CONFIG_HEADERS_DEBIAN "${JPEG_INCLUDE_DIR}/*/jconfig.h")
  56. set(_JPEG_CONFIG_HEADERS
  57. "${JPEG_INCLUDE_DIR}/jpeglib.h"
  58. ${_JPEG_CONFIG_HEADERS_FEDORA}
  59. ${_JPEG_CONFIG_HEADERS_DEBIAN})
  60. foreach (_JPEG_CONFIG_HEADER IN LISTS _JPEG_CONFIG_HEADERS)
  61. if (NOT EXISTS "${_JPEG_CONFIG_HEADER}")
  62. continue ()
  63. endif ()
  64. file(STRINGS "${_JPEG_CONFIG_HEADER}"
  65. jpeg_lib_version REGEX "^#define[\t ]+JPEG_LIB_VERSION[\t ]+.*")
  66. if (NOT jpeg_lib_version)
  67. continue ()
  68. endif ()
  69. string(REGEX REPLACE "^#define[\t ]+JPEG_LIB_VERSION[\t ]+([0-9]+).*"
  70. "\\1" JPEG_VERSION "${jpeg_lib_version}")
  71. break ()
  72. endforeach ()
  73. unset(jpeg_lib_version)
  74. unset(_JPEG_CONFIG_HEADER)
  75. unset(_JPEG_CONFIG_HEADERS)
  76. unset(_JPEG_CONFIG_HEADERS_FEDORA)
  77. unset(_JPEG_CONFIG_HEADERS_DEBIAN)
  78. endif()
  79. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  80. find_package_handle_standard_args(JPEG
  81. REQUIRED_VARS JPEG_LIBRARY JPEG_INCLUDE_DIR
  82. VERSION_VAR JPEG_VERSION)
  83. if(JPEG_FOUND)
  84. set(JPEG_LIBRARIES ${JPEG_LIBRARY})
  85. set(JPEG_INCLUDE_DIRS "${JPEG_INCLUDE_DIR}")
  86. if(NOT TARGET JPEG::JPEG)
  87. add_library(JPEG::JPEG UNKNOWN IMPORTED)
  88. if(JPEG_INCLUDE_DIRS)
  89. set_target_properties(JPEG::JPEG PROPERTIES
  90. INTERFACE_INCLUDE_DIRECTORIES "${JPEG_INCLUDE_DIRS}")
  91. endif()
  92. if(EXISTS "${JPEG_LIBRARY}")
  93. set_target_properties(JPEG::JPEG PROPERTIES
  94. IMPORTED_LINK_INTERFACE_LANGUAGES "C"
  95. IMPORTED_LOCATION "${JPEG_LIBRARY}")
  96. endif()
  97. if(EXISTS "${JPEG_LIBRARY_RELEASE}")
  98. set_property(TARGET JPEG::JPEG APPEND PROPERTY
  99. IMPORTED_CONFIGURATIONS RELEASE)
  100. set_target_properties(JPEG::JPEG PROPERTIES
  101. IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "C"
  102. IMPORTED_LOCATION_RELEASE "${JPEG_LIBRARY_RELEASE}")
  103. endif()
  104. if(EXISTS "${JPEG_LIBRARY_DEBUG}")
  105. set_property(TARGET JPEG::JPEG APPEND PROPERTY
  106. IMPORTED_CONFIGURATIONS DEBUG)
  107. set_target_properties(JPEG::JPEG PROPERTIES
  108. IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG "C"
  109. IMPORTED_LOCATION_DEBUG "${JPEG_LIBRARY_DEBUG}")
  110. endif()
  111. endif()
  112. endif()
  113. mark_as_advanced(JPEG_LIBRARY JPEG_INCLUDE_DIR)