FindPNG.cmake 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. # - Find the native PNG includes and library
  2. #
  3. # This module searches libpng, the library for working with PNG images.
  4. #
  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.
  14. #
  15. # Since PNG depends on the ZLib compression library, none of the above will be
  16. # defined unless ZLib can be found.
  17. #=============================================================================
  18. # Copyright 2002-2009 Kitware, Inc.
  19. #
  20. # Distributed under the OSI-approved BSD License (the "License");
  21. # see accompanying file Copyright.txt for details.
  22. #
  23. # This software is distributed WITHOUT ANY WARRANTY; without even the
  24. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  25. # See the License for more information.
  26. #=============================================================================
  27. # (To distribute this file outside of CMake, substitute the full
  28. # License text for the above reference.)
  29. if(PNG_FIND_QUIETLY)
  30. set(_FIND_ZLIB_ARG QUIET)
  31. endif()
  32. find_package(ZLIB ${_FIND_ZLIB_ARG})
  33. if(ZLIB_FOUND)
  34. find_path(PNG_PNG_INCLUDE_DIR png.h
  35. /usr/local/include/libpng # OpenBSD
  36. )
  37. set(PNG_NAMES ${PNG_NAMES} png libpng png15 libpng15 png15d libpng15d png14 libpng14 png14d libpng14d png12 libpng12 png12d libpng12d)
  38. find_library(PNG_LIBRARY NAMES ${PNG_NAMES} )
  39. if (PNG_LIBRARY AND PNG_PNG_INCLUDE_DIR)
  40. # png.h includes zlib.h. Sigh.
  41. set(PNG_INCLUDE_DIRS ${PNG_PNG_INCLUDE_DIR} ${ZLIB_INCLUDE_DIR} )
  42. set(PNG_INCLUDE_DIR ${PNG_INCLUDE_DIRS} ) # for backward compatiblity
  43. set(PNG_LIBRARIES ${PNG_LIBRARY} ${ZLIB_LIBRARY})
  44. if (CYGWIN)
  45. if(BUILD_SHARED_LIBS)
  46. # No need to define PNG_USE_DLL here, because it's default for Cygwin.
  47. else()
  48. set (PNG_DEFINITIONS -DPNG_STATIC)
  49. endif()
  50. endif ()
  51. endif ()
  52. if (PNG_PNG_INCLUDE_DIR AND EXISTS "${PNG_PNG_INCLUDE_DIR}/png.h")
  53. file(STRINGS "${PNG_PNG_INCLUDE_DIR}/png.h" png_version_str REGEX "^#define[ \t]+PNG_LIBPNG_VER_STRING[ \t]+\".+\"")
  54. string(REGEX REPLACE "^#define[ \t]+PNG_LIBPNG_VER_STRING[ \t]+\"([^\"]+)\".*" "\\1" PNG_VERSION_STRING "${png_version_str}")
  55. unset(png_version_str)
  56. endif ()
  57. endif()
  58. # handle the QUIETLY and REQUIRED arguments and set PNG_FOUND to TRUE if
  59. # all listed variables are TRUE
  60. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  61. find_package_handle_standard_args(PNG
  62. REQUIRED_VARS PNG_LIBRARY PNG_PNG_INCLUDE_DIR
  63. VERSION_VAR PNG_VERSION_STRING)
  64. mark_as_advanced(PNG_PNG_INCLUDE_DIR PNG_LIBRARY )