FindCURL: Add CURL_VERSION variable to match upstream cmake package

`find_package(CURL CONFIG)` provides `CURL_VERSION` from the upstream
cmake package version file.

Upstream curl commit `699ac9430c` (cmake: publish/check supported
protocols/features via `CURLConfig.cmake`, 2024-12-29) extends the
upstream cmake package to provide our old `CURL_VERSION_STRING`.
Provide both names from CMake's own module to aid transition.

Fixes: #26634
This commit is contained in:
Brad King 2025-01-28 09:45:18 -05:00
parent aeff709a27
commit d039da1c24
3 changed files with 21 additions and 3 deletions

View File

@ -0,0 +1,5 @@
FindCURL-version-var
--------------------
* The :module:`FindCURL` module now provides a ``CURL_VERSION`` result
variable to match upstream cURL's CMake package.

View File

@ -40,8 +40,15 @@ This module defines the following variables:
``CURL_LIBRARIES``
List of libraries when using ``curl``.
``CURL_VERSION``
.. versionadded:: 4.0
The version of ``curl`` found.
This supersedes ``CURL_VERSION_STRING``.
``CURL_VERSION_STRING``
The version of ``curl`` found.
Superseded by ``CURL_VERSION``.
.. versionadded:: 3.13
Debug and Release variants are found separately.
@ -147,7 +154,8 @@ if(CURL_INCLUDE_DIR)
if(EXISTS "${CURL_INCLUDE_DIR}/curl/${_curl_version_header}")
file(STRINGS "${CURL_INCLUDE_DIR}/curl/${_curl_version_header}" curl_version_str REGEX "^#define[\t ]+LIBCURL_VERSION[\t ]+\".*\"")
string(REGEX REPLACE "^#define[\t ]+LIBCURL_VERSION[\t ]+\"([^\"]*)\".*" "\\1" CURL_VERSION_STRING "${curl_version_str}")
string(REGEX REPLACE "^#define[\t ]+LIBCURL_VERSION[\t ]+\"([^\"]*)\".*" "\\1" CURL_VERSION "${curl_version_str}")
set(CURL_VERSION_STRING "${CURL_VERSION}")
unset(curl_version_str)
break()
endif()
@ -202,7 +210,7 @@ endif()
find_package_handle_standard_args(CURL
REQUIRED_VARS CURL_LIBRARY CURL_INCLUDE_DIR
VERSION_VAR CURL_VERSION_STRING
VERSION_VAR CURL_VERSION
HANDLE_COMPONENTS)
if(CURL_FOUND)

View File

@ -4,7 +4,12 @@ include(CTest)
find_package(CURL REQUIRED COMPONENTS HTTP)
add_definitions(-DCMAKE_EXPECTED_CURL_VERSION="${CURL_VERSION_STRING}")
if(NOT CURL_VERSION MATCHES "^[0-9]+\\.[0-9]+(\\.|$)")
message(FATAL_ERROR "CURL_VERSION not set")
endif()
if(NOT CURL_VERSION_STRING MATCHES "^[0-9]+\\.[0-9]+(\\.|$)")
message(FATAL_ERROR "CURL_VERSION_STRING not set")
endif()
add_executable(test_tgt main.c)
target_link_libraries(test_tgt CURL::libcurl)