curl-curl/CMake
Viktor Szakats 91e06fde1b
cmake: fix building with CMAKE_FIND_PACKAGE_PREFER_CONFIG=ON
This CMake global custom option tells it to find dependencies as cmake
Configs first, and only then look for `Find*` modules. This may result
in `find_package()` succeeding, but without actually creating `CURL::*`
imported targets the curl build scripts are expecting.

For dependencies with curl-specific, local, `Find*` modules, we always
want to use them, via the module detection method, and never a
Config-based detection. Ensure this by passing the `MODULE` option to
`find_package()` and `find_dependency()` to make them use `Find*`
modules unconditionally, making them work as expected with the
`CMAKE_FIND_PACKAGE_PREFER_CONFIG=ON` option 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 curl
  with this option set.
  Authored-by: Valerie Snyder
  Ref: #20764
  Follow-up to 16f073ef49 #16973

- GHA/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 fcde8d7e37 #20773

Reported-by: Valerie Snyder
Fixes #20729

Closes #20784
2026-03-03 16:33:21 +01:00
..
cmake_uninstall.in.cmake cmake: match filename suffixes with file content 2025-12-20 11:34:27 +01:00
curl-config.in.cmake cmake: fix building with CMAKE_FIND_PACKAGE_PREFER_CONFIG=ON 2026-03-03 16:33:21 +01:00
CurlSymbolHiding.cmake build: merge TrackMemory (CURLDEBUG) into debug-enabled option 2026-01-19 18:43:17 +01:00
CurlTests.c tidy-up: miscellaneous 2026-02-25 14:44:56 +01:00
FindBrotli.cmake cmke: add *_USE_STATIC_LIBS options for 9 dependencies 2026-01-26 05:21:24 +01:00
FindCares.cmake cmke: add *_USE_STATIC_LIBS options for 9 dependencies 2026-01-26 05:21:24 +01:00
FindGnuTLS.cmake cmake: define dependencies as IMPORTED interface targets 2025-11-29 01:41:40 +01:00
FindGSS.cmake cmake/FindGSS: add backtick missing from comment 2026-01-27 15:08:33 +01:00
FindLDAP.cmake cmake: define dependencies as IMPORTED interface targets 2025-11-29 01:41:40 +01:00
FindLibbacktrace.cmake cmake: define dependencies as IMPORTED interface targets 2025-11-29 01:41:40 +01:00
FindLibgsasl.cmake cmake: define dependencies as IMPORTED interface targets 2025-11-29 01:41:40 +01:00
FindLibidn2.cmake cmake: define dependencies as IMPORTED interface targets 2025-11-29 01:41:40 +01:00
FindLibpsl.cmake cmake: define dependencies as IMPORTED interface targets 2025-11-29 01:41:40 +01:00
FindLibrtmp.cmake cmake: replace deprecated OPENSSL_FOUND with OpenSSL_FOUND 2025-12-17 17:56:33 +01:00
FindLibssh2.cmake cmke: add *_USE_STATIC_LIBS options for 9 dependencies 2026-01-26 05:21:24 +01:00
FindLibssh.cmake cmke: add *_USE_STATIC_LIBS options for 9 dependencies 2026-01-26 05:21:24 +01:00
FindLibuv.cmake cmake: define dependencies as IMPORTED interface targets 2025-11-29 01:41:40 +01:00
FindMbedTLS.cmake cmake/FindMbedTLS: add workaround for missing static MSVC mbedcrypto.lib 4.0.0 2026-02-19 12:38:49 +01:00
FindNettle.cmake cmake: define dependencies as IMPORTED interface targets 2025-11-29 01:41:40 +01:00
FindNGHTTP2.cmake cmke: add *_USE_STATIC_LIBS options for 9 dependencies 2026-01-26 05:21:24 +01:00
FindNGHTTP3.cmake cmke: add *_USE_STATIC_LIBS options for 9 dependencies 2026-01-26 05:21:24 +01:00
FindNGTCP2.cmake cmke: add *_USE_STATIC_LIBS options for 9 dependencies 2026-01-26 05:21:24 +01:00
FindQuiche.cmake cmake: define dependencies as IMPORTED interface targets 2025-11-29 01:41:40 +01:00
FindRustls.cmake cmake/FindRustls: merge two ifs 2025-12-18 15:16:33 +01:00
FindWolfSSL.cmake cmake: define dependencies as IMPORTED interface targets 2025-11-29 01:41:40 +01:00
FindZstd.cmake cmke: add *_USE_STATIC_LIBS options for 9 dependencies 2026-01-26 05:21:24 +01:00
Macros.cmake cmake: fix building with CMAKE_FIND_PACKAGE_PREFER_CONFIG=ON 2026-03-03 16:33:21 +01:00
OtherTests.cmake build: check MSG_NOSIGNAL directly, drop detection and interim macro 2026-02-11 14:51:08 +01:00
PickyWarnings.cmake cmake: stop disabling C4774 after replacing snprintf(), update comment (MSVC) 2026-03-03 00:46:41 +01:00
unix-cache.cmake build: check MSG_NOSIGNAL directly, drop detection and interim macro 2026-02-11 14:51:08 +01:00
Utilities.cmake cmake: define dependencies as IMPORTED interface targets 2025-11-29 01:41:40 +01:00
win32-cache.cmake build: drop unused snprintf() feature check on Windows 2026-03-02 22:40:29 +01:00