Advertisement
Guest User

Untitled

a guest
Dec 21st, 2014
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.40 KB | None | 0 0
  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. #=============================================================================
  19. # Copyright 2002-2009 Kitware, Inc.
  20. #
  21. # Distributed under the OSI-approved BSD License (the "License");
  22. # see accompanying file Copyright.txt for details.
  23. #
  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.)
  30.  
  31. if(PNG_FIND_QUIETLY)
  32. set(_FIND_ZLIB_ARG QUIET)
  33. endif()
  34. find_package(ZLIB ${_FIND_ZLIB_ARG})
  35.  
  36. if(ZLIB_FOUND)
  37. find_path(PNG_PNG_INCLUDE_DIR png.h
  38. /usr/local/include/libpng # OpenBSD
  39. )
  40.  
  41. list(APPEND PNG_NAMES png libpng)
  42. unset(PNG_NAMES_DEBUG)
  43. set(_PNG_VERSION_SUFFIXES 17 16 15 14 12)
  44. if (PNG_FIND_VERSION MATCHES "^[0-9]+\\.[0-9]+(\\..*)?$")
  45. string(REGEX REPLACE
  46. "^([0-9]+)\\.([0-9]+).*" "\\1\\2"
  47. _PNG_VERSION_SUFFIX_MIN "${PNG_FIND_VERSION}")
  48. if (PNG_FIND_VERSION_EXACT)
  49. set(_PNG_VERSION_SUFFIXES ${_PNG_VERSION_SUFFIX_MIN})
  50. else ()
  51. string(REGEX REPLACE
  52. "${_PNG_VERSION_SUFFIX_MIN}.*" "${_PNG_VERSION_SUFFIX_MIN}"
  53. _PNG_VERSION_SUFFIXES "${_PNG_VERSION_SUFFIXES}")
  54. endif ()
  55. unset(_PNG_VERSION_SUFFIX_MIN)
  56. endif ()
  57. foreach(v IN LISTS _PNG_VERSION_SUFFIXES)
  58. list(APPEND PNG_NAMES png${v} libpng${v})
  59. list(APPEND PNG_NAMES_DEBUG png${v}d libpng${v}d)
  60. endforeach()
  61. unset(_PNG_VERSION_SUFFIXES)
  62. # For compatiblity with versions prior to this multi-config search, honor
  63. # any PNG_LIBRARY that is already specified and skip the search.
  64. if(NOT PNG_LIBRARY)
  65. find_library(PNG_LIBRARY_RELEASE NAMES ${PNG_NAMES})
  66. find_library(PNG_LIBRARY_DEBUG NAMES ${PNG_NAMES_DEBUG})
  67. include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake)
  68. select_library_configurations(PNG)
  69. mark_as_advanced(PNG_LIBRARY_RELEASE PNG_LIBRARY_DEBUG)
  70. endif()
  71. unset(PNG_NAMES)
  72. unset(PNG_NAMES_DEBUG)
  73.  
  74. # Set by select_library_configurations(), but we want the one from
  75. # find_package_handle_standard_args() below.
  76. unset(PNG_FOUND)
  77.  
  78. if (PNG_LIBRARY AND PNG_PNG_INCLUDE_DIR)
  79. # png.h includes zlib.h. Sigh.
  80. set(PNG_INCLUDE_DIRS ${PNG_PNG_INCLUDE_DIR} ${ZLIB_INCLUDE_DIR} )
  81. set(PNG_INCLUDE_DIR ${PNG_INCLUDE_DIRS} ) # for backward compatiblity
  82. set(PNG_LIBRARIES ${PNG_LIBRARY} ${ZLIB_LIBRARY})
  83.  
  84. if (CYGWIN)
  85. if(BUILD_SHARED_LIBS)
  86. # No need to define PNG_USE_DLL here, because it's default for Cygwin.
  87. else()
  88. set (PNG_DEFINITIONS -DPNG_STATIC)
  89. endif()
  90. endif ()
  91.  
  92. endif ()
  93.  
  94. if (PNG_PNG_INCLUDE_DIR AND EXISTS "${PNG_PNG_INCLUDE_DIR}/png.h")
  95. file(STRINGS "${PNG_PNG_INCLUDE_DIR}/png.h" png_version_str REGEX "^#define[ \t]+PNG_LIBPNG_VER_STRING[ \t]+\".+\"")
  96.  
  97. string(REGEX REPLACE "^#define[ \t]+PNG_LIBPNG_VER_STRING[ \t]+\"([^\"]+)\".*" "\\1" PNG_VERSION_STRING "${png_version_str}")
  98. unset(png_version_str)
  99. endif ()
  100. endif()
  101.  
  102. # handle the QUIETLY and REQUIRED arguments and set PNG_FOUND to TRUE if
  103. # all listed variables are TRUE
  104. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  105. find_package_handle_standard_args(PNG
  106. REQUIRED_VARS PNG_LIBRARY PNG_PNG_INCLUDE_DIR
  107. VERSION_VAR PNG_VERSION_STRING)
  108.  
  109. mark_as_advanced(PNG_PNG_INCLUDE_DIR PNG_LIBRARY )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement