summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex <10857-leha-bot@users.noreply.gitlab.kitware.com>2021-03-08 21:11:09 +0300
committerBrad King <brad.king@kitware.com>2021-03-18 10:42:02 -0400
commit73b27f6ae8c9599c9cfea13d8b3413837355ec8a (patch)
treee230cdbeff20e7d8e522c6a8c3a2be98e8f4acdf
parent52d3d1bdc5c099209d02e44130d352df55ffc9a0 (diff)
downloadcmake-73b27f6ae8c9599c9cfea13d8b3413837355ec8a.tar.gz
FindDevIL: add imported targets and tests
Fixes: #21900
-rw-r--r--Help/release/dev/FindDevIL-imported-targets.rst4
-rw-r--r--Modules/FindDevIL.cmake57
-rw-r--r--Tests/CMakeLists.txt1
-rw-r--r--Tests/FindDevIL/CMakeLists.txt10
-rw-r--r--Tests/FindDevIL/Test/CMakeLists.txt29
-rw-r--r--Tests/FindDevIL/Test/main.c10
-rw-r--r--Tests/FindDevIL/Test/main_ilu.c8
7 files changed, 119 insertions, 0 deletions
diff --git a/Help/release/dev/FindDevIL-imported-targets.rst b/Help/release/dev/FindDevIL-imported-targets.rst
new file mode 100644
index 0000000000..aa0929ea0f
--- /dev/null
+++ b/Help/release/dev/FindDevIL-imported-targets.rst
@@ -0,0 +1,4 @@
+FindDevIL
+---------
+
+* The :module:`FindDevIL` module now provides imported targets.
diff --git a/Modules/FindDevIL.cmake b/Modules/FindDevIL.cmake
index e01cdcd15b..c8e5e31549 100644
--- a/Modules/FindDevIL.cmake
+++ b/Modules/FindDevIL.cmake
@@ -10,6 +10,25 @@ FindDevIL
This module locates the developer's image library.
http://openil.sourceforge.net/
+IMPORTED Targets
+^^^^^^^^^^^^^^^^
+
+.. versionadded:: 3.21
+
+This module defines the :prop_tgt:`IMPORTED` targets:
+
+``DevIL::IL``
+ Defined if the system has DevIL.
+
+``DevIL::ILU``
+ Defined if the system has DevIL Utilities.
+
+``DevIL::ILUT``
+ Defined if the system has DevIL Utility Toolkit.
+
+Result Variables
+^^^^^^^^^^^^^^^^
+
This module sets:
``IL_LIBRARIES``
@@ -37,6 +56,11 @@ This module sets:
even if they are not needed. In most systems, if one
library is found all the others are as well. That's the
way the DevIL developers release it.
+
+``DevIL_ILUT_FOUND``
+ .. versionadded:: 3.21
+
+ This is set to TRUE if the ILUT library is found.
#]=======================================================================]
# TODO: Add version support.
@@ -80,3 +104,36 @@ FIND_PACKAGE_HANDLE_STANDARD_ARGS(DevIL DEFAULT_MSG
IL_INCLUDE_DIR)
# provide legacy variable for compatibility
set(IL_FOUND ${DevIL_FOUND})
+
+# create imported targets ONLY if we found DevIL.
+if(DevIL_FOUND)
+ # Report the ILUT found if ILUT_LIBRARIES contains valid path.
+ if (ILUT_LIBRARIES)
+ set(DevIL_ILUT_FOUND TRUE)
+ else()
+ set(DevIL_ILUT_FOUND FALSE)
+ endif()
+
+ if(NOT TARGET DevIL::IL)
+ add_library(DevIL::IL UNKNOWN IMPORTED)
+ set_target_properties(DevIL::IL PROPERTIES
+ INTERFACE_INCLUDE_DIRECTORIES "${IL_INCLUDE_DIR}"
+ IMPORTED_LOCATION "${IL_LIBRARIES}")
+ endif()
+
+ # DevIL Utilities target
+ if(NOT TARGET DevIL::ILU)
+ add_library(DevIL::ILU UNKNOWN IMPORTED)
+ set_target_properties(DevIL::ILU PROPERTIES
+ IMPORTED_LOCATION "${ILU_LIBRARIES}")
+ target_link_libraries(DevIL::ILU INTERFACE DevIL::IL)
+ endif()
+
+ # ILUT (if found)
+ if(NOT TARGET DevIL::ILUT AND DevIL_ILUT_FOUND)
+ add_library(DevIL::ILUT UNKNOWN IMPORTED)
+ set_target_properties(DevIL::ILUT PROPERTIES
+ IMPORTED_LOCATION "${ILUT_LIBRARIES}")
+ target_link_libraries(DevIL::ILUT INTERFACE DevIL::ILU)
+ endif()
+endif()
diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt
index 0430afb77f..e532acef3a 100644
--- a/Tests/CMakeLists.txt
+++ b/Tests/CMakeLists.txt
@@ -1424,6 +1424,7 @@ if(BUILD_TESTING)
CURL
Cups
Doxygen
+ DevIL
EnvModules
EXPAT
Fontconfig
diff --git a/Tests/FindDevIL/CMakeLists.txt b/Tests/FindDevIL/CMakeLists.txt
new file mode 100644
index 0000000000..d37d50faf5
--- /dev/null
+++ b/Tests/FindDevIL/CMakeLists.txt
@@ -0,0 +1,10 @@
+add_test(NAME FindDevIL.Test COMMAND
+ ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION>
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/FindDevIL/Test"
+ "${CMake_BINARY_DIR}/Tests/FindDevIL/Test"
+ ${build_generator_args}
+ --build-project TestFindDevIL
+ --build-options ${build_options}
+ --test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION>
+ )
diff --git a/Tests/FindDevIL/Test/CMakeLists.txt b/Tests/FindDevIL/Test/CMakeLists.txt
new file mode 100644
index 0000000000..c2c132223e
--- /dev/null
+++ b/Tests/FindDevIL/Test/CMakeLists.txt
@@ -0,0 +1,29 @@
+cmake_minimum_required(VERSION 3.1)
+project(TestFindDevIL C)
+include(CTest)
+
+find_package(DevIL)
+
+#FIXME: check version too.
+# add_definitions(
+# -DCMAKE_EXPECTED_SDL_VERSION_MAJOR=${SDL_VERSION_MAJOR}
+# -DCMAKE_EXPECTED_SDL_VERSION_MINOR=${SDL_VERSION_MINOR}
+# -DCMAKE_EXPECTED_SDL_VERSION_PATCH=${SDL_VERSION_PATCH})
+
+add_executable(test_devil_var main.c)
+target_include_directories(test_devil_var PRIVATE ${IL_INCLUDE_DIRS})
+target_link_libraries(test_devil_var PRIVATE ${IL_LIBRARIES})
+add_test(NAME test_devil_var COMMAND test_devil_var)
+
+add_executable(test_devil_il_tgt main.c)
+target_link_libraries(test_devil_il_tgt DevIL::IL)
+add_test(NAME test_devil_il_tgt COMMAND test_devil_il_tgt)
+
+add_executable(test_devil_ilu_tgt main_ilu.c)
+target_link_libraries(test_devil_ilu_tgt DevIL::ILU)
+
+add_executable(test_devil_ilu_var main_ilu.c)
+target_include_directories(test_devil_ilu_var PRIVATE ${IL_INCLUDE_DIRS} ${ILU_INCLUDE_DIRS})
+target_link_libraries(test_devil_ilu_var ${IL_LIBRARIES} ${ILU_LIBRARIES})
+
+#FIXME: Check DevIL::ILUT target
diff --git a/Tests/FindDevIL/Test/main.c b/Tests/FindDevIL/Test/main.c
new file mode 100644
index 0000000000..4a07087200
--- /dev/null
+++ b/Tests/FindDevIL/Test/main.c
@@ -0,0 +1,10 @@
+#include <IL/il.h>
+
+int main()
+{
+ // Test 1 requires to link to the library.
+ ilInit();
+
+ ilShutDown();
+ return 0;
+}
diff --git a/Tests/FindDevIL/Test/main_ilu.c b/Tests/FindDevIL/Test/main_ilu.c
new file mode 100644
index 0000000000..a9e7819ba6
--- /dev/null
+++ b/Tests/FindDevIL/Test/main_ilu.c
@@ -0,0 +1,8 @@
+#include <IL/ilu.h>
+
+int main()
+{
+ // IL Utilities requires only initialization.
+ // Unlike main DevIL there are no shutdown function.
+ iluInit();
+}