Skip to content

Commit 916be8f

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.
1 parent 4e36356 commit 916be8f

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
@@ -51,7 +51,7 @@ if config.enable_per_target_runtime_dir:
5151
else:
5252
set_default("target_suffix", "-%s" % config.target_arch)
5353

54-
set_default("have_zlib", "@LLVM_ENABLE_ZLIB@")
54+
set_default("have_zlib", "@HAVE_LIBZ@")
5555
set_default("libcxx_used", "@LLVM_LIBCXX_USED@")
5656

5757
# 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
@@ -1053,7 +1053,7 @@ void GDBRemoteCommunicationClient::MaybeEnableCompression(
10531053
}
10541054
#endif
10551055

1056-
#if LLVM_ENABLE_ZLIB
1056+
#if defined(HAVE_LIBZ)
10571057
if (avail_type == CompressionType::None) {
10581058
for (auto compression : supported_compressions) {
10591059
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

llvm/lib/Support/CMakeLists.txt

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
if(LLVM_ENABLE_ZLIB)
2-
set(imported_libs ZLIB::ZLIB)
1+
set(system_libs)
2+
if ( LLVM_ENABLE_ZLIB AND HAVE_LIBZ )
3+
set(system_libs ${system_libs} ${ZLIB_LIBRARIES})
34
endif()
4-
55
if( MSVC OR MINGW )
66
# libuuid required for FOLDERID_Profile usage in lib/Support/Windows/Path.inc.
77
# advapi32 required for CryptAcquireContextW in lib/Support/Windows/Path.inc.
@@ -186,31 +186,10 @@ add_llvm_component_library(LLVMSupport
186186
${LLVM_MAIN_INCLUDE_DIR}/llvm/ADT
187187
${LLVM_MAIN_INCLUDE_DIR}/llvm/Support
188188
${Backtrace_INCLUDE_DIRS}
189-
LINK_LIBS ${system_libs} ${imported_libs} ${delayload_flags} ${Z3_LINK_FILES}
189+
LINK_LIBS ${system_libs} ${delayload_flags} ${Z3_LINK_FILES}
190190
)
191191

192-
set(llvm_system_libs ${system_libs})
193-
194-
if(LLVM_ENABLE_ZLIB)
195-
string(TOUPPER ${CMAKE_BUILD_TYPE} build_type)
196-
get_property(zlib_library TARGET ZLIB::ZLIB PROPERTY LOCATION_${build_type})
197-
if(NOT zlib_library)
198-
get_property(zlib_library TARGET ZLIB::ZLIB PROPERTY LOCATION)
199-
endif()
200-
get_filename_component(zlib_library ${zlib_library} NAME)
201-
if(CMAKE_STATIC_LIBRARY_PREFIX AND
202-
zlib_library MATCHES "^${CMAKE_STATIC_LIBRARY_PREFIX}.*${CMAKE_STATIC_LIBRARY_SUFFIX}$")
203-
STRING(REGEX REPLACE "^${CMAKE_STATIC_LIBRARY_PREFIX}" "" zlib_library ${zlib_library})
204-
STRING(REGEX REPLACE "${CMAKE_STATIC_LIBRARY_SUFFIX}$" "" zlib_library ${zlib_library})
205-
elseif(CMAKE_SHARED_LIBRARY_PREFIX AND
206-
zlib_library MATCHES "^${CMAKE_SHARED_LIBRARY_PREFIX}.*${CMAKE_SHARED_LIBRARY_SUFFIX}$")
207-
STRING(REGEX REPLACE "^${CMAKE_SHARED_LIBRARY_PREFIX}" "" zlib_library ${zlib_library})
208-
STRING(REGEX REPLACE "${CMAKE_SHARED_LIBRARY_SUFFIX}$" "" zlib_library ${zlib_library})
209-
endif()
210-
set(llvm_system_libs ${llvm_system_libs} "${zlib_library}")
211-
endif()
212-
213-
set_property(TARGET LLVMSupport PROPERTY LLVM_SYSTEM_LIBS "${llvm_system_libs}")
192+
set_property(TARGET LLVMSupport PROPERTY LLVM_SYSTEM_LIBS "${system_libs}")
214193

215194
if(LLVM_WITH_Z3)
216195
target_include_directories(LLVMSupport SYSTEM

llvm/lib/Support/CRC.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
using namespace llvm;
2727

28-
#if !LLVM_ENABLE_ZLIB
28+
#if LLVM_ENABLE_ZLIB == 0 || !HAVE_ZLIB_H
2929

3030
static const uint32_t CRCTable[256] = {
3131
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,

llvm/lib/Support/Compression.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@
1717
#include "llvm/Support/Compiler.h"
1818
#include "llvm/Support/Error.h"
1919
#include "llvm/Support/ErrorHandling.h"
20-
#if LLVM_ENABLE_ZLIB
20+
#if LLVM_ENABLE_ZLIB == 1 && HAVE_ZLIB_H
2121
#include <zlib.h>
2222
#endif
2323

2424
using namespace llvm;
2525

26-
#if LLVM_ENABLE_ZLIB
26+
#if LLVM_ENABLE_ZLIB == 1 && HAVE_LIBZ
2727
static Error createError(StringRef Err) {
2828
return make_error<StringError>(Err, inconvertibleErrorCode());
2929
}

llvm/test/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
llvm_canonicalize_cmake_booleans(
22
BUILD_SHARED_LIBS
33
HAVE_LIBXAR
4+
HAVE_LIBZ
45
HAVE_OCAMLOPT
56
HAVE_OCAML_OUNIT
67
LLVM_ENABLE_DIA_SDK
78
LLVM_ENABLE_FFI
89
LLVM_ENABLE_THREADS
9-
LLVM_ENABLE_ZLIB
1010
LLVM_INCLUDE_GO_TESTS
1111
LLVM_LIBXML2_ENABLED
1212
LLVM_LINK_LLVM_DYLIB

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ config.host_cxx = "@HOST_CXX@"
3333
config.host_ldflags = '@HOST_LDFLAGS@'
3434
config.llvm_use_intel_jitevents = @LLVM_USE_INTEL_JITEVENTS@
3535
config.llvm_use_sanitizer = "@LLVM_USE_SANITIZER@"
36-
config.have_zlib = @LLVM_ENABLE_ZLIB@
36+
config.have_zlib = @HAVE_LIBZ@
3737
config.have_libxar = @HAVE_LIBXAR@
3838
config.have_dia_sdk = @LLVM_ENABLE_DIA_SDK@
3939
config.enable_ffi = @LLVM_ENABLE_FFI@

llvm/unittests/Support/CompressionTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ using namespace llvm;
2121

2222
namespace {
2323

24-
#if LLVM_ENABLE_ZLIB
24+
#if LLVM_ENABLE_ZLIB == 1 && HAVE_LIBZ
2525

2626
void TestZlibCompression(StringRef Input, int Level) {
2727
SmallString<32> Compressed;

0 commit comments

Comments
 (0)