1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-15 12:16:40 +08:00

file(DOWNLOAD): Fix User-Agent to use run-time curl version

If CMake is linked to a system-provided curl shared library, the version
at run-time may not match the `LIBCURL_VERSION` at build time.  Look up
the run-time curl version to populate the User-Agent string.

This is particularly important since commit d3cbee99e3 (macOS: Prefer
building with system-provided curl, 2024-05-09, v3.30.0-rc1~130^2~1)
switched to building our official binaries on macOS against the system
provided curl shared library.

Fixes: #26209
This commit is contained in:
Brad King
2024-08-13 14:02:07 -04:00
parent d88682dff6
commit 1a74f95656

View File

@@ -2131,7 +2131,10 @@ bool HandleDownloadCommand(std::vector<std::string> const& args,
res = ::curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1);
check_curl_result(res, "DOWNLOAD cannot set http failure option: ");
res = ::curl_easy_setopt(curl, CURLOPT_USERAGENT, "curl/" LIBCURL_VERSION);
curl_version_info_data* cv = curl_version_info(CURLVERSION_FIRST);
res = ::curl_easy_setopt(
curl, CURLOPT_USERAGENT,
cmStrCat("curl/", cv ? cv->version : LIBCURL_VERSION).c_str());
check_curl_result(res, "DOWNLOAD cannot set user agent option: ");
res = ::curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, cmWriteToFileCallback);