Blame cmake/modules/FindPNG.cmake

Packit ed3af9
# - Find the native PNG includes and library
Packit ed3af9
#
Packit ed3af9
# This module searches libpng, the library for working with PNG images.
Packit ed3af9
#
Packit ed3af9
# It defines the following variables
Packit ed3af9
#  PNG_INCLUDE_DIRS, where to find png.h, etc.
Packit ed3af9
#  PNG_LIBRARIES, the libraries to link against to use PNG.
Packit ed3af9
#  PNG_DEFINITIONS - You should add_definitons(${PNG_DEFINITIONS}) before compiling code that includes png library files.
Packit ed3af9
#  PNG_FOUND, If false, do not try to use PNG.
Packit ed3af9
#  PNG_VERSION_STRING - the version of the PNG library found (since CMake 2.8.8)
Packit ed3af9
# Also defined, but not for general use are
Packit ed3af9
#  PNG_LIBRARY, where to find the PNG library.
Packit ed3af9
# For backward compatiblity the variable PNG_INCLUDE_DIR is also set. It has the same value as PNG_INCLUDE_DIRS.
Packit ed3af9
#
Packit ed3af9
# Since PNG depends on the ZLib compression library, none of the above will be
Packit ed3af9
# defined unless ZLib can be found.
Packit ed3af9
Packit ed3af9
#=============================================================================
Packit ed3af9
# Copyright 2002-2009 Kitware, Inc.
Packit ed3af9
#
Packit ed3af9
#
Packit ed3af9
# Redistribution and use in source and binary forms, with or without
Packit ed3af9
# modification, are permitted provided that the following conditions are
Packit ed3af9
# met:
Packit ed3af9
#
Packit ed3af9
#  * Redistributions of source code must retain the above copyright notice,
Packit ed3af9
#    this list of conditions and the following disclaimer.
Packit ed3af9
# 
Packit ed3af9
#  * Redistributions in binary form must reproduce the above copyright notice,
Packit ed3af9
#    this list of conditions and the following disclaimer in the documentation
Packit ed3af9
#    and/or other materials provided with the distribution.
Packit ed3af9
# 
Packit ed3af9
#  * The names of Kitware, Inc., the Insight Consortium, or the names of
Packit ed3af9
#    any consortium members, or of any contributors, may not be used to
Packit ed3af9
#    endorse or promote products derived from this software without
Packit ed3af9
#    specific prior written permission.
Packit ed3af9
# 
Packit ed3af9
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS ``AS IS''
Packit ed3af9
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Packit ed3af9
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
Packit ed3af9
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
Packit ed3af9
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Packit ed3af9
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
Packit ed3af9
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
Packit ed3af9
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
Packit ed3af9
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Packit ed3af9
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Packit ed3af9
Packit ed3af9
if(PNG_FIND_QUIETLY)
Packit ed3af9
  set(_FIND_ZLIB_ARG QUIET)
Packit ed3af9
endif()
Packit ed3af9
find_package(ZLIB ${_FIND_ZLIB_ARG})
Packit ed3af9
Packit ed3af9
if(ZLIB_FOUND)
Packit ed3af9
  find_path(PNG_PNG_INCLUDE_DIR png.h
Packit ed3af9
  /usr/local/include/libpng             # OpenBSD
Packit ed3af9
  )
Packit ed3af9
Packit ed3af9
  set(PNG_NAMES ${PNG_NAMES} png libpng png15 libpng15 png15d libpng15d png14 libpng14 png14d libpng14d png12 libpng12 png12d libpng12d libpng_a)
Packit ed3af9
  find_library(PNG_LIBRARY NAMES ${PNG_NAMES} )
Packit ed3af9
Packit ed3af9
  if (PNG_LIBRARY AND PNG_PNG_INCLUDE_DIR)
Packit ed3af9
      # png.h includes zlib.h. Sigh.
Packit ed3af9
      set(PNG_INCLUDE_DIRS ${PNG_PNG_INCLUDE_DIR} ${ZLIB_INCLUDE_DIR} )
Packit ed3af9
      set(PNG_INCLUDE_DIR ${PNG_INCLUDE_DIRS} ) # for backward compatiblity
Packit ed3af9
      set(PNG_LIBRARIES ${PNG_LIBRARY} ${ZLIB_LIBRARY})
Packit ed3af9
Packit ed3af9
      if (CYGWIN)
Packit ed3af9
        if(BUILD_SHARED_LIBS)
Packit ed3af9
           # No need to define PNG_USE_DLL here, because it's default for Cygwin.
Packit ed3af9
        else()
Packit ed3af9
          set (PNG_DEFINITIONS -DPNG_STATIC)
Packit ed3af9
        endif()
Packit ed3af9
      endif ()
Packit ed3af9
Packit ed3af9
  endif ()
Packit ed3af9
Packit ed3af9
  if (PNG_PNG_INCLUDE_DIR AND EXISTS "${PNG_PNG_INCLUDE_DIR}/png.h")
Packit ed3af9
      file(STRINGS "${PNG_PNG_INCLUDE_DIR}/png.h" png_version_str REGEX "^#define[ \t]+PNG_LIBPNG_VER_STRING[ \t]+\".+\"")
Packit ed3af9
Packit ed3af9
      string(REGEX REPLACE "^#define[ \t]+PNG_LIBPNG_VER_STRING[ \t]+\"([^\"]+)\".*" "\\1" PNG_VERSION_STRING "${png_version_str}")
Packit ed3af9
      unset(png_version_str)
Packit ed3af9
  endif ()
Packit ed3af9
endif()
Packit ed3af9
Packit ed3af9
# handle the QUIETLY and REQUIRED arguments and set PNG_FOUND to TRUE if
Packit ed3af9
# all listed variables are TRUE
Packit ed3af9
include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
Packit ed3af9
find_package_handle_standard_args(PNG
Packit ed3af9
                                  REQUIRED_VARS PNG_LIBRARY PNG_PNG_INCLUDE_DIR
Packit ed3af9
                                  VERSION_VAR PNG_VERSION_STRING)
Packit ed3af9
Packit ed3af9
mark_as_advanced(PNG_PNG_INCLUDE_DIR PNG_LIBRARY )