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

Fix #1446 #2253

wants to merge 2 commits into from

Conversation

Ericson2314
Copy link

@Ericson2314 Ericson2314 commented Jun 26, 2024

@Ericson2314 Ericson2314 changed the title Fix #1446 in CMake build Fix #1446 Jun 27, 2024
@kientzle
Copy link
Contributor

kientzle commented Jul 5, 2024

This looks interesting, but I'm not familiar enough with Pkgconfig to judge whether this is a good approach.

@dg0yt
Copy link

dg0yt commented Jul 5, 2024

You seem to have started from the outdated https://github.com/dg0yt/vcpkg/blob/issue-template/ports/libarchive/pkgconfig-modules.patch.
You should check the latest version of the patch,
https://github.com/microsoft/vcpkg/blob/master/ports/libarchive/fix-deps.patch
It has improvements with regard to library and pc module names. For example, the spelling is lower case bcrypt for mingw on linux.

Some pc files can be missing on windows if not using vcpkg.

@Ericson2314
Copy link
Author

Ericson2314 commented Jul 9, 2024

I split out the autoconf part in #2268 so they can be reviewed separately.

@dg0yt I thought I did work from the latest version? I skipped the other changes, such as more FIND_PACKAGE because I thought they would best be done in another PR. Those are perfectly good changes, but that fix other things than #1446. I would be happy to review porting the rest of them next.

@dg0yt
Copy link

dg0yt commented Jul 10, 2024

I thought I did work from the latest version?

I don't know. I know that the reference you made points to an unrelated and old branch. And my comment even highlighted one of the issues of the old branch.

@Ericson2314
Copy link
Author

Sorry, I failed to find the upper-case Bcrypt before, but I see it now.

@Ericson2314
Copy link
Author

Ericson2314 commented Jul 10, 2024

@dg0yt OK I put most of the things from https://github.com/microsoft/vcpkg/blob/master/ports/libarchive/fix-deps.patch in a second commit, so we can review carefully what goes where.

See my comments below on things differing between https://github.com/microsoft/vcpkg/blob/master/ports/libarchive/fix-deps.patch and what I got that are worthy of further attention.

Comment on lines 526 to 532
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})
INCLUDE_DIRECTORIES(${LIBLZMA_INCLUDE_DIRS})
LIST(APPEND ADDITIONAL_LIBS ${LIBLZMA_LIBRARIES})
Copy link
Author

@Ericson2314 Ericson2314 Jul 10, 2024

Choose a reason for hiding this comment

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

What's the relationship between these two ADDITIONAL_LIBS? @dg0yt

Copy link

Choose a reason for hiding this comment

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

The relationship is that vcpkg never uses the second ADDITIONAL_LIBS. You omitted the third inserted line (which doesn't make sense here).

+elseif(0)

With this trick, the vcpkg patch is intentionally kept short.

For upstreaming the change, you wouldn't insert the code at the beginning but indeed update the code around the original ADDITIONAL_LIBS line.

@@ -628,13 +631,16 @@ 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?

Comment on lines 636 to 637
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)
CMAKE_POP_CHECK_STATE() # Restore the state of the variables
INCLUDE_DIRECTORIES(${LZ4_INCLUDE_DIR})
LIST(APPEND ADDITIONAL_LIBS ${LZ4_LIBRARY})
LIST(APPEND LIBARCHIVE_REQUIRES_PRIVATE liblz4)
Copy link
Author

Choose a reason for hiding this comment

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

Does no pkg-config in the FIND_PACKAGE not found case make sense?

Comment on lines 682 to 669
LIST(APPEND LIBARCHIVE_REQUIRES_PRIVATE libzstd)
elseif(0)
INCLUDE_DIRECTORIES(${ZSTD_INCLUDE_DIR})
LIST(APPEND ADDITIONAL_LIBS ${ZSTD_LIBRARY})
LIST(APPEND LIBARCHIVE_REQUIRES_PRIVATE libzstd)
Copy link
Author

Choose a reason for hiding this comment

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

Does no pkg-config in the FIND_PACKAGE not found case make sense?

@@ -977,7 +992,7 @@ 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).

@@ -851,8 +867,7 @@ 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).

Copy link

@dg0yt dg0yt left a comment

Choose a reason for hiding this comment

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

You cannot copy the vcpkg patch literally. It is for a certain controlled environment.
You really have to check package by package. And the libarchive must check how modern the systems are required to be when relying on system packages.

Comment on lines +654 to +655
FIND_PACKAGE(ZSTD NAMES zstd CONFIG REQUIRED)
elseif(0)
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.

@@ -851,8 +867,7 @@ 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

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).

@@ -977,7 +992,7 @@ 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

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).

@Ericson2314 Ericson2314 marked this pull request as draft July 11, 2024 02:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pkg-config file missing Requires.private, which breaks static linking
3 participants