1# Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
2# file Copyright.txt or https://cmake.org/licensing for details.
3
4#[=======================================================================[.rst:
5FindDevIL
6---------
7
8
9
10This module locates the developer's image library.
11http://openil.sourceforge.net/
12
13IMPORTED Targets
14^^^^^^^^^^^^^^^^
15
16.. versionadded:: 3.21
17
18This module defines the :prop_tgt:`IMPORTED` targets:
19
20``DevIL::IL``
21 Defined if the system has DevIL.
22
23``DevIL::ILU``
24 Defined if the system has DevIL Utilities.
25
26``DevIL::ILUT``
27 Defined if the system has DevIL Utility Toolkit.
28
29Result Variables
30^^^^^^^^^^^^^^^^
31
32This module sets:
33
34``IL_LIBRARIES``
35  The name of the IL library. These include the full path to
36  the core DevIL library. This one has to be linked into the
37  application.
38
39``ILU_LIBRARIES``
40  The name of the ILU library. Again, the full path. This
41  library is for filters and effects, not actual loading. It
42  doesn't have to be linked if the functionality it provides
43  is not used.
44
45``ILUT_LIBRARIES``
46  The name of the ILUT library. Full path. This part of the
47  library interfaces with OpenGL. It is not strictly needed
48  in applications.
49
50``IL_INCLUDE_DIR``
51  where to find the il.h, ilu.h and ilut.h files.
52
53``DevIL_FOUND``
54  This is set to TRUE if all the above variables were set.
55  This will be set to false if ILU or ILUT are not found,
56  even if they are not needed. In most systems, if one
57  library is found all the others are as well. That's the
58  way the DevIL developers release it.
59
60``DevIL_ILUT_FOUND``
61  .. versionadded:: 3.21
62
63  This is set to TRUE if the ILUT library is found.
64#]=======================================================================]
65
66# TODO: Add version support.
67# Tested under Linux and Windows (MSVC)
68
69include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
70
71find_path(IL_INCLUDE_DIR il.h
72  PATH_SUFFIXES include IL
73  DOC "The path to the directory that contains il.h"
74)
75
76#message("IL_INCLUDE_DIR is ${IL_INCLUDE_DIR}")
77
78find_library(IL_LIBRARIES
79  NAMES IL DEVIL
80  PATH_SUFFIXES libx32 lib64 lib lib32
81  DOC "The file that corresponds to the base il library."
82)
83
84#message("IL_LIBRARIES is ${IL_LIBRARIES}")
85
86find_library(ILUT_LIBRARIES
87  NAMES ILUT
88  PATH_SUFFIXES libx32 lib64 lib lib32
89  DOC "The file that corresponds to the il (system?) utility library."
90)
91
92#message("ILUT_LIBRARIES is ${ILUT_LIBRARIES}")
93
94find_library(ILU_LIBRARIES
95  NAMES ILU
96  PATH_SUFFIXES libx32 lib64 lib lib32
97  DOC "The file that corresponds to the il utility library."
98)
99
100#message("ILU_LIBRARIES is ${ILU_LIBRARIES}")
101
102FIND_PACKAGE_HANDLE_STANDARD_ARGS(DevIL DEFAULT_MSG
103                                  IL_LIBRARIES ILU_LIBRARIES
104                                  IL_INCLUDE_DIR)
105# provide legacy variable for compatibility
106set(IL_FOUND ${DevIL_FOUND})
107
108# create imported targets ONLY if we found DevIL.
109if(DevIL_FOUND)
110  # Report the ILUT found if ILUT_LIBRARIES contains valid path.
111  if (ILUT_LIBRARIES)
112    set(DevIL_ILUT_FOUND TRUE)
113  else()
114    set(DevIL_ILUT_FOUND FALSE)
115  endif()
116
117  if(NOT TARGET DevIL::IL)
118    add_library(DevIL::IL UNKNOWN IMPORTED)
119    set_target_properties(DevIL::IL PROPERTIES
120      INTERFACE_INCLUDE_DIRECTORIES "${IL_INCLUDE_DIR}"
121      IMPORTED_LOCATION "${IL_LIBRARIES}")
122  endif()
123
124  # DevIL Utilities target
125  if(NOT TARGET DevIL::ILU)
126    add_library(DevIL::ILU UNKNOWN IMPORTED)
127    set_target_properties(DevIL::ILU PROPERTIES
128      IMPORTED_LOCATION "${ILU_LIBRARIES}")
129    target_link_libraries(DevIL::ILU INTERFACE DevIL::IL)
130  endif()
131
132  # ILUT (if found)
133  if(NOT TARGET DevIL::ILUT AND DevIL_ILUT_FOUND)
134    add_library(DevIL::ILUT UNKNOWN IMPORTED)
135    set_target_properties(DevIL::ILUT PROPERTIES
136      IMPORTED_LOCATION "${ILUT_LIBRARIES}")
137    target_link_libraries(DevIL::ILUT INTERFACE DevIL::ILU)
138  endif()
139endif()
140