cmake: fix building with CMAKE_FIND_PACKAGE_PREFER_CONFIG=ON#20784
cmake: fix building with CMAKE_FIND_PACKAGE_PREFER_CONFIG=ON#20784vszakats wants to merge 23 commits into
CMAKE_FIND_PACKAGE_PREFER_CONFIG=ON#20784Conversation
-DCMAKE_FIND_PACKAGE_PREFER_CONFIG=ON
-DCMAKE_FIND_PACKAGE_PREFER_CONFIG=ONCMAKE_FIND_PACKAGE_PREFER_CONFIG=ON
|
This may also be a way to add support to curl Find modules for using cmake CONFIGs |
- add support for separate provider / consumer cmake options in `find_package` tests. To help test more integration scenarios. Refs: #20784 #20729 #20764 - dump generated curl config files in `find_package` tests. (cmake CONFIG source, `libcurl.pc`, `curl-config`. - test.sh: use `sha256sum` (was: `openssl`). Closes #20773
5213f78 to
d3fcf41
Compare
|
@aisle-analyzer augment review |
🔒 Aisle Security Analysis✅ We scanned this PR and did not find any security vulnerabilities. Aisle supplements but does not replace security review. Analyzed PR: #20784 at commit Last updated on: 2026-03-02T17:37:54Z |
There was a problem hiding this comment.
Pull request overview
This PR adjusts curl’s CMake dependency discovery to behave correctly when users enable CMAKE_FIND_PACKAGE_PREFER_CONFIG=ON, ensuring curl’s build and exported CURLConfig.cmake consistently use curl’s bundled Find*.cmake modules (so expected CURL::<dep> targets are created).
Changes:
- Force
find_package(... MODULE ...)for dependencies that have curl-providedFind<Dep>.cmakemodules (both in-tree build and exported config consumption). - Update the exported
CMake/curl-config.in.cmaketo usefind_dependency(... MODULE)for these dependencies while preserving CONFIG-based behavior for OpenSSL and ZLIB. - Add a Windows distcheck job that builds and consumes curl with
CMAKE_FIND_PACKAGE_PREFER_CONFIG=ON.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| CMakeLists.txt | Forces MODULE-mode package discovery for curl-bundled Find modules so CURL::<dep> targets are reliably defined. |
| CMake/curl-config.in.cmake | Forces MODULE-mode dependency discovery when consuming curl via find_package(CURL), avoiding CONFIG packages that don’t create CURL::<dep> targets. |
| CMake/Macros.cmake | Updates curl_dependency_option() to prefer MODULE finds for curl-bundled deps, with an explicit exception for ZLIB. |
| .github/workflows/distcheck.yml | Adds a Windows integration test that exercises build+consume under CMAKE_FIND_PACKAGE_PREFER_CONFIG=ON. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
🤖 Augment PR SummarySummary: This PR hardens curl’s CMake build/packaging against builds where Changes:
Technical Notes: This keeps curl’s custom 🤖 Was this summary useful? React with 👍 or 👎 |
CMAKE_FIND_PACKAGE_PREFER_CONFIG=ONCMAKE_FIND_PACKAGE_PREFER_CONFIG=ON
CMAKE_FIND_PACKAGE_PREFER_CONFIG=ONCMAKE_FIND_PACKAGE_PREFER_CONFIG=ON
make sure to omit for ZLIB (no visible fallout in CI)
When using -DCMAKE_FIND_PACKAGE_PREFER_CONFIG=ON, the find_dependency() and find_package() macros give preference to CMake config files (e.g. `<prefix>/lib/cmake/libssh2/libssh2-config.cmake`) if found, over using curl's `Find<Package>.cmake` file and results in different target names such as Libssh2::libssh2 instead of CURL::libssh2. Beyond the target naming discrepency, this also relies heavily on correctness of those config files, which in my experience is a mixed bag. Using the MODULE parameter for `find_dependency()` and `find_package()` will force CMake to use the `Find<Package>.cmake` module instead of using the config file. Fixes 20729 Follow-up to 16f073e curl#16973
…en consumers" This reverts commit d1d4912.
…rt it when consumers"" This reverts commit d3fcf41.
…ert it when consumers"" This reverts commit caa8597.
This reverts commit 3c5c511. https://github.com/curl/curl/actions/runs/22584370194/job/65424999010?pr=20784 Not sure why it failed when setting the setting via CMakeLists.txt. Ah, it was on macOS.
This reverts commit bc1582e. This settings causes `find_package(OpenSSL)` to not find Homebrew's OpenSSL. Not sure why. Unrelated to this PR, just wanted to confirm. https://github.com/curl/curl/actions/runs/22584940990/job/65427083479?pr=20784
…to suppoert it when consumers""" This reverts commit b86535b.
This reverts commit 91603f8.
… to suppoert it when consumers""" This reverts commit b357bdf.
This reverts commit 52c3ecc.
- [ ] how to control priority? (honor CMAKE's PREFER_CONFIG option?) - [ ] switch default to OFF, initially. - [ ] make a list of deps that support this (and since which versions) - [ ] add for the rest - [ ] test locally? - [ ] test in CI? This may also be a way to add support to curl Find modules for using cmake Configs (in addition to existing `pkg-config` and raw/manual detection). Which in turn may help with static builds. When using MODULE, it's guaranteed to hit curl's Find module first without using Configs, then the Find module may possibly use a `find_package()` limited to Configs, effectively "chaining" them. Then the curl logic needs to create aliases to map the found targets to the `CURL::` namespaced ones, and possibly do other things to make those targets compatible with the rest of the build. I have made minimal tests, so it's mostly theory at this point. curl#20784 (comment) Refs: curl#20013 curl#19117 curl#19156
- [ ] how to control priority? (honor CMAKE's PREFER_CONFIG option?) - [ ] switch default to OFF, initially. - [ ] make a list of deps that support this (and since which versions) - [ ] add for the rest - [ ] test locally? - [ ] test in CI? This may also be a way to add support to curl Find modules for using cmake Configs (in addition to existing `pkg-config` and raw/manual detection). Which in turn may help with static builds. When using MODULE, it's guaranteed to hit curl's Find module first without using Configs, then the Find module may possibly use a `find_package()` limited to Configs, effectively "chaining" them. Then the curl logic needs to create aliases to map the found targets to the `CURL::` namespaced ones, and possibly do other things to make those targets compatible with the rest of the build. I have made minimal tests, so it's mostly theory at this point. curl#20784 (comment) Refs: curl#20013 curl#19117 curl#19156
- [ ] how to control priority? (honor CMAKE's PREFER_CONFIG option?) - [ ] switch default to OFF, initially. - [ ] make a list of deps that support this (and since which versions) - [ ] add for the rest - [ ] test locally? - [ ] test in CI? This may also be a way to add support to curl Find modules for using cmake Configs (in addition to existing `pkg-config` and raw/manual detection). Which in turn may help with static builds. When using MODULE, it's guaranteed to hit curl's Find module first without using Configs, then the Find module may possibly use a `find_package()` limited to Configs, effectively "chaining" them. Then the curl logic needs to create aliases to map the found targets to the `CURL::` namespaced ones, and possibly do other things to make those targets compatible with the rest of the build. I have made minimal tests, so it's mostly theory at this point. curl#20784 (comment) Refs: curl#20013 curl#19117 curl#19156
- [ ] how to control priority? (honor CMAKE's PREFER_CONFIG option?) - [ ] switch default to OFF, initially. - [ ] make a list of deps that support this (and since which versions) - [ ] add for the rest - [ ] test locally? - [ ] test in CI? This may also be a way to add support to curl Find modules for using cmake Configs (in addition to existing `pkg-config` and raw/manual detection). Which in turn may help with static builds. When using MODULE, it's guaranteed to hit curl's Find module first without using Configs, then the Find module may possibly use a `find_package()` limited to Configs, effectively "chaining" them. Then the curl logic needs to create aliases to map the found targets to the `CURL::` namespaced ones, and possibly do other things to make those targets compatible with the rest of the build. I have made minimal tests, so it's mostly theory at this point. curl#20784 (comment) Refs: curl#20013 curl#19117 curl#19156
- [ ] how to control priority? (honor CMAKE's PREFER_CONFIG option?) - [ ] switch default to OFF, initially. - [ ] make a list of deps that support this (and since which versions) - [ ] add for the rest - [ ] test locally? - [ ] test in CI? This may also be a way to add support to curl Find modules for using cmake Configs (in addition to existing `pkg-config` and raw/manual detection). Which in turn may help with static builds. When using MODULE, it's guaranteed to hit curl's Find module first without using Configs, then the Find module may possibly use a `find_package()` limited to Configs, effectively "chaining" them. Then the curl logic needs to create aliases to map the found targets to the `CURL::` namespaced ones, and possibly do other things to make those targets compatible with the rest of the build. I have made minimal tests, so it's mostly theory at this point. curl#20784 (comment) Refs: curl#20013 curl#19117 curl#19156
- [ ] how to control priority? (honor CMAKE's PREFER_CONFIG option?) - [ ] switch default to OFF, initially. - [ ] make a list of deps that support this (and since which versions) - [ ] add for the rest - [ ] test locally? - [ ] test in CI? This may also be a way to add support to curl Find modules for using cmake Configs (in addition to existing `pkg-config` and raw/manual detection). Which in turn may help with static builds. When using MODULE, it's guaranteed to hit curl's Find module first without using Configs, then the Find module may possibly use a `find_package()` limited to Configs, effectively "chaining" them. Then the curl logic needs to create aliases to map the found targets to the `CURL::` namespaced ones, and possibly do other things to make those targets compatible with the rest of the build. I have made minimal tests, so it's mostly theory at this point. curl#20784 (comment) Refs: curl#20013 curl#19117 curl#19156
- [ ] how to control priority? (honor CMAKE's PREFER_CONFIG option?) - [ ] switch default to OFF, initially. - [ ] make a list of deps that support this (and since which versions) - [ ] add for the rest - [ ] test locally? - [ ] test in CI? This may also be a way to add support to curl Find modules for using cmake Configs (in addition to existing `pkg-config` and raw/manual detection). Which in turn may help with static builds. When using MODULE, it's guaranteed to hit curl's Find module first without using Configs, then the Find module may possibly use a `find_package()` limited to Configs, effectively "chaining" them. Then the curl logic needs to create aliases to map the found targets to the `CURL::` namespaced ones, and possibly do other things to make those targets compatible with the rest of the build. I have made minimal tests, so it's mostly theory at this point. curl#20784 (comment) Refs: curl#20013 curl#19117 curl#19156
- [ ] how to control priority? (honor CMAKE's PREFER_CONFIG option?) - [ ] switch default to OFF, initially. - [ ] make a list of deps that support this (and since which versions) - [ ] add for the rest - [ ] test locally? - [ ] test in CI? This may also be a way to add support to curl Find modules for using cmake Configs (in addition to existing `pkg-config` and raw/manual detection). Which in turn may help with static builds. When using MODULE, it's guaranteed to hit curl's Find module first without using Configs, then the Find module may possibly use a `find_package()` limited to Configs, effectively "chaining" them. Then the curl logic needs to create aliases to map the found targets to the `CURL::` namespaced ones, and possibly do other things to make those targets compatible with the rest of the build. I have made minimal tests, so it's mostly theory at this point. curl#20784 (comment) Refs: curl#20013 curl#19117 curl#19156
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 CMake global custom option tells it to find dependencies as cmake
Configs first, and only then look for
Find*modules. This may resultin
find_package()succeeding, but without actually creatingCURL::*imported targets the curl build scripts are expecting.
For dependencies with curl-specific, local,
Find*modules, we alwayswant to use them, via the module detection method, and never a
Config-based detection. Ensure this by passing the
MODULEoption tofind_package()andfind_dependency()to make them useFind*modules unconditionally, making them work as expected with the
CMAKE_FIND_PACKAGE_PREFER_CONFIG=ONoption set.curl uses local Find modules for all dependencies except OpenSSL and
ZLIB. The latter two keep using either CMake's built-in Find modules or
Config method as before this patch.
Also:
apply the same change to
curl-config.cmake. To fix consuming curlwith this option set.
Authored-by: Valerie Snyder
Ref: cmake: fix downstream app build issue when curl dep library paths defined #20764
Follow-up to 16f073e cmake: define dependencies as
IMPORTEDinterface targets #16973GHA/distcheck: add a job testing both building and consuming curl with
this option set. (takes 15 seconds)
Use custom NGHTTP2 configuration for an extra twist (not required
to trigger this issue.)
Follow-up to fcde8d7 cmake: minor improvements to integration test framework #20773
Reported-by: Valerie Snyder
Fixes #20729
https://github.com/curl/curl/pull/20784/files?w=1
The CI confirms a number of fallout when this custom option is set:
https://github.com/curl/curl/actions/runs/22546213460 macOS
https://github.com/curl/curl/actions/runs/22546213435 Linux
https://github.com/curl/curl/actions/runs/22546213465 Windows