Commits

pornel  committed cfa2336

Download libimagequant in cmakefile if needed

--HG--
branch : liq
extra : source : de3e993342bc3d4eefe4b638143a7657e0aafe62
extra : histedit_source : 961d951975c5df5b9da5848ce2b04777a2156890%2C12013ded8ac6e49f8af6e757daa1aad8299d3e65

  • Participants
  • Parent commits 46054d2

Comments (0)

Files changed (6)

 CPackConfig.cmake
 CPackSourceConfig.cmake
 CTestTestfile.cmake
+libimagequant
+libimagequant-prefix

File CMakeLists.txt

 SET(CMAKE_MODULE_PATH "${GD_SOURCE_DIR}/cmake/modules")
 
 OPTION(ENABLE_PNG "Enable PNG support" 1)
+OPTION(ENABLE_LIQ "Enable libimagequant support" 1)
 OPTION(ENABLE_JPEG "Enable JPEG support" 1)
 OPTION(ENABLE_TIFF "Enable TIFF support" 1)
 OPTION(ENABLE_XPM "Enable XPM support" 1)
 
 	FIND_PACKAGE(ZLIB)
 
+	IF (ENABLE_LIQ)
+		FIND_PACKAGE(LIQ)
+	ENDIF (ENABLE_LIQ)
+
 	IF (NOT WIN32)
 		FIND_PACKAGE(PTHREAD)
 	ENDIF (NOT WIN32)
 		SET(HAVE_LIBPNG 1)
 	ENDIF(PNG_FOUND)
 
+	IF(LIQ_FOUND)
+		INCLUDE_DIRECTORIES(${LIQ_INCLUDE_DIR})
+		SET(HAVE_LIBIMAGEQUANT_H 1)
+	ENDIF(LIQ_FOUND)
+
 	IF(XPM_FOUND)
 		INCLUDE_DIRECTORIES(${XPM_INCLUDE_DIR})
 		SET(HAVE_LIBXPM 1)
 	set(CPACK_GENERATOR TGZ)
 endif(WIN32)
 
+IF (ENABLE_LIQ AND LIQ_BUILD)
+    ADD_DEPENDENCIES(${GD_LIB} libimagequant)
+    ADD_DEPENDENCIES(${GD_LIB_STATIC} libimagequant)
+ENDIF(ENABLE_LIQ AND LIQ_BUILD)
 
 set(CPACK_SOURCE_GENERATOR TGZ)
 set(CPACK_SOURCE_IGNORE_FILES

File cmake/modules/FindLIQ.cmake

+# Find libimagequant includes and library (and download+build if needed)
+# http://pngquant.org/lib
+#
+# This module defines
+#  LIQ_INCLUDE_DIR, where to find libimagequant.h
+#  LIQ_LIBRARIES, the libraries to link against to use libimagequant.
+#  LIQ_FOUND, If false, do not try to use libimagequant.
+
+SET(LIQ_FOUND "NO")
+
+FIND_PATH(LIQ_INCLUDE_DIR libimagequant.h
+"${PROJECT_SOURCE_DIR}/libimagequant"
+"${PROJECT_SOURCE_DIR}/pngquant/lib"
+/usr/local/include
+/usr/include
+)
+
+FIND_LIBRARY(LIQ_LIBRARY
+  NAMES libimagequant imagequant
+  PATHS "${PROJECT_SOURCE_DIR}/libimagequant" "${PROJECT_SOURCE_DIR}/pngquant/lib" /usr/lib64 /usr/lib /usr/local/lib
+)
+
+IF (LIQ_LIBRARY AND LIQ_INCLUDE_DIR)
+    SET(LIQ_FOUND "YES")
+    SET(LIQ_LIBRARIES ${LIQ_LIBRARY})
+		SET(HAVE_LIBIMAGEQUANT_H 1)
+ENDIF (LIQ_LIBRARY AND LIQ_INCLUDE_DIR)
+
+IF (LIQ_FOUND)
+  IF (NOT LIQ_FIND_QUIETLY)
+    MESSAGE(STATUS "Found LIQ: ${LIQ_LIBRARY} ${LIQ_INCLUDE_DIR}")
+  ENDIF (NOT LIQ_FIND_QUIETLY)
+ELSE (LIQ_FOUND)
+  # if existing library not found, then download and build it
+  IF (NOT WIN32 OR CYGWIN OR MINGW) # MSVC's C compiler is too old to compile libimagequant
+    MESSAGE(STATUS "LIQ will be built")
+    INCLUDE(ExternalProject)
+    EXTERNALPROJECT_ADD(
+        libimagequant
+        URL "http://pngquant.org/libimagequant-2.0.0-src.tar.bz2"
+        SOURCE_DIR libimagequant
+        BUILD_IN_SOURCE 1
+        INSTALL_DIR libimagequant
+        INSTALL_COMMAND true
+        CONFIGURE_COMMAND true
+        BUILD_COMMAND make static
+    )
+
+    SET(LIQ_FOUND "SORTOF")
+    SET(LIQ_BUILD "YES")
+    SET(LIQ_LIBRARIES "${PROJECT_SOURCE_DIR}/libimagequant/libimagequant.a")
+    SET(LIQ_INCLUDE_DIR "${PROJECT_SOURCE_DIR}/libimagequant/")
+    SET(HAVE_LIBIMAGEQUANT_H 1)
+  ENDIF(NOT WIN32 OR CYGWIN OR MINGW)
+ENDIF (LIQ_FOUND)
+
+MARK_AS_ADVANCED(LIQ_INCLUDE_DIR LIQ_LIBRARIES LIQ_BUILD)

File src/CMakeLists.txt

 
 INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR}/  ${GD_SOURCE_DIR}/src)
 
