summaryrefslogtreecommitdiff
path: root/Modules/FindPNG.cmake
diff options
context:
space:
mode:
authorRolf Eike Beer <eike@sf-mail.de>2012-01-25 18:24:44 +0100
committerRolf Eike Beer <eike@sf-mail.de>2012-01-25 18:24:57 +0100
commit0051506aa4ea3e1fdbe5333b529a0a5af9476be5 (patch)
treef94b32e67bfa08289a7a21d062351e754e430c53 /Modules/FindPNG.cmake
parent731f996ce070bbba1b4913050497afa95436f2d2 (diff)
downloadcmake-0051506aa4ea3e1fdbe5333b529a0a5af9476be5.tar.gz
FindPNG: support version selection
Diffstat (limited to 'Modules/FindPNG.cmake')
-rw-r--r--Modules/FindPNG.cmake11
1 files changed, 10 insertions, 1 deletions
diff --git a/Modules/FindPNG.cmake b/Modules/FindPNG.cmake
index f616973098..a6c181cb15 100644
--- a/Modules/FindPNG.cmake
+++ b/Modules/FindPNG.cmake
@@ -7,6 +7,7 @@
# PNG_LIBRARIES, the libraries to link against to use PNG.
# PNG_DEFINITIONS - You should add_definitons(${PNG_DEFINITIONS}) before compiling code that includes png library files.
# PNG_FOUND, If false, do not try to use PNG.
+# PNG_VERSION_STRING - the version of the PNG library found (since CMake 2.8.8)
# Also defined, but not for general use are
# PNG_LIBRARY, where to find the PNG library.
# For backward compatiblity the variable PNG_INCLUDE_DIR is also set. It has the same value as PNG_INCLUDE_DIRS.
@@ -56,11 +57,19 @@ if(ZLIB_FOUND)
endif (PNG_LIBRARY AND PNG_PNG_INCLUDE_DIR)
+ if (PNG_PNG_INCLUDE_DIR AND EXISTS "${PNG_PNG_INCLUDE_DIR}/png.h")
+ file(STRINGS "${PNG_PNG_INCLUDE_DIR}/png.h" png_version_str REGEX "^#define[ \t]+PNG_LIBPNG_VER_STRING[ \t]+\".+\"")
+
+ string(REGEX REPLACE "^#define[ \t]+PNG_LIBPNG_VER_STRING[ \t]+\"([^\"]+)\".*" "\\1" PNG_VERSION_STRING "${png_version_str}")
+ unset(png_version_str)
+ endif (PNG_PNG_INCLUDE_DIR AND EXISTS "${PNG_PNG_INCLUDE_DIR}/png.h")
endif(ZLIB_FOUND)
# handle the QUIETLY and REQUIRED arguments and set PNG_FOUND to TRUE if
# all listed variables are TRUE
include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
-find_package_handle_standard_args(PNG DEFAULT_MSG PNG_LIBRARY PNG_PNG_INCLUDE_DIR)
+find_package_handle_standard_args(PNG
+ REQUIRED_VARS PNG_LIBRARY PNG_PNG_INCLUDE_DIR
+ VERSION_VAR PNG_VERSION_STRING)
mark_as_advanced(PNG_PNG_INCLUDE_DIR PNG_LIBRARY )