FindDevIL.cmake 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file LICENSE.rst or https://cmake.org/licensing for details.
  3. #[=======================================================================[.rst:
  4. FindDevIL
  5. ---------
  6. Finds the Developer's Image Library, `DevIL <https://openil.sourceforge.net/>`_:
  7. .. code-block:: cmake
  8. find_package(DevIL [<version>] [...])
  9. .. versionadded:: 4.2
  10. Support for the ``<version>`` argument in the :command:`find_package`
  11. call. Version can be also specified as a range.
  12. The DevIL package internally consists of the following libraries, all
  13. distributed as part of the same release:
  14. * The core Image Library (IL)
  15. This library is always required when working with DevIL, as it provides the
  16. main image loading and manipulation functionality.
  17. * The Image Library Utilities (ILU)
  18. This library depends on IL and provides image filters and effects. It is only
  19. required if the application uses this extended functionality.
  20. * The Image Library Utility Toolkit (ILUT)
  21. This library depends on both IL and ILU, and additionally provides an
  22. interface to OpenGL. It is only needed if the application uses DevIL together
  23. with OpenGL.
  24. Imported Targets
  25. ^^^^^^^^^^^^^^^^
  26. This module provides the following :ref:`Imported Targets`:
  27. ``DevIL::IL``
  28. .. versionadded:: 3.21
  29. Target encapsulating the core Image Library (IL) usage requirements, available
  30. if the DevIL package is found.
  31. ``DevIL::ILU``
  32. .. versionadded:: 3.21
  33. Target encapsulating the Image Library Utilities (ILU) usage requirements,
  34. available if the DevIL package is found. This target also links to
  35. ``DevIL::IL`` for convenience, as ILU depends on the core IL library.
  36. ``DevIL::ILUT``
  37. .. versionadded:: 3.21
  38. Target encapsulating the Image Library Utility Toolkit (ILUT) usage
  39. requirements, available if the DevIL package and its ILUT library are found.
  40. This target also links to ``DevIL::ILU``, and transitively to ``DevIL::IL``,
  41. since ILUT depends on both.
  42. Result Variables
  43. ^^^^^^^^^^^^^^^^
  44. This module defines the following variables:
  45. ``DevIL_FOUND``
  46. .. versionadded:: 3.8
  47. Boolean indicating whether the (requested version of) DevIL package was
  48. found, including the IL and ILU libraries.
  49. ``DevIL_VERSION``
  50. .. versionadded:: 4.2
  51. The version of the DevIL found.
  52. ``DevIL_ILUT_FOUND``
  53. .. versionadded:: 3.21
  54. Boolean indicating whether the ILUT library was found. On most systems,
  55. ILUT is found when both IL and ILU are available.
  56. Cache Variables
  57. ^^^^^^^^^^^^^^^
  58. The following cache variables may also be set:
  59. ``IL_INCLUDE_DIR``
  60. The directory containing the ``il.h``, ``ilu.h`` and ``ilut.h`` header files.
  61. ``IL_LIBRARIES``
  62. The full path to the core Image Library (IL).
  63. ``ILU_LIBRARIES``
  64. The full path to the ILU library.
  65. ``ILUT_LIBRARIES``
  66. The full path to the ILUT library.
  67. Examples
  68. ^^^^^^^^
  69. Finding the DevIL package and linking against the core Image Library (IL):
  70. .. code-block:: cmake
  71. find_package(DevIL)
  72. target_link_libraries(app PRIVATE DevIL::IL)
  73. Linking against the Image Library Utilities (ILU):
  74. .. code-block:: cmake
  75. find_package(DevIL)
  76. target_link_libraries(app PRIVATE DevIL::ILU)
  77. Linking against the Image Library Utility Toolkit (ILUT):
  78. .. code-block:: cmake
  79. find_package(DevIL)
  80. target_link_libraries(app PRIVATE DevIL::ILUT)
  81. #]=======================================================================]
  82. cmake_policy(PUSH)
  83. cmake_policy(SET CMP0159 NEW) # file(STRINGS) with REGEX updates CMAKE_MATCH_<n>
  84. include(FindPackageHandleStandardArgs)
  85. find_path(IL_INCLUDE_DIR il.h
  86. PATH_SUFFIXES include IL
  87. DOC "The path to the directory that contains il.h"
  88. )
  89. find_library(IL_LIBRARIES
  90. NAMES IL DEVIL
  91. PATH_SUFFIXES libx32 lib64 lib lib32
  92. DOC "The file that corresponds to the base il library."
  93. )
  94. find_library(ILUT_LIBRARIES
  95. NAMES ILUT
  96. PATH_SUFFIXES libx32 lib64 lib lib32
  97. DOC "The file that corresponds to the il (system?) utility library."
  98. )
  99. find_library(ILU_LIBRARIES
  100. NAMES ILU
  101. PATH_SUFFIXES libx32 lib64 lib lib32
  102. DOC "The file that corresponds to the il utility library."
  103. )
  104. # Get version.
  105. block(PROPAGATE DevIL_VERSION)
  106. if(IL_INCLUDE_DIR AND EXISTS "${IL_INCLUDE_DIR}/il.h")
  107. set(regex "^[ \t]*#[ \t]*define[ \t]+IL_VERSION[ \t]+([0-9]+)[ \t]*$")
  108. file(STRINGS ${IL_INCLUDE_DIR}/il.h result REGEX "${regex}")
  109. if(result MATCHES "${regex}")
  110. set(DevIL_VERSION "${CMAKE_MATCH_1}")
  111. math(EXPR DevIL_VERSION_MAJOR "${DevIL_VERSION} / 100")
  112. math(EXPR DevIL_VERSION_MINOR "${DevIL_VERSION} / 10 % 10")
  113. math(EXPR DevIL_VERSION_PATCH "${DevIL_VERSION} % 10")
  114. set(DevIL_VERSION "")
  115. foreach(part MAJOR MINOR PATCH)
  116. if(DevIL_VERSION)
  117. string(APPEND ".${DevIL_VERSION_${part}}")
  118. else()
  119. set(DevIL_VERSION "${DevIL_VERSION_${part}}")
  120. endif()
  121. set(
  122. DevIL_VERSION
  123. "${DevIL_VERSION_MAJOR}.${DevIL_VERSION_MINOR}.${DevIL_VERSION_PATCH}"
  124. )
  125. endforeach()
  126. endif()
  127. endif()
  128. endblock()
  129. find_package_handle_standard_args(
  130. DevIL
  131. REQUIRED_VARS IL_LIBRARIES ILU_LIBRARIES IL_INCLUDE_DIR
  132. VERSION_VAR DevIL_VERSION
  133. HANDLE_VERSION_RANGE
  134. )
  135. # provide legacy variable for compatibility
  136. set(IL_FOUND ${DevIL_FOUND})
  137. # create imported targets ONLY if we found DevIL.
  138. if(DevIL_FOUND)
  139. # Report the ILUT found if ILUT_LIBRARIES contains valid path.
  140. if (ILUT_LIBRARIES)
  141. set(DevIL_ILUT_FOUND TRUE)
  142. else()
  143. set(DevIL_ILUT_FOUND FALSE)
  144. endif()
  145. if(NOT TARGET DevIL::IL)
  146. add_library(DevIL::IL UNKNOWN IMPORTED)
  147. set_target_properties(DevIL::IL PROPERTIES
  148. INTERFACE_INCLUDE_DIRECTORIES "${IL_INCLUDE_DIR}"
  149. IMPORTED_LOCATION "${IL_LIBRARIES}")
  150. endif()
  151. # DevIL Utilities target
  152. if(NOT TARGET DevIL::ILU)
  153. add_library(DevIL::ILU UNKNOWN IMPORTED)
  154. set_target_properties(DevIL::ILU PROPERTIES
  155. IMPORTED_LOCATION "${ILU_LIBRARIES}")
  156. target_link_libraries(DevIL::ILU INTERFACE DevIL::IL)
  157. endif()
  158. # ILUT (if found)
  159. if(NOT TARGET DevIL::ILUT AND DevIL_ILUT_FOUND)
  160. add_library(DevIL::ILUT UNKNOWN IMPORTED)
  161. set_target_properties(DevIL::ILUT PROPERTIES
  162. IMPORTED_LOCATION "${ILUT_LIBRARIES}")
  163. target_link_libraries(DevIL::ILUT INTERFACE DevIL::ILU)
  164. endif()
  165. endif()
  166. cmake_policy(POP)