From 471c5755fcd28d67801756ff167ee4263fd44b92 Mon Sep 17 00:00:00 2001 From: James Zern Date: Wed, 5 Jul 2017 23:52:04 -0700 Subject: [PATCH] cmake: fix gif lib detection when cross compiling GIF find_package only locates the header and library, it doesn't fail compile tests when detecting the version, but falls back to 3 (as of at least cmake 3.7.2). Make sure the library links to avoid incorrect detection when cross compiling. Change-Id: I0224180bbdf800ab261a9333236730b23c006e69 --- cmake/config.h.cmake | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/cmake/config.h.cmake b/cmake/config.h.cmake index 20f62d06..693fa5f0 100644 --- a/cmake/config.h.cmake +++ b/cmake/config.h.cmake @@ -75,13 +75,34 @@ foreach(I_LIB PNG JPEG TIFF) endforeach() # GIF detection, gifdec isn't part of the imageio lib. +include(CMakePushCheckState) set(WEBP_DEP_GIF_LIBRARIES) set(WEBP_DEP_GIF_INCLUDE_DIRS) find_package(GIF) set(WEBP_HAVE_GIF ${GIF_FOUND}) if(GIF_FOUND) - list(APPEND WEBP_DEP_GIF_LIBRARIES ${GIF_LIBRARIES}) - list(APPEND WEBP_DEP_GIF_INCLUDE_DIRS ${GIF_INCLUDE_DIR}) + # GIF find_package only locates the header and library, it doesn't fail + # compile tests when detecting the version, but falls back to 3 (as of at + # least cmake 3.7.2). Make sure the library links to avoid incorrect + # detection when cross compiling. + cmake_push_check_state() + set(CMAKE_REQUIRED_LIBRARIES ${GIF_LIBRARIES}) + set(CMAKE_REQUIRED_INCLUDES ${GIF_INCLUDE_DIR}) + check_c_source_compiles(" + #include + int main(void) { + (void)DGifOpenFileHandle; + return 0; + } + " GIF_COMPILES + ) + cmake_pop_check_state() + if(GIF_COMPILES) + list(APPEND WEBP_DEP_GIF_LIBRARIES ${GIF_LIBRARIES}) + list(APPEND WEBP_DEP_GIF_INCLUDE_DIRS ${GIF_INCLUDE_DIR}) + else() + unset(GIF_FOUND) + endif() endif() ## Check for specific headers.