[cmake-developers] [PATCH] Improve FindGIF version detection (fix for issue #16196)
Ben Campbell
ben at scumways.com
Tue Jul 12 23:16:46 EDT 2016
A fix for https://gitlab.kitware.com/cmake/cmake/issues/16196
This is my first attempt at doing anything with CMake, so I'd appreciate
any feedback on my patch! In particular, the pairs of file()/string()
commands seem a bit convoluted for extracting strings out of the header
file - is there a more idiomatic approach?
Also, I'm a bit concerned that they are polluting scope by leaking out
the GIFMAJ/GIFMIN/GIFREL working variables... how would I improve this?
---
Modules/FindGIF.cmake | 20 ++++++++++++++++++--
1 file changed, 18 insertions(+), 2 deletions(-)
diff --git a/Modules/FindGIF.cmake b/Modules/FindGIF.cmake
index 7bbb8cf..283a299 100644
--- a/Modules/FindGIF.cmake
+++ b/Modules/FindGIF.cmake
@@ -61,7 +61,8 @@ set(GIF_LIBRARIES ${GIF_LIBRARY})
# to be always " Version 2.0, " in versions 3.x of giflib.
# In version 4 the member UserData was added to GifFileType, so we
check for this
# one.
-# http://giflib.sourcearchive.com/documentation/4.1.4/files.html
+# Versions after 4.1.6 define GIFLIB_MAJOR, GIFLIB_MINOR, and
GIFLIB_RELEASE
+# see http://giflib.sourceforge.net/gif_lib.html#compatibility
if(GIF_INCLUDE_DIR)
include(${CMAKE_CURRENT_LIST_DIR}/CMakePushCheckState.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/CheckStructHasMember.cmake)
@@ -71,7 +72,22 @@ if(GIF_INCLUDE_DIR)
set(CMAKE_REQUIRED_INCLUDES "${GIF_INCLUDE_DIR}")
CHECK_STRUCT_HAS_MEMBER(GifFileType UserData gif_lib.h
GIF_GifFileType_UserData )
if(GIF_GifFileType_UserData)
- set(GIF_VERSION 4)
+ # OK. So we're version 4 or higher. Check for specific version defines
+ file(STRINGS ${GIF_INCLUDE_DIR}/gif_lib.h GIFMAJ REGEX "^[
\t]*#define[ \t]+GIFLIB_MAJOR")
+ string(REGEX REPLACE "^.*GIFLIB_MAJOR ([0-9]+).*$" "\\1" GIFMAJ
${GIFMAJ})
+ # extract minor version
+ file(STRINGS ${GIF_INCLUDE_DIR}/gif_lib.h GIFMIN REGEX "^[
\t]*#define[ \t]+GIFLIB_MINOR")
+ string(REGEX REPLACE "^.*GIFLIB_MINOR ([0-9]+).*$" "\\1" GIFMIN
${GIFMIN})
+ # point release
+ file(STRINGS ${GIF_INCLUDE_DIR}/gif_lib.h GIFREL REGEX "^[
\t]*#define[ \t]+GIFLIB_RELEASE")
+ string(REGEX REPLACE "^.*GIFLIB_RELEASE ([0-9]+).*$" "\\1" GIFREL
${GIFREL})
+ if(GIFMAJ)
+ # yay - got exact version info
+ set(GIF_VERSION ${GIFMAJ}.${GIFMIN}.${GIFREL})
+ else(GIFMAJ)
+ # couldn't find the defines - assume version 4
+ set(GIF_VERSION 4)
+ endif(GIFMAJ)
endif()
CMAKE_POP_CHECK_STATE()
endif()
--
2.7.4
More information about the cmake-developers
mailing list