Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #1446 #2253

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 43 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,8 @@ IF(DEFINED __GNUWIN32PATH AND EXISTS "${__GNUWIN32PATH}")
ENDIF(DEFINED __GNUWIN32PATH AND EXISTS "${__GNUWIN32PATH}")

SET(ADDITIONAL_LIBS "")
SET(LIBARCHIVE_LIBS_PRIVATE "") # additional libs for which the pc module is unknown
SET(LIBARCHIVE_REQUIRES_PRIVATE "") # pc modules for additonal libs
#
# Find ZLIB
#
Expand All @@ -452,6 +454,7 @@ IF(ZLIB_FOUND)
SET(HAVE_ZLIB_H 1)
INCLUDE_DIRECTORIES(${ZLIB_INCLUDE_DIR})
LIST(APPEND ADDITIONAL_LIBS ${ZLIB_LIBRARIES})
LIST(APPEND LIBARCHIVE_REQUIRES_PRIVATE zlib)
IF(WIN32 AND NOT CYGWIN)
#
# Test if ZLIB_WINAPI macro is needed to use.
Expand Down Expand Up @@ -491,6 +494,7 @@ IF(BZIP2_FOUND)
SET(HAVE_BZLIB_H 1)
INCLUDE_DIRECTORIES(${BZIP2_INCLUDE_DIR})
LIST(APPEND ADDITIONAL_LIBS ${BZIP2_LIBRARIES})
LIST(APPEND LIBARCHIVE_REQUIRES_PRIVATE bzip2)
# Test if a macro is needed for the library.
TRY_MACRO_FOR_LIBRARY(
"${BZIP2_INCLUDE_DIR}" "${BZIP2_LIBRARIES}"
Expand Down Expand Up @@ -519,6 +523,8 @@ ENDIF()
IF(LIBLZMA_FOUND)
SET(HAVE_LIBLZMA 1)
SET(HAVE_LZMA_H 1)
LIST(APPEND ADDITIONAL_LIBS LibLZMA::LibLZMA)
LIST(APPEND LIBARCHIVE_REQUIRES_PRIVATE liblzma)
CMAKE_PUSH_CHECK_STATE()
SET(CMAKE_REQUIRED_INCLUDES ${LIBLZMA_INCLUDE_DIR})
SET(CMAKE_REQUIRED_LIBRARIES ${LIBLZMA_LIBRARIES})
Expand Down Expand Up @@ -566,6 +572,7 @@ IF(LZO2_FOUND)
SET(HAVE_LZO_LZO1X_H 1)
INCLUDE_DIRECTORIES(${LZO2_INCLUDE_DIR})
LIST(APPEND ADDITIONAL_LIBS ${LZO2_LIBRARY})
LIST(APPEND LIBARCHIVE_REQUIRES_PRIVATE lzo2)
#
# TODO: test for static library.
#
Expand Down Expand Up @@ -593,6 +600,7 @@ IF(LIBB2_FOUND)
SET(HAVE_BLAKE2_H 1)
SET(ARCHIVE_BLAKE2 FALSE)
LIST(APPEND ADDITIONAL_LIBS ${LIBB2_LIBRARY})
LIST(APPEND LIBARCHIVE_LIBS_PRIVATE ${LIBB2_LIBRARY})
INCLUDE_DIRECTORIES(${LIBB2_INCLUDE_DIR})
CMAKE_PUSH_CHECK_STATE()
SET(CMAKE_REQUIRED_LIBRARIES ${LIBB2_LIBRARY})
Expand All @@ -606,6 +614,8 @@ ENDIF(LIBB2_FOUND)
# Find LZ4
#
IF(ENABLE_LZ4)
FIND_PACKAGE(LZ4 NAMES lz4 CONFIG REQUIRED)
elseif(0)
IF (LZ4_INCLUDE_DIR)
# Already in cache, be silent
SET(LZ4_FIND_QUIETLY TRUE)
Expand All @@ -621,6 +631,10 @@ ENDIF(ENABLE_LZ4)
IF(LZ4_FOUND)
SET(HAVE_LIBLZ4 1)
SET(HAVE_LZ4_H 1)
SET(HAVE_LZ4HC_H 1)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems separate?

LIST(APPEND ADDITIONAL_LIBS lz4::lz4)
LIST(APPEND LIBARCHIVE_REQUIRES_PRIVATE liblz4)
elseif(0)
CMAKE_PUSH_CHECK_STATE() # Save the state of the variables
SET(CMAKE_REQUIRED_INCLUDES ${LZ4_INCLUDE_DIR})
CHECK_INCLUDE_FILES("lz4hc.h" HAVE_LZ4HC_H)
Expand All @@ -637,6 +651,8 @@ MARK_AS_ADVANCED(CLEAR LZ4_LIBRARY)
# Find Zstd
#
IF(ENABLE_ZSTD)
FIND_PACKAGE(ZSTD NAMES zstd CONFIG REQUIRED)
elseif(0)
Comment on lines +654 to +655
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not suitable here.
User may not have zstd CMake config.

IF (ZSTD_INCLUDE_DIR)
# Already in cache, be silent
SET(ZSTD_FIND_QUIETLY TRUE)
Expand All @@ -656,6 +672,15 @@ ELSE(ENABLE_ZSTD)
ENDIF(ENABLE_ZSTD)
IF(ZSTD_FOUND)
SET(HAVE_ZSTD_H 1)
SET(HAVE_LIBZSTD 1)
SET(HAVE_LIBZSTD_COMPRESSOR 1)
IF(TARGET zstd::libzstd_shared)
LIST(APPEND ADDITIONAL_LIBS zstd::libzstd_shared)
ELSE()
LIST(APPEND ADDITIONAL_LIBS zstd::libzstd_static)
ENDIF(TARGET zstd::libzstd_shared)
LIST(APPEND LIBARCHIVE_REQUIRES_PRIVATE libzstd)
elseif(0)
INCLUDE_DIRECTORIES(${ZSTD_INCLUDE_DIR})
LIST(APPEND ADDITIONAL_LIBS ${ZSTD_LIBRARY})
CMAKE_PUSH_CHECK_STATE()
Expand Down Expand Up @@ -765,6 +790,7 @@ IF(ENABLE_CNG)
LA_CHECK_INCLUDE_FILE("bcrypt.h" HAVE_BCRYPT_H)
IF(HAVE_BCRYPT_H)
LIST(APPEND ADDITIONAL_LIBS "bcrypt")
LIST(APPEND LIBARCHIVE_LIBS_PRIVATE bcrypt)
ENDIF(HAVE_BCRYPT_H)
ELSE(ENABLE_CNG)
UNSET(HAVE_BCRYPT_H CACHE)
Expand Down Expand Up @@ -796,6 +822,7 @@ IF(ENABLE_MBEDTLS)
IF(MBEDTLS_FOUND)
SET(HAVE_LIBMBEDCRYPTO 1)
LIST(APPEND ADDITIONAL_LIBS ${MBEDCRYPTO_LIBRARY})
LIST(APPEND LIBARCHIVE_LIBS_PRIVATE ${MBEDCRYPTO_LIBRARY})
INCLUDE_DIRECTORIES(${MBEDTLS_INCLUDE_DIRS})

LIST(APPEND CMAKE_REQUIRED_INCLUDES ${MBEDTLS_INCLUDE_DIRS})
Expand All @@ -816,6 +843,7 @@ IF(ENABLE_NETTLE)
IF(NETTLE_FOUND)
SET(HAVE_LIBNETTLE 1)
LIST(APPEND ADDITIONAL_LIBS ${NETTLE_LIBRARIES})
LIST(APPEND LIBARCHIVE_REQUIRES_PRIVATE nettle)
INCLUDE_DIRECTORIES(${NETTLE_INCLUDE_DIR})

LIST(APPEND CMAKE_REQUIRED_INCLUDES ${NETTLE_INCLUDE_DIR})
Expand All @@ -839,8 +867,8 @@ IF(ENABLE_OPENSSL AND NOT CMAKE_SYSTEM_NAME MATCHES "Darwin")
FIND_PACKAGE(OpenSSL)
IF(OPENSSL_FOUND)
SET(HAVE_LIBCRYPTO 1)
INCLUDE_DIRECTORIES(${OPENSSL_INCLUDE_DIR})
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to get rid of this?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For building libarchive, OpenSSL::Crypto' will make CMake pass include dirs and link libs to the targets that link to it. So there is no reason to use both variables and targets. For exported CMake config, using targets implies using find_dependency` (for static linkage).

LIST(APPEND ADDITIONAL_LIBS ${OPENSSL_CRYPTO_LIBRARY})
LIST(APPEND ADDITIONAL_LIBS OpenSSL::Crypto)
LIST(APPEND LIBARCHIVE_REQUIRES_PRIVATE libcrypto)
SET(CMAKE_REQUIRED_LIBRARIES ${OPENSSL_CRYPTO_LIBRARY})
SET(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIR})
LA_CHECK_INCLUDE_FILE("openssl/evp.h" HAVE_OPENSSL_EVP_H)
Expand All @@ -858,6 +886,7 @@ IF(NOT OPENSSL_FOUND)
SET(CMAKE_REQUIRED_LIBRARIES "md")
FIND_LIBRARY(LIBMD_LIBRARY NAMES md)
LIST(APPEND ADDITIONAL_LIBS ${LIBMD_LIBRARY})
LIST(APPEND LIBARCHIVE_LIBS_PRIVATE ${LIBMD_LIBRARY})
CMAKE_POP_CHECK_STATE() # Restore the state of the variables
ENDIF(LIBMD_FOUND)
ENDIF(NOT OPENSSL_FOUND)
Expand Down Expand Up @@ -963,7 +992,8 @@ main(int argc, char **argv)
IF ("${IMPLEMENTATION}" MATCHES "^OPENSSL$" AND OPENSSL_FOUND)
INCLUDE_DIRECTORIES(${OPENSSL_INCLUDE_DIR})
LIST(APPEND ADDITIONAL_LIBS ${OPENSSL_LIBRARIES})
LIST(REMOVE_DUPLICATES ADDITIONAL_LIBS)
#LIST(REMOVE_DUPLICATES ADDITIONAL_LIBS)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to get rid of this?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

