[PATCH] D70519: [CMake] use findzlib util to include zlib

Michael Holman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 20 17:02:24 PST 2019


Holman created this revision.
Holman added reviewers: rnk, labath.
Herald added subscribers: llvm-commits, mgorny.
Herald added a project: LLVM.

See PR19403:
https://bugs.llvm.org/show_bug.cgi?id=19403

This change makes it much easier to use zlib when it isn't on the system include path (e.g. on Windows).
Instead of modifying compiler and linker flags, the user just has to set the CMAKE variable ZLIB_ROOT or ZLIB_INCLUDE_DIRS/ZLIB_LIBRARIES.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D70519

Files:
  llvm/cmake/config-ix.cmake


Index: llvm/cmake/config-ix.cmake
===================================================================
--- llvm/cmake/config-ix.cmake
+++ llvm/cmake/config-ix.cmake
@@ -56,7 +56,6 @@
 check_include_file(termios.h HAVE_TERMIOS_H)
 check_include_file(unistd.h HAVE_UNISTD_H)
 check_include_file(valgrind/valgrind.h HAVE_VALGRIND_VALGRIND_H)
-check_include_file(zlib.h HAVE_ZLIB_H)
 check_include_file(fenv.h HAVE_FENV_H)
 check_symbol_exists(FE_ALL_EXCEPT "fenv.h" HAVE_DECL_FE_ALL_EXCEPT)
 check_symbol_exists(FE_INEXACT "fenv.h" HAVE_DECL_FE_INEXACT)
@@ -120,15 +119,18 @@
 if(NOT LLVM_USE_SANITIZER MATCHES "Memory.*")
   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})
+    # Check for ZLib.
+    include(FindZLib)
+
+    if (ZLIB_FOUND)
+      include_directories(${ZLIB_INCLUDE_DIRS})
+      set(HAVE_ZLIB_H 1)
+      string(TOUPPER ${ZLIB_LIBRARIES} library_suffix)
+      check_library_exists(${ZLIB_LIBRARIES} compress2 "" HAVE_LIBZ_${library_suffix})
       if(HAVE_LIBZ_${library_suffix})
         set(HAVE_LIBZ 1)
-        set(ZLIB_LIBRARIES "${library}")
-        break()
       endif()
-    endforeach()
+    endif()
   endif()
 
   # Don't look for these libraries on Windows.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D70519.230352.patch
Type: text/x-patch
Size: 1353 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191121/00064d05/attachment.bin>


More information about the llvm-commits mailing list