Skip to content

Commit 5f9211b

Browse files
committed
Revert abb0075 "build: reduce CMake handling for zlib" (PR44780)
and follow-ups: a2ca1c2 "build: disable zlib by default on Windows" 2181bf4 "[CMake] Link against ZLIB::ZLIB" 1079c68 "Attempt to fix ZLIB CMake logic on Windows" This changed the output of llvm-config --system-libs, and more importantly it broke stand-alone builds. Instead of piling on more fix attempts, let's revert this to reduce the risk of more breakages. (cherry picked from commit 916be8f)
1 parent 001c8aa commit 5f9211b

File tree

16 files changed

+62
-62
lines changed

16 files changed

+62
-62
lines changed

clang/test/CMakeLists.txt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,23 @@ endif ()
99

1010
string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} CLANG_TOOLS_DIR ${LLVM_RUNTIME_OUTPUT_INTDIR})
1111

12+
if(CLANG_BUILT_STANDALONE)
13+
# Set HAVE_LIBZ according to recorded LLVM_ENABLE_ZLIB value. This
14+
# value is forced to 0 if zlib was not found, so it is fine to use it
15+
# instead of HAVE_LIBZ (not recorded).
16+
if(LLVM_ENABLE_ZLIB)
17+
set(HAVE_LIBZ 1)
18+
endif()
19+
endif()
20+
1221
llvm_canonicalize_cmake_booleans(
1322
CLANG_BUILD_EXAMPLES
1423
CLANG_ENABLE_ARCMT
1524
CLANG_ENABLE_STATIC_ANALYZER
1625
CLANG_SPAWN_CC1
1726
ENABLE_BACKTRACES
1827
ENABLE_EXPERIMENTAL_NEW_PASS_MANAGER
19-
LLVM_ENABLE_ZLIB
28+
HAVE_LIBZ
2029
LLVM_ENABLE_PER_TARGET_RUNTIME_DIR
2130
LLVM_ENABLE_PLUGINS
2231
LLVM_ENABLE_THREADS)

clang/test/lit.site.cfg.py.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ config.host_triple = "@LLVM_HOST_TRIPLE@"
1616
config.target_triple = "@TARGET_TRIPLE@"
1717
config.host_cxx = "@CMAKE_CXX_COMPILER@"
1818
config.llvm_use_sanitizer = "@LLVM_USE_SANITIZER@"
19-
config.have_zlib = @LLVM_ENABLE_ZLIB@
19+
config.have_zlib = @HAVE_LIBZ@
2020
config.clang_arcmt = @CLANG_ENABLE_ARCMT@
2121
config.clang_default_cxx_stdlib = "@CLANG_DEFAULT_CXX_STDLIB@"
2222
config.clang_staticanalyzer = @CLANG_ENABLE_STATIC_ANALYZER@

compiler-rt/test/lit.common.configured.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ if config.enable_per_target_runtime_dir:
5050
else:
5151
set_default("target_suffix", "-%s" % config.target_arch)
5252

53-
set_default("have_zlib", "@LLVM_ENABLE_ZLIB@")
53+
set_default("have_zlib", "@HAVE_LIBZ@")
5454
set_default("libcxx_used", "@LLVM_LIBCXX_USED@")
5555

5656
# LLVM tools dir can be passed in lit parameters, so try to

lld/test/CMakeLists.txt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,17 @@ set(LLVM_BUILD_MODE "%(build_mode)s")
44
set(LLVM_TOOLS_DIR "${LLVM_TOOLS_BINARY_DIR}/%(build_config)s")
55
set(LLVM_LIBS_DIR "${LLVM_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}/%(build_config)s")
66

7+
if(LLD_BUILT_STANDALONE)
8+
# Set HAVE_LIBZ according to recorded LLVM_ENABLE_ZLIB value. This
9+
# value is forced to 0 if zlib was not found, so it is fine to use it
10+
# instead of HAVE_LIBZ (not recorded).
11+
if(LLVM_ENABLE_ZLIB)
12+
set(HAVE_LIBZ 1)
13+
endif()
14+
endif()
15+
716
llvm_canonicalize_cmake_booleans(
8-
LLVM_ENABLE_ZLIB
17+
HAVE_LIBZ
918
LLVM_LIBXML2_ENABLED
1019
)
1120

lld/test/lit.site.cfg.py.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ config.lld_libs_dir = "@LLVM_LIBRARY_OUTPUT_INTDIR@"
1414
config.lld_tools_dir = "@LLVM_RUNTIME_OUTPUT_INTDIR@"
1515
config.target_triple = "@TARGET_TRIPLE@"
1616
config.python_executable = "@PYTHON_EXECUTABLE@"
17-
config.have_zlib = @LLVM_ENABLE_ZLIB@
17+
config.have_zlib = @HAVE_LIBZ@
1818
config.sizeof_void_p = @CMAKE_SIZEOF_VOID_P@
1919

2020
# Support substitution of the tools and libs dirs with user parameters. This is

lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
#include <compression.h>
5151
#endif
5252

53-
#if LLVM_ENABLE_ZLIB
53+
#if defined(HAVE_LIBZ)
5454
#include <zlib.h>
5555
#endif
5656

@@ -582,7 +582,7 @@ bool GDBRemoteCommunication::DecompressPacket() {
582582
}
583583
#endif
584584

