From: Saleem Abdulrasool Date: Wed, 1 Jan 2020 23:01:04 +0000 (-0800) Subject: build: reduce CMake handling for zlib X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=abb00753069554c538f3d850897373d093389945;p=platform%2Fupstream%2Fllvm.git build: reduce CMake handling for zlib Rather than handling zlib handling manually, use `find_package` from CMake to find zlib properly. Use this to normalize the `LLVM_ENABLE_ZLIB`, `HAVE_ZLIB`, `HAVE_ZLIB_H`. Furthermore, require zlib if `LLVM_ENABLE_ZLIB` is set to `YES`, which requires the distributor to explicitly select whether zlib is enabled or not. This simplifies the CMake handling and usage in the rest of the tooling. This restores 68a235d07f9e7049c7eb0c8091f37e385327ac28, e6c7ed6d2164a0659fd9f6ee44f1375d301e3cad. The problem with the windows bot is a need for clearing the cache. --- diff --git a/clang/test/CMakeLists.txt b/clang/test/CMakeLists.txt index 16e487f..6f6121f 100644 --- a/clang/test/CMakeLists.txt +++ b/clang/test/CMakeLists.txt @@ -9,22 +9,13 @@ endif () string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} CLANG_TOOLS_DIR ${LLVM_RUNTIME_OUTPUT_INTDIR}) -if(CLANG_BUILT_STANDALONE) - # Set HAVE_LIBZ according to recorded LLVM_ENABLE_ZLIB value. This - # value is forced to 0 if zlib was not found, so it is fine to use it - # instead of HAVE_LIBZ (not recorded). - if(LLVM_ENABLE_ZLIB) - set(HAVE_LIBZ 1) - endif() -endif() - llvm_canonicalize_cmake_booleans( CLANG_BUILD_EXAMPLES CLANG_ENABLE_ARCMT CLANG_ENABLE_STATIC_ANALYZER ENABLE_BACKTRACES ENABLE_EXPERIMENTAL_NEW_PASS_MANAGER - HAVE_LIBZ + LLVM_ENABLE_ZLIB LLVM_ENABLE_PER_TARGET_RUNTIME_DIR LLVM_ENABLE_PLUGINS LLVM_ENABLE_THREADS) diff --git a/clang/test/lit.site.cfg.py.in b/clang/test/lit.site.cfg.py.in index 520afab..e9b35ac 100644 --- a/clang/test/lit.site.cfg.py.in +++ b/clang/test/lit.site.cfg.py.in @@ -16,7 +16,7 @@ config.host_triple = "@LLVM_HOST_TRIPLE@" config.target_triple = "@TARGET_TRIPLE@" config.host_cxx = "@CMAKE_CXX_COMPILER@" config.llvm_use_sanitizer = "@LLVM_USE_SANITIZER@" -config.have_zlib = @HAVE_LIBZ@ +config.have_zlib = @LLVM_ENABLE_ZLIB@ config.clang_arcmt = @CLANG_ENABLE_ARCMT@ config.clang_default_cxx_stdlib = "@CLANG_DEFAULT_CXX_STDLIB@" config.clang_staticanalyzer = @CLANG_ENABLE_STATIC_ANALYZER@ diff --git a/compiler-rt/test/lit.common.configured.in b/compiler-rt/test/lit.common.configured.in index b4862f7..0fb5174 100644 --- a/compiler-rt/test/lit.common.configured.in +++ b/compiler-rt/test/lit.common.configured.in @@ -50,7 +50,7 @@ if config.enable_per_target_runtime_dir: else: set_default("target_suffix", "-%s" % config.target_arch) -set_default("have_zlib", "@HAVE_LIBZ@") +set_default("have_zlib", "@LLVM_ENABLE_ZLIB@") set_default("libcxx_used", "@LLVM_LIBCXX_USED@") # LLVM tools dir can be passed in lit parameters, so try to diff --git a/lld/test/CMakeLists.txt b/lld/test/CMakeLists.txt index 8be42c4..dc8cedf 100644 --- a/lld/test/CMakeLists.txt +++ b/lld/test/CMakeLists.txt @@ -4,17 +4,8 @@ set(LLVM_BUILD_MODE "%(build_mode)s") set(LLVM_TOOLS_DIR "${LLVM_TOOLS_BINARY_DIR}/%(build_config)s") set(LLVM_LIBS_DIR "${LLVM_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}/%(build_config)s") -if(LLD_BUILT_STANDALONE) - # Set HAVE_LIBZ according to recorded LLVM_ENABLE_ZLIB value. This - # value is forced to 0 if zlib was not found, so it is fine to use it - # instead of HAVE_LIBZ (not recorded). - if(LLVM_ENABLE_ZLIB) - set(HAVE_LIBZ 1) - endif() -endif() - llvm_canonicalize_cmake_booleans( - HAVE_LIBZ + LLVM_ENABLE_ZLIB LLVM_LIBXML2_ENABLED ) diff --git a/lld/test/lit.site.cfg.py.in b/lld/test/lit.site.cfg.py.in index 02840f8..531fce1 100644 --- a/lld/test/lit.site.cfg.py.in +++ b/lld/test/lit.site.cfg.py.in @@ -14,7 +14,7 @@ config.lld_libs_dir = "@LLVM_LIBRARY_OUTPUT_INTDIR@" config.lld_tools_dir = "@LLVM_RUNTIME_OUTPUT_INTDIR@" config.target_triple = "@TARGET_TRIPLE@" config.python_executable = "@PYTHON_EXECUTABLE@" -config.have_zlib = @HAVE_LIBZ@ +config.have_zlib = @LLVM_ENABLE_ZLIB@ config.sizeof_void_p = @CMAKE_SIZEOF_VOID_P@ # Support substitution of the tools and libs dirs with user parameters. This is diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp index 0a98f6a..7cea013 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp @@ -50,7 +50,7 @@ #include #endif -#if defined(HAVE_LIBZ) +#if LLVM_ENABLE_ZLIB #include #endif @@ -582,7 +582,7 @@ bool GDBRemoteCommunication::DecompressPacket() { } #endif -#if defined(HAVE_LIBZ) +#if LLVM_ENABLE_ZLIB if (decompressed_bytes == 0 && decompressed_bufsize != ULONG_MAX && decompressed_buffer != nullptr && m_compression_type == CompressionType::ZlibDeflate) { diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp index 905ebe2..19c3a5b 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp @@ -1045,7 +1045,7 @@ void GDBRemoteCommunicationClient::MaybeEnableCompression( } #endif -#if defined(HAVE_LIBZ) +#if LLVM_ENABLE_ZLIB if (avail_type == CompressionType::None) { for (auto compression : supported_compressions) { if (compression == "zlib-deflate") { diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt index 3505723..25f60da 100644 --- a/llvm/CMakeLists.txt +++ b/llvm/CMakeLists.txt @@ -347,7 +347,7 @@ option(LLVM_ENABLE_LIBPFM "Use libpfm for performance counters if available." ON option(LLVM_ENABLE_THREADS "Use threads if available." ON) -option(LLVM_ENABLE_ZLIB "Use zlib for compression/decompression if available." ON) +set(LLVM_ENABLE_ZLIB "ON" CACHE STRING "Use zlib for compression/decompression if available. Can be ON, OFF, or FORCE_ON") set(LLVM_Z3_INSTALL_DIR "" CACHE STRING "Install directory of the Z3 solver.") diff --git a/llvm/cmake/config-ix.cmake b/llvm/cmake/config-ix.cmake index e7e5e5d..a16038f 100644 --- a/llvm/cmake/config-ix.cmake +++ b/llvm/cmake/config-ix.cmake @@ -56,7 +56,6 @@ check_include_file(sys/types.h HAVE_SYS_TYPES_H) 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) @@ -118,19 +117,6 @@ endif() # 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.*") - 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. if (NOT PURE_WINDOWS) # Skip libedit if using ASan as it contains memory leaks. @@ -515,10 +501,21 @@ else( LLVM_ENABLE_THREADS ) message(STATUS "Threads disabled.") endif() -if (LLVM_ENABLE_ZLIB ) - # Check if zlib is available in the system. - if ( NOT HAVE_ZLIB_H OR NOT HAVE_LIBZ ) - set(LLVM_ENABLE_ZLIB 0) +if(LLVM_ENABLE_ZLIB) + if(LLVM_ENABLE_ZLIB STREQUAL FORCE_ON) + find_package(ZLIB REQUIRED) + else() + find_package(ZLIB) + endif() + + if(ZLIB_FOUND) + set(LLVM_ENABLE_ZLIB "YES" CACHE STRING + "Use zlib for compression/decompression if available. Can be ON, OFF, or FORCE_ON" + FORCE) + else() + set(LLVM_ENABLE_ZLIB "NO" CACHE STRING + "Use zlib for compression/decompression if available. Can be ON, OFF, or FORCE_ON" + FORCE) endif() endif() diff --git a/llvm/include/llvm/Config/config.h.cmake b/llvm/include/llvm/Config/config.h.cmake index 1a38bc1..db170ae 100644 --- a/llvm/include/llvm/Config/config.h.cmake +++ b/llvm/include/llvm/Config/config.h.cmake @@ -109,9 +109,6 @@ /* Define to 1 if you have the `pthread_setname_np' function. */ #cmakedefine HAVE_PTHREAD_SETNAME_NP ${HAVE_PTHREAD_SETNAME_NP} -/* Define to 1 if you have the `z' library (-lz). */ -#cmakedefine HAVE_LIBZ ${HAVE_LIBZ} - /* Define to 1 if you have the header file. */ #cmakedefine HAVE_LINK_H ${HAVE_LINK_H} @@ -226,9 +223,6 @@ /* Define to 1 if you have the header file. */ #cmakedefine HAVE_VALGRIND_VALGRIND_H ${HAVE_VALGRIND_VALGRIND_H} -/* Define to 1 if you have the header file. */ -#cmakedefine HAVE_ZLIB_H ${HAVE_ZLIB_H} - /* Have host's _alloca */ #cmakedefine HAVE__ALLOCA ${HAVE__ALLOCA} diff --git a/llvm/lib/Support/CMakeLists.txt b/llvm/lib/Support/CMakeLists.txt index ddc4d23..26332d4 100644 --- a/llvm/lib/Support/CMakeLists.txt +++ b/llvm/lib/Support/CMakeLists.txt @@ -1,7 +1,7 @@ -set(system_libs) -if ( LLVM_ENABLE_ZLIB AND HAVE_LIBZ ) - set(system_libs ${system_libs} ${ZLIB_LIBRARIES}) +if(LLVM_ENABLE_ZLIB) + set(system_libs ${ZLIB_LIBRARY}) endif() + if( MSVC OR MINGW ) # libuuid required for FOLDERID_Profile usage in lib/Support/Windows/Path.inc. # advapi32 required for CryptAcquireContextW in lib/Support/Windows/Path.inc. diff --git a/llvm/lib/Support/CRC.cpp b/llvm/lib/Support/CRC.cpp index 7c008d3..a3dba1a 100644 --- a/llvm/lib/Support/CRC.cpp +++ b/llvm/lib/Support/CRC.cpp @@ -25,7 +25,7 @@ using namespace llvm; -#if LLVM_ENABLE_ZLIB == 0 || !HAVE_ZLIB_H +#if !LLVM_ENABLE_ZLIB static const uint32_t CRCTable[256] = { 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, diff --git a/llvm/lib/Support/Compression.cpp b/llvm/lib/Support/Compression.cpp index 97d5ffa..4165a27 100644 --- a/llvm/lib/Support/Compression.cpp +++ b/llvm/lib/Support/Compression.cpp @@ -17,13 +17,13 @@ #include "llvm/Support/Compiler.h" #include "llvm/Support/Error.h" #include "llvm/Support/ErrorHandling.h" -#if LLVM_ENABLE_ZLIB == 1 && HAVE_ZLIB_H +#if LLVM_ENABLE_ZLIB #include #endif using namespace llvm; -#if LLVM_ENABLE_ZLIB == 1 && HAVE_LIBZ +#if LLVM_ENABLE_ZLIB static Error createError(StringRef Err) { return make_error(Err, inconvertibleErrorCode()); } diff --git a/llvm/test/CMakeLists.txt b/llvm/test/CMakeLists.txt index 6a11dcb..be5abe2 100644 --- a/llvm/test/CMakeLists.txt +++ b/llvm/test/CMakeLists.txt @@ -1,12 +1,12 @@ llvm_canonicalize_cmake_booleans( BUILD_SHARED_LIBS HAVE_LIBXAR - HAVE_LIBZ HAVE_OCAMLOPT HAVE_OCAML_OUNIT LLVM_ENABLE_DIA_SDK LLVM_ENABLE_FFI LLVM_ENABLE_THREADS + LLVM_ENABLE_ZLIB LLVM_INCLUDE_GO_TESTS LLVM_LIBXML2_ENABLED LLVM_LINK_LLVM_DYLIB diff --git a/llvm/test/lit.site.cfg.py.in b/llvm/test/lit.site.cfg.py.in index e313b0d..0f5e09b 100644 --- a/llvm/test/lit.site.cfg.py.in +++ b/llvm/test/lit.site.cfg.py.in @@ -36,7 +36,7 @@ config.host_cxx = "@HOST_CXX@" config.host_ldflags = '@HOST_LDFLAGS@' config.llvm_use_intel_jitevents = @LLVM_USE_INTEL_JITEVENTS@ config.llvm_use_sanitizer = "@LLVM_USE_SANITIZER@" -config.have_zlib = @HAVE_LIBZ@ +config.have_zlib = @LLVM_ENABLE_ZLIB@ config.have_libxar = @HAVE_LIBXAR@ config.have_dia_sdk = @LLVM_ENABLE_DIA_SDK@ config.enable_ffi = @LLVM_ENABLE_FFI@ diff --git a/llvm/unittests/Support/CompressionTest.cpp b/llvm/unittests/Support/CompressionTest.cpp index cc7be43..5172389 100644 --- a/llvm/unittests/Support/CompressionTest.cpp +++ b/llvm/unittests/Support/CompressionTest.cpp @@ -21,7 +21,7 @@ using namespace llvm; namespace { -#if LLVM_ENABLE_ZLIB == 1 && HAVE_LIBZ +#if LLVM_ENABLE_ZLIB void TestZlibCompression(StringRef Input, int Level) { SmallString<32> Compressed;