Skip to content

Commit

Permalink
Revise wrapper, using find_package
Browse files Browse the repository at this point in the history
  • Loading branch information
dg0yt committed Sep 16, 2021
1 parent f38fbdc commit 0454ce9
Showing 1 changed file with 38 additions and 70 deletions.
108 changes: 38 additions & 70 deletions ports/libarchive/vcpkg-cmake-wrapper.cmake.in
Original file line number Diff line number Diff line change
@@ -1,96 +1,64 @@
_find_package(${ARGS})

include(CMakeFindDependencyMacro)

find_dependency(ZLIB)
if(@ENABLE_BZip2@)
find_dependency(BZip2)
endif()
if(@ENABLE_LIBXML2@)
find_dependency(LibXml2)
endif()
if(@ENABLE_LZ4@)
find_dependency(lz4)
cmake_policy(PUSH)
cmake_policy(SET CMP0057 NEW)
set(z_vcpkg_libarchive_args "")
if("REQUIRED" IN_LIST ARGS)
list(APPEND z_vcpkg_libarchive_args "REQUIRED")
endif()
if(@ENABLE_LZMA@)
find_dependency(LibLZMA)
endif()
if(@ENABLE_ZSTD@)
find_dependency(zstd)
endif()
if(@ENABLE_OPENSSL@ AND NOT CMAKE_SYSTEM_NAME MATCHES "Darwin")
find_dependency(OpenSSL)
endif()
if(@ENABLE_LZO@)
find_library(LZO_LIBRARY_DEBUG NAMES lzo2d lzo2 NAMES_PER_DIR PATH_SUFFIXES lib PATHS "${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/debug" NO_DEFAULT_PATH)
find_library(LZO_LIBRARY_RELEASE NAMES lzo2 NAMES_PER_DIR PATH_SUFFIXES lib PATHS "${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}" NO_DEFAULT_PATH)
if("QUIET" IN_LIST ARGS)
list(APPEND z_vcpkg_libarchive_args "QUIET")
endif()
_find_package(${ARGS})

if("@VCPKG_LIBRARY_LINKAGE@" STREQUAL "static")
if(@ENABLE_ZLIB@)
list(APPEND LibArchive_LIBRARIES ZLIB::ZLIB)
endif()
set(z_vcpkg_libarchive_libs "")
find_package(ZLIB ${z_vcpkg_libarchive_args})
list(APPEND z_vcpkg_libarchive_libs ZLIB::ZLIB)
if(@ENABLE_BZip2@)
list(APPEND LibArchive_LIBRARIES BZip2::BZip2)
find_package(BZip2 ${z_vcpkg_libarchive_args})
list(APPEND z_vcpkg_libarchive_libs BZip2::BZip2)
endif()
if(@ENABLE_LIBXML2@)
list(APPEND LibArchive_LIBRARIES LibXml2::LibXml2)
find_package(LibXml2 ${z_vcpkg_libarchive_args})
list(APPEND z_vcpkg_libarchive_libs LibXml2::LibXml2)
endif()
if(@ENABLE_LZ4@)
list(APPEND LibArchive_LIBRARIES lz4::lz4)
find_package(lz4 CONFIG ${z_vcpkg_libarchive_args})
list(APPEND z_vcpkg_libarchive_libs lz4::lz4)
endif()
if(@ENABLE_LZMA@)
list(APPEND LibArchive_LIBRARIES LibLZMA::LibLZMA)
find_package(LibLZMA ${z_vcpkg_libarchive_args})
list(APPEND z_vcpkg_libarchive_libs LibLZMA::LibLZMA)
endif()
if(@ENABLE_LZO@)
if(LZO_LIBRARY_RELEASE)
list(APPEND LibArchive_LIBRARIES optimized ${LZO_LIBRARY_RELEASE})
endif()
if(LZO_LIBRARY_DEBUG)
list(APPEND LibArchive_LIBRARIES debug ${LZO_LIBRARY_DEBUG})
include(SelectLibraryConfigurations)
find_library(LZO_LIBRARY_DEBUG NAMES lzo2d lzo2 NAMES_PER_DIR PATH_SUFFIXES lib PATHS "${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/debug" NO_DEFAULT_PATH)
find_library(LZO_LIBRARY_RELEASE NAMES lzo2 NAMES_PER_DIR PATH_SUFFIXES lib PATHS "${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}" NO_DEFAULT_PATH)
select_library_configurations(LZO)
set(LZO_FOUND FALSE)
if(LZO_LIBRARY)
list(APPEND z_vcpkg_libarchive_libs ${LZO_LIBRARY})
else()
set(LibArchive_FOUND FALSE)
endif()
endif()
if(@ENABLE_ZSTD@)
find_package(zstd ${z_vcpkg_libarchive_args})
if(TARGET zstd::libzstd_shared)
list(APPEND LibArchive_LIBRARIES zstd::libzstd_shared)
list(APPEND z_vcpkg_libarchive_libs zstd::libzstd_shared)
else(TARGET zstd::libzstd_shared)
list(APPEND LibArchive_LIBRARIES zstd::libzstd_static)
list(APPEND z_vcpkg_libarchive_libs zstd::libzstd_static)
endif(TARGET zstd::libzstd_shared)
endif()
if(@ENABLE_OPENSSL@ AND NOT CMAKE_SYSTEM_NAME MATCHES "Darwin")
list(APPEND LibArchive_LIBRARIES OpenSSL::Crypto)
find_package(OpenSSL ${z_vcpkg_libarchive_args})
list(APPEND z_vcpkg_libarchive_libs OpenSSL::Crypto)
endif()

