From 2be5a7de4ea987649dfc1ac669928fecf2613046 Mon Sep 17 00:00:00 2001 From: Alex Turbov Date: Sun, 21 Aug 2022 09:02:56 +0400 Subject: Build: Use imported target `ZLIB::ZLIB` instead of variables --- Source/CMakeLists.txt | 3 +-- Source/Modules/CMakeBuildUtilities.cmake | 18 ++++++++---------- Utilities/cmcurl/CMakeLists.txt | 17 +++-------------- Utilities/cmcurl/lib/content_encoding.c | 2 +- Utilities/cmcurl/lib/version.c | 2 +- Utilities/cmlibarchive/CMakeLists.txt | 2 ++ 6 files changed, 16 insertions(+), 28 deletions(-) diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index 9357fdf..3edaabb 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -743,7 +743,6 @@ target_include_directories( "${CMake_BINARY_DIR}/Source" "${CMake_SOURCE_DIR}/Source" "${CMake_SOURCE_DIR}/Source/LexerParser" - ${CMAKE_ZLIB_INCLUDES} ${CMAKE_EXPAT_INCLUDES} ${CMAKE_TAR_INCLUDES} ${CMake_HAIKU_INCLUDE_DIRS} @@ -753,8 +752,8 @@ target_link_libraries( PUBLIC cmstd cmsys + ZLIB::ZLIB ${CMAKE_EXPAT_LIBRARIES} - ${CMAKE_ZLIB_LIBRARIES} ${CMAKE_TAR_LIBRARIES} ${CMAKE_CURL_LIBRARIES} ${CMAKE_JSONCPP_LIBRARIES} diff --git a/Source/Modules/CMakeBuildUtilities.cmake b/Source/Modules/CMakeBuildUtilities.cmake index 4823adf..f217f9b 100644 --- a/Source/Modules/CMakeBuildUtilities.cmake +++ b/Source/Modules/CMakeBuildUtilities.cmake @@ -114,18 +114,20 @@ endif() #--------------------------------------------------------------------- # Build zlib library for Curl, CMake, and CTest. -set(CMAKE_ZLIB_HEADER "cm_zlib.h") if(CMAKE_USE_SYSTEM_ZLIB) find_package(ZLIB) if(NOT ZLIB_FOUND) message(FATAL_ERROR "CMAKE_USE_SYSTEM_ZLIB is ON but a zlib is not found!") endif() - set(CMAKE_ZLIB_INCLUDES ${ZLIB_INCLUDE_DIR}) - set(CMAKE_ZLIB_LIBRARIES ${ZLIB_LIBRARIES}) else() - set(CMAKE_ZLIB_INCLUDES ${CMake_SOURCE_DIR}/Utilities) - set(CMAKE_ZLIB_LIBRARIES cmzlib) + if(NOT POLICY CMP0102) # CMake < 3.17 + # Store in cache to protect from mark_as_advanced. + set(ZLIB_INCLUDE_DIR ${CMake_SOURCE_DIR}/Utilities CACHE PATH "") + else() + set(ZLIB_INCLUDE_DIR ${CMake_SOURCE_DIR}/Utilities) + endif() + set(ZLIB_LIBRARY cmzlib) set(WITHOUT_ZLIB_DLL "") set(WITHOUT_ZLIB_DLL_WITH_LIB cmzlib) set(ZLIB_DLL "") @@ -134,6 +136,7 @@ else() set(ZLIB_WINAPI_COMPILED 0) set(ZLIB_WINAPI_WITH_LIB cmzlib) add_subdirectory(Utilities/cmzlib) + add_library(ZLIB::ZLIB ALIAS cmzlib) CMAKE_SET_TARGET_FOLDER(cmzlib "Utilities/3rdParty") endif() @@ -148,9 +151,6 @@ if(CMAKE_USE_SYSTEM_CURL) set(CMAKE_CURL_INCLUDES ${CURL_INCLUDE_DIRS}) set(CMAKE_CURL_LIBRARIES ${CURL_LIBRARIES}) else() - set(CURL_SPECIAL_ZLIB_H ${CMAKE_ZLIB_HEADER}) - set(CURL_SPECIAL_LIBZ_INCLUDES ${CMAKE_ZLIB_INCLUDES}) - set(CURL_SPECIAL_LIBZ ${CMAKE_ZLIB_LIBRARIES}) set(CMAKE_CURL_INCLUDES) set(CMAKE_CURL_LIBRARIES cmcurl) if(CMAKE_TESTS_CDASH_SERVER) @@ -263,8 +263,6 @@ if(CMAKE_USE_SYSTEM_LIBARCHIVE) else() set(EXPAT_INCLUDE_DIR ${CMAKE_EXPAT_INCLUDES}) set(EXPAT_LIBRARY ${CMAKE_EXPAT_LIBRARIES}) - set(ZLIB_INCLUDE_DIR ${CMAKE_ZLIB_INCLUDES}) - set(ZLIB_LIBRARY ${CMAKE_ZLIB_LIBRARIES}) add_compile_definitions(LIBARCHIVE_STATIC) set(ENABLE_MBEDTLS OFF) set(ENABLE_NETTLE OFF) diff --git a/Utilities/cmcurl/CMakeLists.txt b/Utilities/cmcurl/CMakeLists.txt index b8cf412..9b468c3 100644 --- a/Utilities/cmcurl/CMakeLists.txt +++ b/Utilities/cmcurl/CMakeLists.txt @@ -852,11 +852,11 @@ endif() # Check for symbol dlopen (same as HAVE_LIBDL) check_library_exists("${CURL_LIBS}" dlopen "" HAVE_DLOPEN) -if(0) # This code not needed for building within CMake. set(HAVE_LIBZ OFF) set(HAVE_ZLIB_H OFF) set(USE_ZLIB OFF) -optional_dependency(ZLIB) +#optional_dependency(ZLIB) +find_package(ZLIB) if(ZLIB_FOUND) set(HAVE_ZLIB_H ON) set(HAVE_LIBZ ON) @@ -870,19 +870,8 @@ if(ZLIB_FOUND) else() list(APPEND CURL_LIBS ${ZLIB_LIBRARIES}) include_directories(${ZLIB_INCLUDE_DIRS}) + list(APPEND CMAKE_REQUIRED_INCLUDES ${ZLIB_INCLUDE_DIRS}) endif() - list(APPEND CMAKE_REQUIRED_INCLUDES ${ZLIB_INCLUDE_DIRS}) -endif() -endif() - -#----------------------------------------------------------------------------- -# CMake-specific curl code. - -if(CURL_SPECIAL_LIBZ) - set(CURL_LIBS ${CURL_LIBS} "${CURL_SPECIAL_LIBZ}") - include_directories(${CURL_SPECIAL_LIBZ_INCLUDES}) - set(HAVE_LIBZ 0) - set(HAVE_ZLIB_H 0) endif() option(CURL_BROTLI "Set to ON to enable building curl with brotli support." OFF) diff --git a/Utilities/cmcurl/lib/content_encoding.c b/Utilities/cmcurl/lib/content_encoding.c index c03637a..4c723c3 100644 --- a/Utilities/cmcurl/lib/content_encoding.c +++ b/Utilities/cmcurl/lib/content_encoding.c @@ -27,7 +27,7 @@ #include #ifdef HAVE_ZLIB_H -#include +#include #endif #ifdef HAVE_BROTLI diff --git a/Utilities/cmcurl/lib/version.c b/Utilities/cmcurl/lib/version.c index e37253d..5e3e428 100644 --- a/Utilities/cmcurl/lib/version.c +++ b/Utilities/cmcurl/lib/version.c @@ -51,7 +51,7 @@ #endif #ifdef HAVE_ZLIB_H -#include +#include #endif #ifdef HAVE_BROTLI diff --git a/Utilities/cmlibarchive/CMakeLists.txt b/Utilities/cmlibarchive/CMakeLists.txt index eea472f..b38e653 100644 --- a/Utilities/cmlibarchive/CMakeLists.txt +++ b/Utilities/cmlibarchive/CMakeLists.txt @@ -442,6 +442,8 @@ SET(ADDITIONAL_LIBS "") # IF(ENABLE_ZLIB) FIND_PACKAGE(ZLIB) + SET(ZLIB_INCLUDE_DIR "") + SET(ZLIB_LIBRARIES ZLIB::ZLIB) ELSE() SET(ZLIB_FOUND FALSE) # Override cached value ENDIF() -- cgit v0.12