[PATCH] D40779: [cmake] Fix zlib library detection

Pavel Labath via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 4 03:33:09 PST 2017


labath created this revision.
Herald added a subscriber: mgorny.

A couple of people were broken by the previous zlib patch. It turned out
this was because I used find_libraries for searching for the z library.
This returns absolute paths, and when these paths made it into
llvm-config, it made it produce nonsensical flags for the --system-libs
output. To fix this, I hand-roll a search for the library in the same
way that we search for the terminfo library a couple of lines below.

This is a bit less flexible than the find_library option, as it does not
allow the user to specify the path to the library at configure time
(which is important on windows, as zlib is unlikely to be found in any
of the standard places cmake searches), but I was able to guide the
build to find it with appropriate values of LIB and INCLUDE environment
variables.


https://reviews.llvm.org/D40779

Files:
  cmake/config-ix.cmake
  lib/Support/CMakeLists.txt


Index: lib/Support/CMakeLists.txt
===================================================================
--- lib/Support/CMakeLists.txt
+++ lib/Support/CMakeLists.txt
@@ -1,6 +1,6 @@
 set(system_libs)
 if ( LLVM_ENABLE_ZLIB AND HAVE_LIBZ )
-  set(system_libs ${system_libs} ${ZLIB_LIBRARY_PATH})
+  set(system_libs ${system_libs} ${ZLIB_LIBRARIES})
 endif()
 if( MSVC OR MINGW )
   # libuuid required for FOLDERID_Profile usage in lib/Support/Windows/Path.inc.
Index: cmake/config-ix.cmake
===================================================================
--- cmake/config-ix.cmake
+++ cmake/config-ix.cmake
@@ -130,11 +130,17 @@
 # Don't look for these libraries if we're using MSan, since uninstrumented third
 # party code may call MSan interceptors like strlen, leading to false positives.
 if(NOT LLVM_USE_SANITIZER MATCHES "Memory.*")
-  find_library(ZLIB_LIBRARY_PATH NAMES z zlib)
-  if (LLVM_ENABLE_ZLIB AND ZLIB_LIBRARY_PATH)
-    check_library_exists(${ZLIB_LIBRARY_PATH} compress2 "" HAVE_LIBZ)
-  else()
-    set(HAVE_LIBZ 0)
+  set(HAVE_LIBZ 0)
+  if(LLVM_ENABLE_ZLIB)
+    foreach(library z zlib_static zlib)
+      string(TOUPPER ${library} library_suffix)
+      check_library_exists(${library} compress2 "" HAVE_LIBZ_${library_suffix})
+      if(HAVE_LIBZ_${library_suffix})
+        set(HAVE_LIBZ 1)
+        set(ZLIB_LIBRARIES "${library}")
+        break()
+      endif()
+    endforeach()
   endif()
 
   # Don't look for these libraries on Windows.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D40779.125307.patch
Type: text/x-patch
Size: 1471 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171204/0b5f89ac/attachment.bin>


More information about the llvm-commits mailing list