Skip to content

Commit abb0075

Browse files
committed
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 68a235d, e6c7ed6. The problem with the windows bot is a need for clearing the cache.
1 parent aa17d31 commit abb0075

File tree

16 files changed

+33
-60
lines changed

16 files changed

+33
-60
lines changed

clang/test/CMakeLists.txt

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,13 @@ 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-
2112
llvm_canonicalize_cmake_booleans(
2213
CLANG_BUILD_EXAMPLES
2314
CLANG_ENABLE_ARCMT
2415
CLANG_ENABLE_STATIC_ANALYZER
2516
ENABLE_BACKTRACES
2617
ENABLE_EXPERIMENTAL_NEW_PASS_MANAGER
27-
HAVE_LIBZ
18+
LLVM_ENABLE_ZLIB
2819
LLVM_ENABLE_PER_TARGET_RUNTIME_DIR
2920
LLVM_ENABLE_PLUGINS
3021
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 = @HAVE_LIBZ@
19+
config.have_zlib = @LLVM_ENABLE_ZLIB@
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", "@HAVE_LIBZ@")
53+
set_default("have_zlib", "@LLVM_ENABLE_ZLIB@")
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: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,8 @@ 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-
167
llvm_canonicalize_cmake_booleans(
17-
HAVE_LIBZ
8+
LLVM_ENABLE_ZLIB
189
LLVM_LIBXML2_ENABLED
1910
)
2011

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 = @HAVE_LIBZ@
17+
config.have_zlib = @LLVM_ENABLE_ZLIB@
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 defined(HAVE_LIBZ)
53+
#if LLVM_ENABLE_ZLIB
5454
#include <zlib.h>
5555
#endif
5656

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

585-
#if defined(HAVE_LIBZ)
585+
#if LLVM_ENABLE_ZLIB
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 defined(HAVE_LIBZ)
1048+
#if LLVM_ENABLE_ZLIB
10491049
if (avail_type == CompressionType::None) {
10501050
for (auto compression : supported_compressions) {
10511051
if (compression == "zlib-deflate") {

llvm/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +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-
option(LLVM_ENABLE_ZLIB "Use zlib for compression/decompression if available." ON)
350+
set(LLVM_ENABLE_ZLIB "ON" CACHE STRING "Use zlib for compression/decompression if available. Can be ON, OFF, or FORCE_ON")
351351

352352
set(LLVM_Z3_INSTALL_DIR "" CACHE STRING "Install directory of the Z3 solver.")
353353

llvm/cmake/config-ix.cmake

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ 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)
6059
check_include_file(fenv.h HAVE_FENV_H)
6160
check_symbol_exists(FE_ALL_EXCEPT "fenv.h" HAVE_DECL_FE_ALL_EXCEPT)
6261
check_symbol_exists(FE_INEXACT "fenv.h" HAVE_DECL_FE_INEXACT)
@@ -118,19 +117,6 @@ endif()
118117
# Don't look for these libraries if we're using MSan, since uninstrumented third
119118
# party code may call MSan interceptors like strlen, leading to false positives.
120119
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-
134120
# Don't look for these libraries on Windows.
135121
if (NOT PURE_WINDOWS)
136122
# Skip libedit if using ASan as it contains memory leaks.
@@ -515,10 +501,21 @@ else( LLVM_ENABLE_THREADS )
515501
message(STATUS "Threads disabled.")
516502
endif()
517503

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)
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)
522519
endif()
523520
endif()
524521

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,6 @@
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-
115112
/* Define to 1 if you have the <link.h> header file. */
116113
#cmakedefine HAVE_LINK_H ${HAVE_LINK_H}
117114

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

229-
/* Define to 1 if you have the <zlib.h> header file. */
230-
#cmakedefine HAVE_ZLIB_H ${HAVE_ZLIB_H}
231-
232226
/* Have host's _alloca */
233227
#cmakedefine HAVE__ALLOCA ${HAVE__ALLOCA}
234228

llvm/lib/Support/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
set(system_libs)
2-
if ( LLVM_ENABLE_ZLIB AND HAVE_LIBZ )
3-
set(system_libs ${system_libs} ${ZLIB_LIBRARIES})
1+
if(LLVM_ENABLE_ZLIB)
2+
set(system_libs ${ZLIB_LIBRARY})
43
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.

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 == 0 || !HAVE_ZLIB_H
28+
#if !LLVM_ENABLE_ZLIB
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 == 1 && HAVE_ZLIB_H
20+
#if LLVM_ENABLE_ZLIB
2121
#include <zlib.h>
2222
#endif
2323

2424
using namespace llvm;
2525

26-
#if LLVM_ENABLE_ZLIB == 1 && HAVE_LIBZ
26+
#if LLVM_ENABLE_ZLIB
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
54
HAVE_OCAMLOPT
65
HAVE_OCAML_OUNIT
76
LLVM_ENABLE_DIA_SDK
87
LLVM_ENABLE_FFI
98
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
@@ -36,7 +36,7 @@ config.host_cxx = "@HOST_CXX@"
3636
config.host_ldflags = '@HOST_LDFLAGS@'
3737
config.llvm_use_intel_jitevents = @LLVM_USE_INTEL_JITEVENTS@
3838
config.llvm_use_sanitizer = "@LLVM_USE_SANITIZER@"
39-
config.have_zlib = @HAVE_LIBZ@
39+
config.have_zlib = @LLVM_ENABLE_ZLIB@
4040
config.have_libxar = @HAVE_LIBXAR@
4141
config.have_dia_sdk = @LLVM_ENABLE_DIA_SDK@
4242
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 == 1 && HAVE_LIBZ
24+
#if LLVM_ENABLE_ZLIB
2525

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

0 commit comments

Comments
 (0)