-target_link_libraries(${GD_LIB} ${FREETYPE_LIBRARIES} ${PNG_LIBRARIES} ${JPEG_LIBRARIES} ${TIFF_LIBRARIES} ${XPM_LIBRARIES} ${FONTCONFIG_LIBRARY})
-target_link_libraries(${GD_LIB_STATIC} ${FREETYPE_LIBRARIES} ${PNG_LIBRARIES} ${JPEG_LIBRARIES} ${TIFF_LIBRARIES} ${XPM_LIBRARIES} ${FONTCONFIG_LIBRARY})
+target_link_libraries(${GD_LIB} ${FREETYPE_LIBRARIES} ${PNG_LIBRARIES} ${LIQ_LIBRARIES} ${JPEG_LIBRARIES} ${TIFF_LIBRARIES} ${XPM_LIBRARIES} ${FONTCONFIG_LIBRARY})
+target_link_libraries(${GD_LIB_STATIC} ${FREETYPE_LIBRARIES} ${PNG_LIBRARIES} ${LIQ_LIBRARIES} ${JPEG_LIBRARIES} ${TIFF_LIBRARIES} ${XPM_LIBRARIES} ${FONTCONFIG_LIBRARY})
 
 set(GD_PROGRAMS annotate gdparttopng gdtopng gd2copypal gd2topng pngtogd pngtogd2 webpng gd2togif gdcmpgif giftogd2)
 foreach(program ${GD_PROGRAMS})

File src/config.h.cmake

 /* Define to 1 if you have the <libpng/png.h> header file. */
 #cmakedefine HAVE_LIBPNG_PNG_H
 
+/* Define to 1 if you have the <libimagequant.h> header file. */
+#cmakedefine HAVE_LIBIMAGEQUANT_H
+
 /* Define if you have the Xpm library. */
 #cmakedefine HAVE_LIBXPM
 

File src/gd_topal.c

 #include "gdhelpers.h"
 
 #ifdef HAVE_LIBIMAGEQUANT_H
-#include <libimagequant.h>
+#include <libimagequant.h> /* if this fails then set -DENABLE_LIQ=NO in cmake or make static libimagequant.a in libimagequant/ */
 #endif
 
 /* (Re)define some defines known by libjpeg */