From db39c668a8e33e064b9eb20892cd027f46302f77 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Wed, 14 Aug 2024 03:09:08 +0200 Subject: [PATCH] cmake: sync up result variable names in Find modules - bearssl, c-ares, gss, libpsl, libssh2, mbedtls: Before this patch these Find modules returned results via `_INCLUDE_DIR` and `_LIBRARY`. This patch makes them return `_INCLUDE_DIRS` (note the `S`) and `_LIBRARIES` like other modules already did. - bearssl, mbedtls: Before this patch these Find modules allowed custom configuration via `_INCLUDE_DIRS` (note the `S`). This patch makes them accept `_INCLUDE_DIR`, like the rest of the modules did. Deprecate the old variables, but keep accepting them for compatibility. - bearssl: add missing `mark_as_advanced()` call. Closes #14542 --- CMake/FindBearSSL.cmake | 15 +++++++++++++-- CMake/FindCARES.cmake | 11 ++++++++--- CMake/FindGSS.cmake | 8 ++++---- CMake/FindLibPSL.cmake | 13 +++++++++---- CMake/FindLibSSH2.cmake | 13 +++++++++---- CMake/FindMbedTLS.cmake | 19 ++++++++++++++----- CMakeLists.txt | 20 ++++++++++---------- lib/CMakeLists.txt | 2 +- tests/libtest/CMakeLists.txt | 2 +- tests/server/CMakeLists.txt | 2 +- 10 files changed, 70 insertions(+), 35 deletions(-) diff --git a/CMake/FindBearSSL.cmake b/CMake/FindBearSSL.cmake index fe77fddb2f..1d8fbce101 100644 --- a/CMake/FindBearSSL.cmake +++ b/CMake/FindBearSSL.cmake @@ -29,7 +29,13 @@ # BEARSSL_INCLUDE_DIRS The bearssl include directories # BEARSSL_LIBRARIES The bearssl library names -find_path(BEARSSL_INCLUDE_DIRS "bearssl.h") +# for compatibility. Configuration via BEARSSL_INCLUDE_DIRS is deprecated, use BEARSSL_INCLUDE_DIR instead. +if(DEFINED BEARSSL_INCLUDE_DIRS AND NOT DEFINED BEARSSL_INCLUDE_DIR) + set(BEARSSL_INCLUDE_DIR "${BEARSSL_INCLUDE_DIRS}") + unset(BEARSSL_INCLUDE_DIRS) +endif() + +find_path(BEARSSL_INCLUDE_DIR "bearssl.h") find_library(BEARSSL_LIBRARY "bearssl") @@ -40,4 +46,9 @@ find_package_handle_standard_args(BEARSSL BEARSSL_LIBRARY ) -mark_as_advanced(BEARSSL_INCLUDE_DIRS BEARSSL_LIBRARY) +if(BEARSSL_FOUND) + set(BEARSSL_INCLUDE_DIRS ${BEARSSL_INCLUDE_DIR}) + set(BEARSSL_LIBRARIES ${BEARSSL_LIBRARY}) +endif() + +mark_as_advanced(BEARSSL_INCLUDE_DIR BEARSSL_LIBRARY) diff --git a/CMake/FindCARES.cmake b/CMake/FindCARES.cmake index 12efea9138..24c19d24d6 100644 --- a/CMake/FindCARES.cmake +++ b/CMake/FindCARES.cmake @@ -25,9 +25,9 @@ # # Result Variables: # -# CARES_FOUND System has c-ares -# CARES_INCLUDE_DIR The c-ares include directory -# CARES_LIBRARY The c-ares library name +# CARES_FOUND System has c-ares +# CARES_INCLUDE_DIRS The c-ares include directories +# CARES_LIBRARIES The c-ares library names find_path(CARES_INCLUDE_DIR "ares.h") @@ -40,4 +40,9 @@ find_package_handle_standard_args(CARES CARES_LIBRARY ) +if(CARES_FOUND) + set(CARES_INCLUDE_DIRS ${CARES_INCLUDE_DIR}) + set(CARES_LIBRARIES ${CARES_LIBRARY}) +endif() + mark_as_advanced(CARES_INCLUDE_DIR CARES_LIBRARY) diff --git a/CMake/FindGSS.cmake b/CMake/FindGSS.cmake index cbd9bbe5c6..3b528eaa01 100644 --- a/CMake/FindGSS.cmake +++ b/CMake/FindGSS.cmake @@ -31,7 +31,7 @@ # # GSS_FOUND System has the Heimdal library # GSS_FLAVOUR "MIT" or "Heimdal" if anything found -# GSS_INCLUDE_DIR The GSS include directory +# GSS_INCLUDE_DIRS The GSS include directories # GSS_LIBRARIES The GSS library names # GSS_LINK_DIRECTORIES Directories to add to linker search path # GSS_LINKER_FLAGS Additional linker flags @@ -260,7 +260,7 @@ else() endif() endif() -set(GSS_INCLUDE_DIR ${_GSS_INCLUDE_DIRS}) +set(GSS_INCLUDE_DIRS ${_GSS_INCLUDE_DIRS}) set(GSS_LIBRARIES ${_GSS_LIBRARIES}) set(GSS_LINK_DIRECTORIES ${_GSS_LIBRARY_DIRS}) set(GSS_LINKER_FLAGS ${_GSS_LDFLAGS}) @@ -275,8 +275,8 @@ if(GSS_FLAVOUR) set(_heimdal_manifest_file "Heimdal.Application.x86.manifest") endif() - if(EXISTS "${GSS_INCLUDE_DIR}/${_heimdal_manifest_file}") - file(STRINGS "${GSS_INCLUDE_DIR}/${_heimdal_manifest_file}" _heimdal_version_str + if(EXISTS "${GSS_INCLUDE_DIRS}/${_heimdal_manifest_file}") + file(STRINGS "${GSS_INCLUDE_DIRS}/${_heimdal_manifest_file}" _heimdal_version_str REGEX "^.*version=\"[0-9]\\.[^\"]+\".*$") string(REGEX MATCH "[0-9]\\.[^\"]+" GSS_VERSION "${_heimdal_version_str}") diff --git a/CMake/FindLibPSL.cmake b/CMake/FindLibPSL.cmake index 03be5885b8..0f647b114e 100644 --- a/CMake/FindLibPSL.cmake +++ b/CMake/FindLibPSL.cmake @@ -25,10 +25,10 @@ # # Result Variables: # -# LIBPSL_FOUND System has libpsl -# LIBPSL_INCLUDE_DIR The libpsl include directory -# LIBPSL_LIBRARY The libpsl library name -# LIBPSL_VERSION Version of libpsl +# LIBPSL_FOUND System has libpsl +# LIBPSL_INCLUDE_DIRS The libpsl include directories +# LIBPSL_LIBRARIES The libpsl library names +# LIBPSL_VERSION Version of libpsl find_path(LIBPSL_INCLUDE_DIR "libpsl.h") @@ -49,4 +49,9 @@ find_package_handle_standard_args(LibPSL LIBPSL_VERSION ) +if(LIBPSL_FOUND) + set(LIBPSL_INCLUDE_DIRS ${LIBPSL_INCLUDE_DIR}) + set(LIBPSL_LIBRARIES ${LIBPSL_LIBRARY}) +endif() + mark_as_advanced(LIBPSL_INCLUDE_DIR LIBPSL_LIBRARY) diff --git a/CMake/FindLibSSH2.cmake b/CMake/FindLibSSH2.cmake index 05a5bf9c50..d8375b55d6 100644 --- a/CMake/FindLibSSH2.cmake +++ b/CMake/FindLibSSH2.cmake @@ -25,10 +25,10 @@ # # Result Variables: # -# LIBSSH2_FOUND System has libssh2 -# LIBSSH2_INCLUDE_DIR The libssh2 include directory -# LIBSSH2_LIBRARY The libssh2 library name -# LIBSSH2_VERSION Version of libssh2 +# LIBSSH2_FOUND System has libssh2 +# LIBSSH2_INCLUDE_DIRS The libssh2 include directories +# LIBSSH2_LIBRARIES The libssh2 library names +# LIBSSH2_VERSION Version of libssh2 find_path(LIBSSH2_INCLUDE_DIR "libssh2.h") @@ -49,4 +49,9 @@ find_package_handle_standard_args(LibSSH2 LIBSSH2_VERSION ) +if(LIBSSH2_FOUND) + set(LIBSSH2_INCLUDE_DIRS ${LIBSSH2_INCLUDE_DIR}) + set(LIBSSH2_LIBRARIES ${LIBSSH2_LIBRARY}) +endif() + mark_as_advanced(LIBSSH2_INCLUDE_DIR LIBSSH2_LIBRARY) diff --git a/CMake/FindMbedTLS.cmake b/CMake/FindMbedTLS.cmake index afb98f44d6..83c34ec4e3 100644 --- a/CMake/FindMbedTLS.cmake +++ b/CMake/FindMbedTLS.cmake @@ -29,21 +29,30 @@ # MBEDTLS_INCLUDE_DIRS The mbedtls include directories # MBEDTLS_LIBRARIES The mbedtls library names -find_path(MBEDTLS_INCLUDE_DIRS "mbedtls/ssl.h") +# for compatibility. Configuration via MBEDTLS_INCLUDE_DIRS is deprecated, use MBEDTLS_INCLUDE_DIR instead. +if(DEFINED MBEDTLS_INCLUDE_DIRS AND NOT DEFINED MBEDTLS_INCLUDE_DIR) + set(MBEDTLS_INCLUDE_DIR "${MBEDTLS_INCLUDE_DIRS}") + unset(MBEDTLS_INCLUDE_DIRS) +endif() + +find_path(MBEDTLS_INCLUDE_DIR "mbedtls/ssl.h") find_library(MBEDTLS_LIBRARY "mbedtls") find_library(MBEDX509_LIBRARY "mbedx509") find_library(MBEDCRYPTO_LIBRARY "mbedcrypto") -set(MBEDTLS_LIBRARIES "${MBEDTLS_LIBRARY}" "${MBEDX509_LIBRARY}" "${MBEDCRYPTO_LIBRARY}") - include(FindPackageHandleStandardArgs) find_package_handle_standard_args(MbedTLS REQUIRED_VARS - MBEDTLS_INCLUDE_DIRS + MBEDTLS_INCLUDE_DIR MBEDTLS_LIBRARY MBEDX509_LIBRARY MBEDCRYPTO_LIBRARY ) -mark_as_advanced(MBEDTLS_INCLUDE_DIRS MBEDTLS_LIBRARY MBEDX509_LIBRARY MBEDCRYPTO_LIBRARY) +if(MBEDTLS_FOUND) + set(MBEDTLS_INCLUDE_DIRS ${MBEDTLS_INCLUDE_DIR}) + set(MBEDTLS_LIBRARIES ${MBEDTLS_LIBRARY} ${MBEDX509_LIBRARY} ${MBEDCRYPTO_LIBRARY}) +endif() + +mark_as_advanced(MBEDTLS_INCLUDE_DIR MBEDTLS_LIBRARY MBEDX509_LIBRARY MBEDCRYPTO_LIBRARY) diff --git a/CMakeLists.txt b/CMakeLists.txt index ed8097f149..36616b0b0b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -216,7 +216,7 @@ set(LIBCURL_PC_REQUIRES_PRIVATE "") if(ENABLE_ARES) set(USE_ARES 1) find_package(CARES REQUIRED) - list(APPEND CURL_LIBS ${CARES_LIBRARY}) + list(APPEND CURL_LIBS ${CARES_LIBRARIES}) list(APPEND LIBCURL_PC_REQUIRES_PRIVATE "libcares") endif() @@ -568,7 +568,7 @@ if(CURL_USE_BEARSSL) find_package(BearSSL REQUIRED) set(_ssl_enabled ON) set(USE_BEARSSL ON) - list(APPEND CURL_LIBS ${BEARSSL_LIBRARY}) + list(APPEND CURL_LIBS ${BEARSSL_LIBRARIES}) include_directories(${BEARSSL_INCLUDE_DIRS}) if(CURL_DEFAULT_SSL_BACKEND AND CURL_DEFAULT_SSL_BACKEND STREQUAL "bearssl") @@ -1019,10 +1019,10 @@ set(USE_LIBPSL OFF) if(CURL_USE_LIBPSL) find_package(LibPSL) if(LIBPSL_FOUND) - list(APPEND CURL_LIBS ${LIBPSL_LIBRARY}) + list(APPEND CURL_LIBS ${LIBPSL_LIBRARIES}) list(APPEND LIBCURL_PC_REQUIRES_PRIVATE "libpsl") - list(APPEND CMAKE_REQUIRED_INCLUDES "${LIBPSL_INCLUDE_DIR}") - include_directories(${LIBPSL_INCLUDE_DIR}) + list(APPEND CMAKE_REQUIRED_INCLUDES "${LIBPSL_INCLUDE_DIRS}") + include_directories(${LIBPSL_INCLUDE_DIRS}) set(USE_LIBPSL ON) endif() endif() @@ -1035,10 +1035,10 @@ set(USE_LIBSSH2 OFF) if(CURL_USE_LIBSSH2) find_package(LibSSH2) if(LIBSSH2_FOUND) - list(APPEND CURL_LIBS ${LIBSSH2_LIBRARY}) + list(APPEND CURL_LIBS ${LIBSSH2_LIBRARIES}) list(APPEND LIBCURL_PC_REQUIRES_PRIVATE "libssh2") - list(APPEND CMAKE_REQUIRED_INCLUDES "${LIBSSH2_INCLUDE_DIR}") - include_directories(${LIBSSH2_INCLUDE_DIR}) + list(APPEND CMAKE_REQUIRED_INCLUDES "${LIBSSH2_INCLUDE_DIRS}") + include_directories(${LIBSSH2_INCLUDE_DIRS}) set(USE_LIBSSH2 ON) endif() endif() @@ -1093,7 +1093,7 @@ if(CURL_USE_GSSAPI) message(STATUS "Found ${GSS_FLAVOUR} GSSAPI version: \"${GSS_VERSION}\"") - list(APPEND CMAKE_REQUIRED_INCLUDES ${GSS_INCLUDE_DIR}) + list(APPEND CMAKE_REQUIRED_INCLUDES ${GSS_INCLUDE_DIRS}) string(REPLACE ";" " " GSS_COMPILER_FLAGS "${GSS_COMPILER_FLAGS}") string(REPLACE ";" " " GSS_LINKER_FLAGS "${GSS_LINKER_FLAGS}") @@ -1129,7 +1129,7 @@ if(CURL_USE_GSSAPI) endif() endif() - include_directories(${GSS_INCLUDE_DIR}) + include_directories(${GSS_INCLUDE_DIRS}) link_directories(${GSS_LINK_DIRECTORIES}) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${GSS_COMPILER_FLAGS}") set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${GSS_LINKER_FLAGS}") diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index f439b42cad..52324ba296 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -43,7 +43,7 @@ include_directories( "${CMAKE_CURRENT_SOURCE_DIR}" ) if(USE_ARES) - include_directories(${CARES_INCLUDE_DIR}) + include_directories(${CARES_INCLUDE_DIRS}) endif() if(BUILD_TESTING) diff --git a/tests/libtest/CMakeLists.txt b/tests/libtest/CMakeLists.txt index b24ee1087e..c3e27ad53f 100644 --- a/tests/libtest/CMakeLists.txt +++ b/tests/libtest/CMakeLists.txt @@ -38,7 +38,7 @@ function(setup_test _test_name) # ARGN are the files in the test "${CURL_SOURCE_DIR}/tests/libtest" # to be able to build generated tests ) if(USE_ARES) - include_directories(${CARES_INCLUDE_DIR}) + include_directories(${CARES_INCLUDE_DIRS}) endif() target_link_libraries(${_test_name} ${LIB_SELECTED} ${CURL_LIBS}) diff --git a/tests/server/CMakeLists.txt b/tests/server/CMakeLists.txt index 33bc6941ec..3e9bcbcda4 100644 --- a/tests/server/CMakeLists.txt +++ b/tests/server/CMakeLists.txt @@ -31,7 +31,7 @@ function(setup_executable _test_name) # ARGN are the files in the test "${CURL_SOURCE_DIR}/src" # for "tool_xattr.h" in disabled_SOURCES ) if(USE_ARES) - include_directories(${CARES_INCLUDE_DIR}) + include_directories(${CARES_INCLUDE_DIRS}) endif() target_link_libraries(${_test_name} ${CURL_LIBS}) -- 2.47.3