curl/CMake
Viktor Szakats 16f073ef49
cmake: define dependencies as IMPORTED interface targets
Rework the way curl's custom Find modules advertise their properties.

Before this patch, Find modules returned detected dependency properties
(header dirs, libs, libdirs, C flags, etc.) via global variables. curl's
main `CMakeLists.txt` copied their values into global lists, which it
later applied to targets. This solution worked internally, but it was
unsuited for the public, distributed `CURLConfig.cmake` and publishing
curl's Find modules with it, due to polluting the namespace of consumer
projects. It's also impractical to apply the many individual variables
to every targets depending on libcurl.

To allow using Find modules in consumer projects, this patch makes them
define as imported interface targets, named `CURL::<dependency>`. Then
store dependency information as target properties. It avoids namespace
pollution and makes the dependency information apply automatically
to all targets using `CURL::libcurl_static`.

Find modules continue to return `*_FOUND` and `*_VERSION` variables.

For dependencies detected via `pkg-config`, CMake 3.16+ is recommended.
Older CMake versions have a varying degree of support for
propagating/handling library directories. This may cause issues in envs
where dependencies reside in non-system locations and detected via
`pkg-config` (e.g. macOS + Homebrew). Use `CURL_USE_PKGCONFIG=OFF`
to fix these issues. Or upgrade to newer CMake, or link libcurl
dynamically.

Also:
- re-enable `pkg-config` for old cmake `find_library()` integration
  tests.
- make `curlinfo` build after these changes.
- distribute local Find modules.
- export the raw list of lib dependencies via `CURL_LIBRARIES_PRIVATE`.
- `CURLconfig.cmake`: use curl's Find modules to detect dependencies in
  the consumer env.
- add custom property to target property debug function.
- the curl build process no longer modifies `CMAKE_C_FLAGS`.
  Follow-up to e86542038d #17047

Ref: #14930
Ref: https://github.com/libssh2/libssh2/pull/1535
Ref: https://github.com/libssh2/libssh2/pull/1571
Ref: https://github.com/libssh2/libssh2/pull/1581
Ref: https://github.com/libssh2/libssh2/pull/1623

Closes #16973
2025-11-29 01:41:40 +01:00
..
cmake_uninstall.cmake.in cmake: replace exec_program() with execute_process() 2025-03-23 00:06:25 +01:00
CMakeConfigurableFile.in copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
curl-config.cmake.in cmake: define dependencies as IMPORTED interface targets 2025-11-29 01:41:40 +01:00
CurlSymbolHiding.cmake build: drop Windows CE / CeGCC support 2025-11-15 15:35:23 +01:00
CurlTests.c tidy-up: drop stray "unused" comments 2025-09-03 16:31:16 +02:00
FindBrotli.cmake cmake: define dependencies as IMPORTED interface targets 2025-11-29 01:41:40 +01:00
FindCares.cmake cmake: define dependencies as IMPORTED interface targets 2025-11-29 01:41:40 +01:00
FindGnuTLS.cmake cmake: define dependencies as IMPORTED interface targets 2025-11-29 01:41:40 +01:00
FindGSS.cmake cmake: define dependencies as IMPORTED interface targets 2025-11-29 01:41:40 +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: define dependencies as IMPORTED interface targets 2025-11-29 01:41:40 +01:00
FindLibssh.cmake cmake: define dependencies as IMPORTED interface targets 2025-11-29 01:41:40 +01:00
FindLibssh2.cmake cmake: define dependencies as IMPORTED interface targets 2025-11-29 01:41:40 +01:00
FindLibuv.cmake cmake: define dependencies as IMPORTED interface targets 2025-11-29 01:41:40 +01:00
FindMbedTLS.cmake cmake: define dependencies as IMPORTED interface targets 2025-11-29 01:41:40 +01:00
FindNettle.cmake cmake: define dependencies as IMPORTED interface targets 2025-11-29 01:41:40 +01:00
FindNGHTTP2.cmake cmake: define dependencies as IMPORTED interface targets 2025-11-29 01:41:40 +01:00
FindNGHTTP3.cmake cmake: define dependencies as IMPORTED interface targets 2025-11-29 01:41:40 +01:00
FindNGTCP2.cmake cmake: define dependencies as IMPORTED interface targets 2025-11-29 01:41:40 +01:00
FindQuiche.cmake cmake: define dependencies as IMPORTED interface targets 2025-11-29 01:41:40 +01:00
FindRustls.cmake cmake: define dependencies as IMPORTED interface targets 2025-11-29 01:41:40 +01:00
FindWolfSSL.cmake cmake: define dependencies as IMPORTED interface targets 2025-11-29 01:41:40 +01:00
FindZstd.cmake cmake: define dependencies as IMPORTED interface targets 2025-11-29 01:41:40 +01:00
Macros.cmake badwords: fix issues found in scripts and other files 2025-11-17 17:18:07 +01:00
OtherTests.cmake build: drop HAVE_SYS_SOCKET_H and HAVE_SYS_TIME_H macros 2025-06-15 18:44:39 +02:00
PickyWarnings.cmake build: exclude clang prereleases from compiler warning options 2025-11-17 13:43:50 +01:00
unix-cache.cmake cmake: fix Linux pre-fill HAVE_POSIX_STRERROR_R (when _CURL_PREFILL=ON) 2025-10-18 14:30:43 +02:00
Utilities.cmake cmake: define dependencies as IMPORTED interface targets 2025-11-29 01:41:40 +01:00
win32-cache.cmake build: drop support for VS2008 (Windows) 2025-11-15 15:56:19 +01:00