REMOVE_DUPLICATES has the potential to break static linking with "traditional linkers". Independent libs must come at the end of the list, but that command leaves only the first occurence.
In addition, it will break multi-config keywords (optimized, debug).

LIST(APPEND LIBARCHIVE_REQUIRES_PRIVATE libssl)
ENDIF ("${IMPLEMENTATION}" MATCHES "^OPENSSL$" AND OPENSSL_FOUND)
ENDIF (ARCHIVE_CRYPTO_${ALGORITHM}_${IMPLEMENTATION})
ENDIF(NOT ARCHIVE_CRYPTO_${ALGORITHM})
Expand Down Expand Up @@ -1137,6 +1167,7 @@ IF(ENABLE_ICONV)
CHECK_ICONV("libiconv" "")
IF (HAVE_ICONV)
LIST(APPEND ADDITIONAL_LIBS ${LIBICONV_PATH})
LIST(APPEND LIBARCHIVE_LIBS_PRIVATE ${LIBICONV_PATH})
ENDIF(HAVE_ICONV)
ENDIF(NOT HAVE_ICONV AND LIBICONV_PATH)
ENDIF(ICONV_INCLUDE_DIR)
Expand Down Expand Up @@ -1170,6 +1201,7 @@ IF(ENABLE_ICONV)
ENDIF(WIN32 AND NOT CYGWIN)
IF(HAVE_LOCALE_CHARSET)
LIST(APPEND ADDITIONAL_LIBS ${LIBCHARSET_PATH})
LIST(APPEND LIBARCHIVE_LIBS_PRIVATE ${LIBCHARSET_PATH})
ENDIF(HAVE_LOCALE_CHARSET)
ENDIF(LIBCHARSET_PATH)
ENDIF(LIBICONV_PATH)
Expand Down Expand Up @@ -1203,6 +1235,7 @@ IF(LIBXML2_FOUND)
CMAKE_PUSH_CHECK_STATE() # Save the state of the variables
INCLUDE_DIRECTORIES(${LIBXML2_INCLUDE_DIR})
LIST(APPEND ADDITIONAL_LIBS ${LIBXML2_LIBRARIES})
LIST(APPEND LIBARCHIVE_REQUIRES_PRIVATE libxml-2.0)
SET(HAVE_LIBXML2 1)
# libxml2's include files use iconv.h
SET(CMAKE_REQUIRED_INCLUDES ${ICONV_INCLUDE_DIR} ${LIBXML2_INCLUDE_DIR})
Expand Down Expand Up @@ -1232,6 +1265,7 @@ ELSE(LIBXML2_FOUND)
CMAKE_PUSH_CHECK_STATE() # Save the state of the variables
INCLUDE_DIRECTORIES(${EXPAT_INCLUDE_DIR})
LIST(APPEND ADDITIONAL_LIBS ${EXPAT_LIBRARIES})
LIST(APPEND LIBARCHIVE_REQUIRES_PRIVATE expat)
SET(HAVE_LIBEXPAT 1)
LA_CHECK_INCLUDE_FILE("expat.h" HAVE_EXPAT_H)
CMAKE_POP_CHECK_STATE() # Restore the state of the variables
Expand Down Expand Up @@ -1262,6 +1296,7 @@ IF(POSIX_REGEX_LIB MATCHES "^(AUTO|LIBC|LIBREGEX)$")
CHECK_FUNCTION_EXISTS_GLIBC(regcomp HAVE_REGCOMP_LIBREGEX)
IF(HAVE_REGCOMP_LIBREGEX)
LIST(APPEND ADDITIONAL_LIBS ${REGEX_LIBRARY})
LIST(APPEND LIBARCHIVE_LIBS_PRIVATE ${REGEX_LIBRARY})
#
# If regex.h is not found, retry looking for regex.h at
# REGEX_INCLUDE_DIR
Expand Down Expand Up @@ -1311,6 +1346,7 @@ IF(NOT FOUND_POSIX_REGEX_LIB AND POSIX_REGEX_LIB MATCHES "^(AUTO|LIBPCREPOSIX)$"
IF(PCREPOSIX_FOUND)
INCLUDE_DIRECTORIES(${PCRE_INCLUDE_DIR})
LIST(APPEND ADDITIONAL_LIBS ${PCREPOSIX_LIBRARIES})
LIST(APPEND LIBARCHIVE_LIBS_PRIVATE ${PCREPOSIX_LIBRARIES})
# Test if a macro is needed for the library.
TRY_MACRO_FOR_LIBRARY(
"${PCRE_INCLUDE_DIR}" "${PCREPOSIX_LIBRARIES}"
Expand All @@ -1322,6 +1358,7 @@ IF(NOT FOUND_POSIX_REGEX_LIB AND POSIX_REGEX_LIB MATCHES "^(AUTO|LIBPCREPOSIX)$"
ELSEIF(NOT WITHOUT_PCRE_STATIC AND NOT PCRE_STATIC AND PCRE_FOUND)
# Determine if pcre static libraries are to be used.
LIST(APPEND ADDITIONAL_LIBS ${PCRE_LIBRARIES})
LIST(APPEND LIBARCHIVE_LIBS_PRIVATE ${PCRE_LIBRARIES})
SET(TMP_LIBRARIES ${PCREPOSIX_LIBRARIES} ${PCRE_LIBRARIES})
MESSAGE(STATUS "trying again with -lpcre included")
TRY_MACRO_FOR_LIBRARY(
Expand All @@ -1337,6 +1374,7 @@ IF(NOT FOUND_POSIX_REGEX_LIB AND POSIX_REGEX_LIB MATCHES "^(AUTO|LIBPCREPOSIX)$"
# ___chkstk_ms.
MESSAGE(STATUS "Visual Studio build detected, trying again with -lgcc included")
LIST(APPEND ADDITIONAL_LIBS ${LIBGCC_LIBRARIES})
LIST(APPEND LIBARCHIVE_LIBS_PRIVATE ${LIBGCC_LIBRARIES})
SET(TMP_LIBRARIES ${PCREPOSIX_LIBRARIES} ${PCRE_LIBRARIES} ${LIBGCC_LIBRARIES})
TRY_MACRO_FOR_LIBRARY(
"${PCRE_INCLUDE_DIR}" "${TMP_LIBRARIES}"
Expand Down Expand Up @@ -1908,6 +1946,7 @@ IF(ENABLE_ACL)
SET(CMAKE_REQUIRED_LIBRARIES "acl")
FIND_LIBRARY(ACL_LIBRARY NAMES acl)
LIST(APPEND ADDITIONAL_LIBS ${ACL_LIBRARY})
LIST(APPEND LIBARCHIVE_LIBS_PRIVATE ${ACL_LIBRARY})
ENDIF(HAVE_LIBACL)

CHECK_TYPE_EXISTS(acl_t "sys/types.h;sys/acl.h" HAVE_ACL_T)
Expand Down Expand Up @@ -2047,6 +2086,7 @@ int main(void) { return ACL_SYNCHRONIZE; }" HAVE_DECL_ACL_SYNCHRONIZE)
SET(CMAKE_REQUIRED_LIBRARIES "richacl")
FIND_LIBRARY(RICHACL_LIBRARY NAMES richacl)
LIST(APPEND ADDITIONAL_LIBS ${RICHACL_LIBRARY})
LIST(APPEND LIBARCHIVE_LIBS_PRIVATE ${RICHACL_LIBRARY})
ENDIF(HAVE_LIBRICHACL)

CHECK_STRUCT_HAS_MEMBER("struct richace" e_type "sys/richacl.h"
Expand Down
7 changes: 3 additions & 4 deletions build/cmake/CreatePkgConfigFile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,16 @@ SET(libdir \${exec_prefix}/lib)
SET(includedir \${prefix}/include)
# Now, this is not particularly pretty, nor is it terribly accurate...
# Loop over all our additional libs
FOREACH(mylib ${ADDITIONAL_LIBS})
FOREACH(mylib ${LIBARCHIVE_LIBS_PRIVATE})
# Extract the filename from the absolute path
GET_FILENAME_COMPONENT(mylib_name ${mylib} NAME_WE)
# Strip the lib prefix
STRING(REGEX REPLACE "^lib" "" mylib_name ${mylib_name})
# Append it to our LIBS string
SET(LIBS "${LIBS} -l${mylib_name}")
ENDFOREACH()
# libxml2 is easier, since it's already using pkg-config
FOREACH(mylib ${PC_LIBXML_STATIC_LDFLAGS})
SET(LIBS "${LIBS} ${mylib}")
FOREACH(required LIBARCHIVE_REQUIRES_PRIVATE)
SET(LIBSREQUIRED "${LIBSREQUIRED} ${required}")
ENDFOREACH()
# FIXME: The order of the libraries doesn't take dependencies into account,
# thus there's a good chance it'll make some binutils versions unhappy...
Expand Down