From 1f5d9c5299bb7add5a7afcc1d054fd4259c04b89 Mon Sep 17 00:00:00 2001 From: Alex Turbov Date: Sun, 21 Aug 2022 09:13:32 +0400 Subject: Build: Use imported target `LibArchive::LibArchive` instead of variables --- Modules/FindLibArchive.cmake | 3 +++ Source/CMakeLists.txt | 3 +-- Source/Modules/CMakeBuildUtilities.cmake | 13 +++++++++---- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/Modules/FindLibArchive.cmake b/Modules/FindLibArchive.cmake index 08078a2..9d3ac13 100644 --- a/Modules/FindLibArchive.cmake +++ b/Modules/FindLibArchive.cmake @@ -26,6 +26,9 @@ The module defines the following ``IMPORTED`` targets: .. versionadded:: 3.6 Support for new libarchive 3.2 version string format. +.. versionadded:: 3.17 + Provides an imported target. + #]=======================================================================] find_path(LibArchive_INCLUDE_DIR diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index 93b3f0c..b1d8cb7 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_TAR_INCLUDES} ${CMake_HAIKU_INCLUDE_DIRS} ) target_link_libraries( @@ -752,8 +751,8 @@ target_link_libraries( cmstd cmsys EXPAT::EXPAT + LibArchive::LibArchive ZLIB::ZLIB - ${CMAKE_TAR_LIBRARIES} ${CMAKE_CURL_LIBRARIES} ${CMAKE_JSONCPP_LIBRARIES} ${CMAKE_LIBUV_LIBRARIES} diff --git a/Source/Modules/CMakeBuildUtilities.cmake b/Source/Modules/CMakeBuildUtilities.cmake index dad4bc1..157367f 100644 --- a/Source/Modules/CMakeBuildUtilities.cmake +++ b/Source/Modules/CMakeBuildUtilities.cmake @@ -259,12 +259,16 @@ if(CMAKE_USE_SYSTEM_LIBARCHIVE) if(NOT LibArchive_FOUND) message(FATAL_ERROR "CMAKE_USE_SYSTEM_LIBARCHIVE is ON but LibArchive is not found!") endif() - set(CMAKE_TAR_INCLUDES ${LibArchive_INCLUDE_DIRS}) - set(CMAKE_TAR_LIBRARIES ${LibArchive_LIBRARIES}) + # NOTE `FindLibArchive` got imported targets support since 3.17 + if (NOT TARGET LibArchive::LibArchive) + add_library(LibArchive::LibArchive UNKNOWN IMPORTED) + set_target_properties(LibArchive::LibArchive PROPERTIES + IMPORTED_LOCATION "${LibArchive_LIBRARIES}" + INTERFACE_INCLUDE_DIRECTORIES "${LibArchive_INCLUDE_DIRS}") + endif () else() set(EXPAT_INCLUDE_DIR ${CMAKE_EXPAT_INCLUDES}) set(EXPAT_LIBRARY ${CMAKE_EXPAT_LIBRARIES}) - add_compile_definitions(LIBARCHIVE_STATIC) set(ENABLE_MBEDTLS OFF) set(ENABLE_NETTLE OFF) if(DEFINED CMAKE_USE_OPENSSL) @@ -300,8 +304,9 @@ else() set(ENABLE_SAFESEH "" CACHE INTERNAL "libarchive: No /SAFESEH linker flag") set(WINDOWS_VERSION "WIN7" CACHE INTERNAL "libarchive: Set Windows version to use (Windows only)") add_subdirectory(Utilities/cmlibarchive) + add_library(LibArchive::LibArchive ALIAS cmlibarchive) + target_compile_definitions(cmlibarchive INTERFACE LIBARCHIVE_STATIC) CMAKE_SET_TARGET_FOLDER(cmlibarchive "Utilities/3rdParty") - set(CMAKE_TAR_LIBRARIES cmlibarchive ${BZIP2_LIBRARIES}) endif() #--------------------------------------------------------------------- -- cgit v0.12