summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2018-11-21 12:41:21 (GMT)
committerKitware Robot <kwrobot@kitware.com>2018-11-21 12:41:27 (GMT)
commit2b427c2fadc917ebcaf2f246d53504ce5b6ad754 (patch)
treeaa6bc418e2f3861e25d9af347f8df74d7993c636
parent8b83d1fdffeab9d24946552a9b8252c2e0dc4570 (diff)
parent74cc42e937e3117e9514f0c1561f212a8867bc92 (diff)
downloadCMake-2b427c2fadc917ebcaf2f246d53504ce5b6ad754.zip
CMake-2b427c2fadc917ebcaf2f246d53504ce5b6ad754.tar.gz
CMake-2b427c2fadc917ebcaf2f246d53504ce5b6ad754.tar.bz2
Merge topic 'FindGIF-modernize'
74cc42e937 Help: Add notes for topic 'FindGIF-modernize' 6962a41e6b FindGIF: Add test 5bc64fe6c2 FindGIF: Modernize Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !2632
-rw-r--r--Help/release/dev/FindGIF-modernize.rst4
-rw-r--r--Modules/FindGIF.cmake60
-rw-r--r--Tests/CMakeLists.txt4
-rw-r--r--Tests/FindGIF/CMakeLists.txt10
-rw-r--r--Tests/FindGIF/Test/CMakeLists.txt16
-rw-r--r--Tests/FindGIF/Test/main.c35
6 files changed, 116 insertions, 13 deletions
diff --git a/Help/release/dev/FindGIF-modernize.rst b/Help/release/dev/FindGIF-modernize.rst
new file mode 100644
index 0000000..3bb4821
--- /dev/null
+++ b/Help/release/dev/FindGIF-modernize.rst
@@ -0,0 +1,4 @@
+FindGIF-modernize
+-----------------
+
+* The :module:`FindGIF` module now provides imported targets.
diff --git a/Modules/FindGIF.cmake b/Modules/FindGIF.cmake
index 9a995af..9687b57 100644
--- a/Modules/FindGIF.cmake
+++ b/Modules/FindGIF.cmake
@@ -7,22 +7,43 @@ FindGIF
This finds the GIF library (giflib)
-The module defines the following variables:
+Imported targets
+^^^^^^^^^^^^^^^^
+
+This module defines the following :prop_tgt:`IMPORTED` target:
+
+``GIF::GIF``
+ The giflib library, if found.
+
+Result variables
+^^^^^^^^^^^^^^^^
+
+This module will set the following variables in your project:
``GIF_FOUND``
- True if giflib was found
+ If false, do not try to use GIF.
+``GIF_INCLUDE_DIRS``
+ where to find gif_lib.h, etc.
``GIF_LIBRARIES``
- Libraries to link to in order to use giflib
-``GIF_INCLUDE_DIR``
- where to find the headers
+ the libraries needed to use GIF.
``GIF_VERSION``
- 3, 4 or a full version string (eg 5.1.4) for versions >= 4.1.6
+ 3, 4 or a full version string (eg 5.1.4) for versions >= 4.1.6.
+
+Cache variables
+^^^^^^^^^^^^^^^
+
+The following cache variables may also be set:
-The minimum required version of giflib can be specified using the
-standard syntax, e.g. find_package(GIF 4)
+``GIF_INCLUDE_DIR``
+ where to find the GIF headers.
+``GIF_LIBRARY``
+ where to find the GIF library.
+
+Hints
+^^^^^
-$GIF_DIR is an environment variable that would correspond to the
-./configure --prefix=$GIF_DIR
+``GIF_DIR`` is an environment variable that would correspond to the
+``./configure --prefix=$GIF_DIR``.
#]=======================================================================]
# Created by Eric Wing.
@@ -44,9 +65,6 @@ find_library(GIF_LIBRARY
PATH_SUFFIXES lib
)
-# see readme.txt
-set(GIF_LIBRARIES ${GIF_LIBRARY})
-
# Very basic version detection.
# The GIF_LIB_VERSION string in gif_lib.h seems to be unreliable, since it seems
# to be always " Version 2.0, " in versions 3.x of giflib.
@@ -90,4 +108,20 @@ include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(GIF REQUIRED_VARS GIF_LIBRARY GIF_INCLUDE_DIR
VERSION_VAR GIF_VERSION )
+if(GIF_FOUND)
+ set(GIF_INCLUDE_DIRS "${GIF_INCLUDE_DIR}")
+ set(GIF_LIBRARIES ${GIF_LIBRARY})
+
+ if(NOT TARGET GIF::GIF)
+ add_library(GIF::GIF UNKNOWN IMPORTED)
+ set_target_properties(GIF::GIF PROPERTIES
+ INTERFACE_INCLUDE_DIRECTORIES "${GIF_INCLUDE_DIRS}")
+ if(EXISTS "${GIF_LIBRARY}")
+ set_target_properties(GIF::GIF PROPERTIES
+ IMPORTED_LINK_INTERFACE_LANGUAGES "C"
+ IMPORTED_LOCATION "${GIF_LIBRARY}")
+ endif()
+ endif()
+endif()
+
mark_as_advanced(GIF_INCLUDE_DIR GIF_LIBRARY)
diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt
index 96cdfd0..8b5f2e9 100644
--- a/Tests/CMakeLists.txt
+++ b/Tests/CMakeLists.txt
@@ -1388,6 +1388,10 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release
add_subdirectory(FindGDAL)
endif()
+ if(CMake_TEST_FindGIF)
+ add_subdirectory(FindGIF)
+ endif()
+
if(CMake_TEST_FindGSL)
add_subdirectory(FindGSL)
endif()
diff --git a/Tests/FindGIF/CMakeLists.txt b/Tests/FindGIF/CMakeLists.txt
new file mode 100644
index 0000000..bac64af
--- /dev/null
+++ b/Tests/FindGIF/CMakeLists.txt
@@ -0,0 +1,10 @@
+add_test(NAME FindGIF.Test COMMAND
+ ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION>
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/FindGIF/Test"
+ "${CMake_BINARY_DIR}/Tests/FindGIF/Test"
+ ${build_generator_args}
+ --build-project TestFindGIF
+ --build-options ${build_options}
+ --test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION>
+ )
diff --git a/Tests/FindGIF/Test/CMakeLists.txt b/Tests/FindGIF/Test/CMakeLists.txt
new file mode 100644
index 0000000..961e636
--- /dev/null
+++ b/Tests/FindGIF/Test/CMakeLists.txt
@@ -0,0 +1,16 @@
+cmake_minimum_required(VERSION 3.4)
+project(TestFindGIF C)
+include(CTest)
+
+find_package(GIF REQUIRED)
+
+add_definitions(-DCMAKE_EXPECTED_GIF_VERSION="${GIF_VERSION}")
+
+add_executable(test_tgt main.c)
+target_link_libraries(test_tgt GIF::GIF)
+add_test(NAME test_tgt COMMAND test_tgt)
+
+add_executable(test_var main.c)
+target_include_directories(test_var PRIVATE ${GIF_INCLUDE_DIRS})
+target_link_libraries(test_var PRIVATE ${GIF_LIBRARIES})
+add_test(NAME test_var COMMAND test_var)
diff --git a/Tests/FindGIF/Test/main.c b/Tests/FindGIF/Test/main.c
new file mode 100644
index 0000000..4ed72ec
--- /dev/null
+++ b/Tests/FindGIF/Test/main.c
@@ -0,0 +1,35 @@
+#include <assert.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <gif_lib.h>
+
+// GIFLIB before version 5 didn't know this macro
+#ifndef GIFLIB_MAJOR
+# define GIFLIB_MAJOR 4
+#endif
+
+int main()
+{
+ // because of the API changes we have to test different functions depending
+ // on the version of GIFLIB
+#if GIFLIB_MAJOR >= 5
+ // test the linker
+ GifErrorString(D_GIF_SUCCEEDED);
+
+ // check the version
+ char gif_version_string[16];
+ snprintf(gif_version_string, 16, "%i.%i.%i", GIFLIB_MAJOR, GIFLIB_MINOR,
+ GIFLIB_RELEASE);
+
+ assert(strcmp(gif_version_string, CMAKE_EXPECTED_GIF_VERSION) == 0);
+#else
+ // test the linker
+ GifLastError();
+
+ // unfortunately there is no way to check the version in older version of
+ // GIFLIB
+#endif
+
+ return 0;
+}