1 # - Find the native PNG includes and library
3 # This module searches libpng, the library for working with PNG images.
5 # It defines the following variables
6 # PNG_INCLUDE_DIRS, where to find png.h, etc.
7 # PNG_LIBRARIES, the libraries to link against to use PNG.
8 # PNG_DEFINITIONS - You should add_definitons(${PNG_DEFINITIONS}) before compiling code that includes png library files.
9 # PNG_FOUND, If false, do not try to use PNG.
10 # PNG_VERSION_STRING - the version of the PNG library found (since CMake 2.8.8)
11 # Also defined, but not for general use are
12 # PNG_LIBRARY, where to find the PNG library.
13 # For backward compatiblity the variable PNG_INCLUDE_DIR is also set. It has the same value as PNG_INCLUDE_DIRS.
15 # Since PNG depends on the ZLib compression library, none of the above will be
16 # defined unless ZLib can be found.
18 #=============================================================================
19 # Copyright 2002-2009 Kitware, Inc.
21 # Distributed under the OSI-approved BSD License (the "License");
22 # see accompanying file Copyright.txt for details.
24 # This software is distributed WITHOUT ANY WARRANTY; without even the
25 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
26 # See the License for more information.
27 #=============================================================================
28 # (To distribute this file outside of CMake, substitute the full
29 # License text for the above reference.)
32 set(_FIND_ZLIB_ARG QUIET)
34 find_package(ZLIB ${_FIND_ZLIB_ARG})
37 find_path(PNG_PNG_INCLUDE_DIR png.h
38 /usr/local/include/libpng # OpenBSD
41 set(PNG_NAMES ${PNG_NAMES} png libpng png15 libpng15 png15d libpng15d png14 libpng14 png14d libpng14d png12 libpng12 png12d libpng12d)
42 find_library(PNG_LIBRARY NAMES ${PNG_NAMES} )
44 if (PNG_LIBRARY AND PNG_PNG_INCLUDE_DIR)
45 # png.h includes zlib.h. Sigh.
46 set(PNG_INCLUDE_DIRS ${PNG_PNG_INCLUDE_DIR} ${ZLIB_INCLUDE_DIR} )
47 set(PNG_INCLUDE_DIR ${PNG_INCLUDE_DIRS} ) # for backward compatiblity
48 set(PNG_LIBRARIES ${PNG_LIBRARY} ${ZLIB_LIBRARY})
52 # No need to define PNG_USE_DLL here, because it's default for Cygwin.
54 set (PNG_DEFINITIONS -DPNG_STATIC)
60 if (PNG_PNG_INCLUDE_DIR AND EXISTS "${PNG_PNG_INCLUDE_DIR}/png.h")
61 file(STRINGS "${PNG_PNG_INCLUDE_DIR}/png.h" png_version_str REGEX "^#define[ \t]+PNG_LIBPNG_VER_STRING[ \t]+\".+\"")
63 string(REGEX REPLACE "^#define[ \t]+PNG_LIBPNG_VER_STRING[ \t]+\"([^\"]+)\".*" "\\1" PNG_VERSION_STRING "${png_version_str}")
64 unset(png_version_str)
68 # handle the QUIETLY and REQUIRED arguments and set PNG_FOUND to TRUE if
69 # all listed variables are TRUE
70 include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
71 find_package_handle_standard_args(PNG
72 REQUIRED_VARS PNG_LIBRARY PNG_PNG_INCLUDE_DIR
73 VERSION_VAR PNG_VERSION_STRING)
75 mark_as_advanced(PNG_PNG_INCLUDE_DIR PNG_LIBRARY )