list(APPEND LibArchive_LIBRARIES ${z_vcpkg_libarchive_libs})
if(TARGET LibArchive::LibArchive)
if(@ENABLE_BZip2@)
set_property(TARGET LibArchive::LibArchive APPEND PROPERTY INTERFACE_LINK_LIBRARIES BZip2::BZip2)
endif()
if(@ENABLE_ZLIB@)
set_property(TARGET LibArchive::LibArchive APPEND PROPERTY INTERFACE_LINK_LIBRARIES ZLIB::ZLIB)
endif()
if(@ENABLE_LIBXML2@)
set_property(TARGET LibArchive::LibArchive APPEND PROPERTY INTERFACE_LINK_LIBRARIES LibXml2::LibXml2)
endif()
if(@ENABLE_LZ4@)
set_property(TARGET LibArchive::LibArchive APPEND PROPERTY INTERFACE_LINK_LIBRARIES lz4::lz4)
endif()
if(@ENABLE_LZMA@)
set_property(TARGET LibArchive::LibArchive APPEND PROPERTY INTERFACE_LINK_LIBRARIES LibLZMA::LibLZMA)
endif()
if(@ENABLE_LZO@)
if(LZO_LIBRARY_RELEASE)
list(APPEND interface_lib \$<\$<NOT:\$<CONFIG:DEBUG>>:${LZO_LIBRARY_RELEASE}>)
endif()
if(LZO_LIBRARY_DEBUG)
list(APPEND interface_lib \$<\$<CONFIG:DEBUG>:${LZO_LIBRARY_DEBUG}>)
endif()
set_property(TARGET LibArchive::LibArchive APPEND PROPERTY INTERFACE_LINK_LIBRARIES ${interface_lib})
endif()
if(@ENABLE_ZSTD@)
set_property(TARGET LibArchive::LibArchive APPEND PROPERTY INTERFACE_LINK_LIBRARIES zstd::libzstd_static)
endif()
if(@ENABLE_OPENSSL@)
set_property(TARGET LibArchive::LibArchive APPEND PROPERTY INTERFACE_LINK_LIBRARIES OpenSSL::Crypto)
endif()
set_property(TARGET LibArchive::LibArchive APPEND PROPERTY INTERFACE_LINK_LIBRARIES ${z_vcpkg_libarchive_libs})
endif()
unset(z_vcpkg_libarchive_libs)
endif()
unset(z_vcpkg_libarchive_args)
cmake_policy(POP)

0 comments on commit 0454ce9

Please sign in to comment.