cmake: resolve imported targets recursively when generating libcurl.pc#20840
Closed
vszakats wants to merge 1 commit intocurl:masterfrom
Closed
cmake: resolve imported targets recursively when generating libcurl.pc#20840vszakats wants to merge 1 commit intocurl:masterfrom
libcurl.pc#20840vszakats wants to merge 1 commit intocurl:masterfrom
Conversation
To allow simplifying the binutils ld hack, by chaining the original imported target to curl's local duplicate target. Also to allow linking to dependencies' native imported targes via their CMake Configs, which may similarly be chained by default. Fixing (seen on Linux with simplified binutils hack via curl#20839): ``` Requires: Requires.private: libzstd openssl zlib Libs: -L${libdir} -lcurl -Libs.private: -lcrypto -lssl -lz -lzstd +Libs.private: -lOpenSSL::Crypto -lZLIB::ZLIB -lcrypto -lssl -lz -lzstd Cflags: -I${includedir} Cflags.private: -DCURL_STATICLIB Error: Process completed with exit code ``` Ref: https://github.com/curl/curl/actions/runs/22768301699/job/66041980258?pr=20839 Cherry-picked from curl#20814 Cherry-picked from curl#20839
libcurl.pc
This was referenced Mar 6, 2026
libcurl.pclibcurl.pc
vszakats
added a commit
that referenced
this pull request
Mar 16, 2026
Instead hook up the upstream target name as-is to the local wrapper target. To: - make the hack work regardless of how the upstream target was created. - make it work the same way in `curl-config.cmake`. Before this patch it had no guard for `IMPORTED` targets even though `find_dependencies()` is not guaranteed to create the target expected if it already existed and was potentially created differently. Depends-on: #20840 Follow-up to 4f1646e #20486 #20419 Closes #20839
vszakats
added a commit
that referenced
this pull request
Mar 21, 2026
After limiting `find_package()`/`find_dependency()` calls to curl local Find modules via the `MODULES` keyword, it became possible to detect dependencies via CMake Configs from within those local Find modules, by calling `find_package()` again with the `CONFIG` keyword. This patch implements this. Then maps detection results to the result variables and curl-specific imported targets the rest of the build expects. Also honor recently introduced `*_USE_STATIC_LIBS` (experimental) flags to map to the static target when requested. This adds CMake Configs as an alternative to the existing `pkg-config` and `find_path()`/`find_library()` auto-detection methods. Enabled by default for MSVC, outside vcpkg and when not cross-building. To enable for other cases, or override the default, you can use `-DCURL_USE_CMAKECONFIG=ON` or `OFF`. When enabled, Config detection happens after `pkg-config` and before `find_path()`/`find_library()`. Using CMake's built-in options, you may also manually point to the absolute directory holding Config files: `Libssh2_DIR`, `MbedTLS_DIR`, `NGHTTP2_DIR`, `NGHTTP3_DIR`, `NGTCP2_DIR` v1.19.0+ (with non-fork OpenSSL only), `Zstd_DIR` v1.4.5+ E.g. `-DMbedTLS_DIR=/path/to/mbedtls/lib/cmake/MbedTLS` These dependencies typically need to be built with CMake to support this. Tagged as experimental. Refs: #20013 #19156 #19117 #20784 (comment) Depends-on: fad1eba #20840 Follow-up to 91e06fd #20784 Follow-up to 26c39d8 #20015 Closes #20814
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
To allow simplifying the binutils ld hack, by chaining the original
imported target to curl's local duplicate target. Also to allow linking
to dependencies' native imported targets via their CMake Configs, which
will always be hooked up to a
CURL::interface, and may also bechained upstream.
Fixing (seen on Linux with simplified binutils hack via #20839):
Ref: https://github.com/curl/curl/actions/runs/22768301699/job/66041980258?pr=20839
Note this makes it possible to run into an infinite loop because CMake
allows cyclic dependencies. It isn't added by curl's CMake script nor by
any dependencies as defined by default, but may happen in theory with
custom-created targets. In such case CMake automatically stops with
an error at 1000 iterations. I find it overkill to add custom protection
for it.
Cherry-picked from #20814
Cherry-picked from #20839