585-
#if LLVM_ENABLE_ZLIB
585+
#if defined(HAVE_LIBZ)
586586
if (decompressed_bytes == 0 && decompressed_bufsize != ULONG_MAX &&
587587
decompressed_buffer != nullptr &&
588588
m_compression_type == CompressionType::ZlibDeflate) {

lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1045,7 +1045,7 @@ void GDBRemoteCommunicationClient::MaybeEnableCompression(
10451045
}
10461046
#endif
10471047

1048-
#if LLVM_ENABLE_ZLIB
1048+
#if defined(HAVE_LIBZ)
10491049
if (avail_type == CompressionType::None) {
10501050
for (auto compression : supported_compressions) {
10511051
if (compression == "zlib-deflate") {

llvm/CMakeLists.txt

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -347,13 +347,7 @@ option(LLVM_ENABLE_LIBPFM "Use libpfm for performance counters if available." ON
347347

348348
option(LLVM_ENABLE_THREADS "Use threads if available." ON)
349349

350-
if(CMAKE_SYSTEM_NAME STREQUAL Windows)
351-
set(zlib_DEFAULT "OFF")
352-
else()
353-
set(zlib_DEFAULT "ON")
354-
endif()
355-
356-
set(LLVM_ENABLE_ZLIB "${zlib_DEFAULT}" CACHE STRING "Use zlib for compression/decompression if available. Can be ON, OFF, or FORCE_ON")
350+
option(LLVM_ENABLE_ZLIB "Use zlib for compression/decompression if available." ON)
357351

358352
set(LLVM_Z3_INSTALL_DIR "" CACHE STRING "Install directory of the Z3 solver.")
359353

llvm/cmake/config-ix.cmake

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ check_include_file(sys/types.h HAVE_SYS_TYPES_H)
5656
check_include_file(termios.h HAVE_TERMIOS_H)
5757
check_include_file(unistd.h HAVE_UNISTD_H)
5858
check_include_file(valgrind/valgrind.h HAVE_VALGRIND_VALGRIND_H)
59+
check_include_file(zlib.h HAVE_ZLIB_H)
5960
check_include_file(fenv.h HAVE_FENV_H)
6061
check_symbol_exists(FE_ALL_EXCEPT "fenv.h" HAVE_DECL_FE_ALL_EXCEPT)
6162
check_symbol_exists(FE_INEXACT "fenv.h" HAVE_DECL_FE_INEXACT)
@@ -117,6 +118,19 @@ endif()
117118
# Don't look for these libraries if we're using MSan, since uninstrumented third
118119
# party code may call MSan interceptors like strlen, leading to false positives.
119120
if(NOT LLVM_USE_SANITIZER MATCHES "Memory.*")
121+
set(HAVE_LIBZ 0)
122+
if(LLVM_ENABLE_ZLIB)
123+
foreach(library z zlib_static zlib)
124+
string(TOUPPER ${library} library_suffix)
125+
check_library_exists(${library} compress2 "" HAVE_LIBZ_${library_suffix})
126+
if(HAVE_LIBZ_${library_suffix})
127+
set(HAVE_LIBZ 1)
128+
set(ZLIB_LIBRARIES "${library}")
129+
break()
130+
endif()
131+
endforeach()
132+
endif()
133+
120134
# Don't look for these libraries on Windows.
121135
if (NOT PURE_WINDOWS)
122136
# Skip libedit if using ASan as it contains memory leaks.
@@ -501,21 +515,10 @@ else( LLVM_ENABLE_THREADS )
501515
message(STATUS "Threads disabled.")
502516
endif()
503517

504-
if(LLVM_ENABLE_ZLIB)
505-
if(LLVM_ENABLE_ZLIB STREQUAL FORCE_ON)
506-
find_package(ZLIB REQUIRED)
507-
else()
508-
find_package(ZLIB)
509-
endif()
510-
511-
if(ZLIB_FOUND)
512-
set(LLVM_ENABLE_ZLIB "YES" CACHE STRING
513-
"Use zlib for compression/decompression if available. Can be ON, OFF, or FORCE_ON"
514-
FORCE)
515-
else()
516-
set(LLVM_ENABLE_ZLIB "NO" CACHE STRING
517-
"Use zlib for compression/decompression if available. Can be ON, OFF, or FORCE_ON"
518-
FORCE)
518+
if (LLVM_ENABLE_ZLIB )
519+
# Check if zlib is available in the system.
520+
if ( NOT HAVE_ZLIB_H OR NOT HAVE_LIBZ )
521+
set(LLVM_ENABLE_ZLIB 0)
519522
endif()
520523
endif()
521524

llvm/include/llvm/Config/config.h.cmake

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@
109109
/* Define to 1 if you have the `pthread_setname_np' function. */
110110
#cmakedefine HAVE_PTHREAD_SETNAME_NP ${HAVE_PTHREAD_SETNAME_NP}
111111

112+
/* Define to 1 if you have the `z' library (-lz). */
113+
#cmakedefine HAVE_LIBZ ${HAVE_LIBZ}
114+
112115
/* Define to 1 if you have the <link.h> header file. */
113116
#cmakedefine HAVE_LINK_H ${HAVE_LINK_H}
114117

@@ -223,6 +226,9 @@
223226
/* Define to 1 if you have the <valgrind/valgrind.h> header file. */
224227
#cmakedefine HAVE_VALGRIND_VALGRIND_H ${HAVE_VALGRIND_VALGRIND_H}
225228

229+
/* Define to 1 if you have the <zlib.h> header file. */
230+
#cmakedefine HAVE_ZLIB_H ${HAVE_ZLIB_H}
231+
226232
/* Have host's _alloca */
227233
#cmakedefine HAVE__ALLOCA ${HAVE__ALLOCA}
228234

0 commit comments

Comments
 (0)