cmake: use modern alternatives for get_filename_component()

- use `cmake_path()` to query filenames, with CMake 3.20 or upper.
  https://cmake.org/cmake/help/v4.1/command/cmake_path.html#query

- use `cmake_host_system_information()` to query the registry,
  with CMake 3.24 or upper.
  https://cmake.org/cmake/help/v4.1/command/cmake_host_system_information.html#query-windows-registry
  Replacing the undocumented method.

- also quote the value passed to `get_filename_component()` where
  missing. (Could not cause an actual issue as used in the code.)

Closes #18688
This commit is contained in:
Viktor Szakats 2025-09-22 18:02:49 +02:00
parent d75785c7de
commit f833d5d1fb
No known key found for this signature in database
GPG Key ID: B5ABD165E2AEF201
3 changed files with 24 additions and 6 deletions

View File

@ -230,7 +230,11 @@ if(NOT _gss_FOUND) # Not found by pkg-config. Let us take more traditional appr
if(GSS_FLAVOUR)
set(_gss_libdir_suffixes "")
set(_gss_libdir_hints ${_gss_root_hints})
get_filename_component(_gss_calculated_potential_root "${_gss_INCLUDE_DIRS}" DIRECTORY)
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.20)
cmake_path(GET _gss_INCLUDE_DIRS PARENT_PATH _gss_calculated_potential_root)
else()
get_filename_component(_gss_calculated_potential_root "${_gss_INCLUDE_DIRS}" DIRECTORY)
endif()
list(APPEND _gss_libdir_hints ${_gss_calculated_potential_root})
if(WIN32)
@ -323,8 +327,13 @@ if(GSS_FLAVOUR)
set(GSS_VERSION "Heimdal Unknown")
endif()
elseif(NOT GSS_VERSION AND GSS_FLAVOUR STREQUAL "MIT")
get_filename_component(_mit_version "[HKEY_LOCAL_MACHINE\\SOFTWARE\\MIT\\Kerberos\\SDK\\CurrentVersion;VersionString]" NAME
CACHE)
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.24)
cmake_host_system_information(RESULT _mit_version QUERY WINDOWS_REGISTRY
"HKLM/SOFTWARE/MIT/Kerberos/SDK/CurrentVersion" VALUE "VersionString")
else()
get_filename_component(_mit_version
"[HKEY_LOCAL_MACHINE\\SOFTWARE\\MIT\\Kerberos\\SDK\\CurrentVersion;VersionString]" NAME CACHE)
endif()
if(WIN32 AND _mit_version)
set(GSS_VERSION "${_mit_version}")
else()

View File

@ -104,7 +104,11 @@ else()
endif()
if(_ngtcp2_crypto_backend)
get_filename_component(_ngtcp2_library_dir "${NGTCP2_LIBRARY}" DIRECTORY)
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.20)
cmake_path(GET NGTCP2_LIBRARY PARENT_PATH _ngtcp2_library_dir)
else()
get_filename_component(_ngtcp2_library_dir "${NGTCP2_LIBRARY}" DIRECTORY)
endif()
find_library(${_crypto_library_upper}_LIBRARY NAMES ${_crypto_library_lower} HINTS ${_ngtcp2_library_dir})
if(${_crypto_library_upper}_LIBRARY)

View File

@ -2339,8 +2339,13 @@ if(NOT CURL_DISABLE_INSTALL)
elseif(_lib MATCHES "/")
# This gets a bit more complex, because we want to specify the
# directory separately, and only once per directory
get_filename_component(_libdir ${_lib} DIRECTORY)
get_filename_component(_libname ${_lib} NAME_WE)
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.20)
cmake_path(GET _lib PARENT_PATH _libdir)
cmake_path(GET _lib STEM _libname)
else()
get_filename_component(_libdir "${_lib}" DIRECTORY)
get_filename_component(_libname "${_lib}" NAME_WE)
endif()
if(_libname MATCHES "^lib")
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.20)
cmake_path(SET _libdir NORMALIZE "${_libdir}")