Commit 8c1a79dc authored by Petr Hosek's avatar Petr Hosek
Browse files

[CMake] Simplify 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 is a reland of abb00753 with all followup changes and fixes that
should address issues that were reported in PR44780.

Differential Revision: https://reviews.llvm.org/D79219
parent 6b78ed60
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -114,6 +114,10 @@ if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR )
  option(CLANG_ENABLE_BOOTSTRAP "Generate the clang bootstrap target" OFF)
  option(LLVM_ENABLE_LIBXML2 "Use libxml2 if available." ON)

  if(LLVM_ENABLE_ZLIB)
    find_package(ZLIB)
  endif()

  include(AddLLVM)
  include(TableGen)
  include(HandleLLVMOptions)
+1 −10
Original line number Diff line number Diff line
@@ -9,15 +9,6 @@ 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
@@ -25,7 +16,7 @@ llvm_canonicalize_cmake_booleans(
  CLANG_SPAWN_CC1
  ENABLE_BACKTRACES
  ENABLE_EXPERIMENTAL_NEW_PASS_MANAGER
  HAVE_LIBZ
  LLVM_ENABLE_ZLIB
  LLVM_ENABLE_PER_TARGET_RUNTIME_DIR
  LLVM_ENABLE_PLUGINS
  LLVM_ENABLE_THREADS)
+1 −1
Original line number Diff line number Diff line
@@ -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@
+1 −1
Original line number Diff line number Diff line
@@ -56,7 +56,7 @@ elif config.android:
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
+4 −0
Original line number Diff line number Diff line
@@ -51,6 +51,10 @@ if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
  set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin)
  find_program(LLVM_TABLEGEN_EXE "llvm-tblgen" ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH)

  if(LLVM_ENABLE_ZLIB)
    find_package(ZLIB)
  endif()

  include(AddLLVM)
  include(TableGen)
  include(HandleLLVMOptions)
Loading