[cmake-developers] [PATCH] [Module] FindPNG: Add Env Hint via PNG_ROOT

Huebl, Axel a.huebl at hzdr.de
Fri Jun 27 11:04:01 EDT 2014


This patch provides users the optional hint via the environment
variable PNG_ROOT.
This comes very useful when libpng is not installed in a default
location and/or if several versions are installed in parallel.
---
 Modules/FindPNG.cmake | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/Modules/FindPNG.cmake b/Modules/FindPNG.cmake
index fa04bf0..b6d0473 100644
--- a/Modules/FindPNG.cmake
+++ b/Modules/FindPNG.cmake
@@ -8,6 +8,9 @@
 #
 # This module searches libpng, the library for working with PNG images.
 #
+# To provide the module with a hint about where to find your libpng
+# installation, you can set the environment variable PNG_ROOT.
+#
 # It defines the following variables
 #
 # ::
@@ -32,6 +35,7 @@

 #=============================================================================
 # Copyright 2002-2009 Kitware, Inc.
+# Copyright 2014      Axel Huebl https://github.com/ax3l
 #
 # Distributed under the OSI-approved BSD License (the "License");
 # see accompanying file Copyright.txt for details.
@@ -49,8 +53,10 @@ endif()
 find_package(ZLIB ${_FIND_ZLIB_ARG})

 if(ZLIB_FOUND)
-  find_path(PNG_PNG_INCLUDE_DIR png.h
-  /usr/local/include/libpng             # OpenBSD
+  find_path(PNG_PNG_INCLUDE_DIR
+      NAMES png.h
+      PATHS /usr/local/include/libpng             # OpenBSD
+      PATHS $ENV{PNG_ROOT}/include                # generic hint
   )

   list(APPEND PNG_NAMES png libpng)
@@ -75,8 +81,8 @@ if(ZLIB_FOUND)
   # For compatiblity with versions prior to this multi-config search, honor
   # any PNG_LIBRARY that is already specified and skip the search.
   if(NOT PNG_LIBRARY)
-    find_library(PNG_LIBRARY_RELEASE NAMES ${PNG_NAMES})
-    find_library(PNG_LIBRARY_DEBUG NAMES ${PNG_NAMES_DEBUG})
+    find_library(PNG_LIBRARY_RELEASE NAMES ${PNG_NAMES} HINTS
$ENV{PNG_ROOT}/lib)
+    find_library(PNG_LIBRARY_DEBUG NAMES ${PNG_NAMES_DEBUG} HINTS
$ENV{PNG_ROOT}/lib)
     include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake)
     select_library_configurations(PNG)
     mark_as_advanced(PNG_LIBRARY_RELEASE PNG_LIBRARY_DEBUG)
-- 
2.0.0

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4921 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://public.kitware.com/pipermail/cmake-developers/attachments/20140627/4dfe2678/attachment.bin>


More information about the cmake-developers mailing list