Hi,

Carrying on in the list of open issues to look at for contributing to CMake, I've had a look at issue "15280 - FindZLIB module should find debug and release variants". I've made some changes to the FindZLIB module which should make it so that debug and release variants are found as separate libraries, if they're both found then they're provided in ZLIB_LIBRARIES and ZLIB::ZLIB's imported location properties. Attached is the patch for FindZLIB.cmake.

With this, I noticed that the Windows DLL's use different file names for the release and debug variants, but I couldn't tell if this is true on UNIX, it didn't seem to be the case. As the change to FinZLIB is based on the two variants having different names, I'm not sure these changes will have any effect on UNIX, is this expected or am I missing something/going about it the wrong way?

Cheers,
Michael
From 9d1aa288cc68008797cbf67d0fe86a8713b4ad29 Mon Sep 17 00:00:00 2001
From: Michael Scott <[email protected]>
Date: Sun, 23 Aug 2015 10:45:27 +0100
Subject: [PATCH] Find the debug and release variants as separate libraries,
 providing both in ZLIB_LIBRARIES and ZLIB::ZLIB's imported location
 properties, when both are found.

---
 Modules/FindZLIB.cmake | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/Modules/FindZLIB.cmake b/Modules/FindZLIB.cmake
index d4a27d5..b572b09 100644
--- a/Modules/FindZLIB.cmake
+++ b/Modules/FindZLIB.cmake
@@ -74,15 +74,17 @@ set(_ZLIB_SEARCH_NORMAL
   )
 list(APPEND _ZLIB_SEARCHES _ZLIB_SEARCH_NORMAL)
 
-set(ZLIB_NAMES z zlib zdll zlib1 zlibd zlibd1)
+set(ZLIB_NAMES z zlib zdll zlib1)
+set(ZLIB_NAMES_DEBUG zlibd zlibd1)
 
 # Try each search configuration.
 foreach(search ${_ZLIB_SEARCHES})
   find_path(ZLIB_INCLUDE_DIR NAMES zlib.h        ${${search}} PATH_SUFFIXES 
include)
   find_library(ZLIB_LIBRARY  NAMES ${ZLIB_NAMES} ${${search}} PATH_SUFFIXES 
lib)
+  find_library(ZLIB_LIBRARY_DEBUG  NAMES ${ZLIB_NAMES_DEBUG} ${${search}} 
PATH_SUFFIXES lib)
 endforeach()
 
-mark_as_advanced(ZLIB_LIBRARY ZLIB_INCLUDE_DIR)
+mark_as_advanced(ZLIB_LIBRARY ZLIB_LIBRARY_DEBUG ZLIB_INCLUDE_DIR)
 
 if(ZLIB_INCLUDE_DIR AND EXISTS "${ZLIB_INCLUDE_DIR}/zlib.h")
     file(STRINGS "${ZLIB_INCLUDE_DIR}/zlib.h" ZLIB_H REGEX "^#define 
ZLIB_VERSION \"[^\"]*\"$")
@@ -112,12 +114,25 @@ FIND_PACKAGE_HANDLE_STANDARD_ARGS(ZLIB REQUIRED_VARS 
ZLIB_LIBRARY ZLIB_INCLUDE_D
 
 if(ZLIB_FOUND)
     set(ZLIB_INCLUDE_DIRS ${ZLIB_INCLUDE_DIR})
-    set(ZLIB_LIBRARIES ${ZLIB_LIBRARY})
+
+    if(ZLIB_LIBRARY_DEBUG)
+        set(ZLIB_LIBRARIES optimized ${ZLIB_LIBRARY} debug 
${ZLIB_LIBRARY_DEBUG})
+    else()
+        set(ZLIB_LIBRARIES ${ZLIB_LIBRARY})
+    endif()
 
     if(NOT TARGET ZLIB::ZLIB)
       add_library(ZLIB::ZLIB UNKNOWN IMPORTED)
       set_target_properties(ZLIB::ZLIB PROPERTIES
-        IMPORTED_LOCATION "${ZLIB_LIBRARY}"
         INTERFACE_INCLUDE_DIRECTORIES "${ZLIB_INCLUDE_DIRS}")
+        
+      if(ZLIB_LIBRARY_DEBUG)
+        set_target_properties(ZLIB::ZLIB PROPERTIES
+          IMPORTED_LOCATION_RELEASE "${ZLIB_LIBRARY}"
+          IMPORTED_LOCATION_DEBUG "${ZLIB_LIBRARY_DEBUG}")
+      else()
+        set_target_properties(ZLIB::ZLIB PROPERTIES
+          IMPORTED_LOCATION "${ZLIB_LIBRARY}")
+      endif()
     endif()
 endif()
-- 
2.1.4

-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake-developers

Reply via email to