mirror of
https://github.com/curl/curl.git
synced 2026-04-15 00:01:41 +03:00
cmake: fix building with CMAKE_FIND_PACKAGE_PREFER_CONFIG=ON
This CMake global custom option tells it to find dependencies as cmake Configs first, and only then look for `Find*` modules. This may result in `find_package()` succeeding, but without actually creating `CURL::*` imported targets the curl build scripts are expecting. For dependencies with curl-specific, local, `Find*` modules, we always want to use them, via the module detection method, and never a Config-based detection. Ensure this by passing the `MODULE` option to `find_package()` and `find_dependency()` to make them use `Find*` modules unconditionally, making them work as expected with the `CMAKE_FIND_PACKAGE_PREFER_CONFIG=ON` option set. curl uses local Find modules for all dependencies except OpenSSL and ZLIB. The latter two keep using either CMake's built-in Find modules or Config method as before this patch. Also: - apply the same change to `curl-config.cmake`. To fix consuming curl with this option set. Authored-by: Valerie Snyder Ref: #20764 Follow-up to16f073ef49#16973 - GHA/distcheck: add a job testing both building and consuming curl with this option set. (takes 15 seconds) Use custom NGHTTP2 configuration for an extra twist (not required to trigger this issue.) Follow-up tofcde8d7e37#20773 Reported-by: Valerie Snyder Fixes #20729 Closes #20784
This commit is contained in:
parent
3d708e239b
commit
91e06fde1b
4 changed files with 64 additions and 50 deletions
6
.github/workflows/distcheck.yml
vendored
6
.github/workflows/distcheck.yml
vendored
|
|
@ -319,6 +319,12 @@ jobs:
|
|||
- name: 'via find_package (C++)'
|
||||
if: ${{ contains(matrix.image, 'ubuntu') }}
|
||||
run: TEST_CMAKE_FLAGS=-DTEST_CPP=ON ./tests/cmake/test.sh find_package ${TESTOPTS} -DCURL_USE_OPENSSL=ON
|
||||
- name: 'via find_package (PREFER_CONFIG=ON)'
|
||||
if: ${{ contains(matrix.image, 'windows') }}
|
||||
run: |
|
||||
export TEST_CMAKE_FLAGS_PROVIDER='-DCMAKE_FIND_PACKAGE_PREFER_CONFIG=ON -DCURL_ZSTD=OFF -DNGHTTP2_INCLUDE_DIR=C:/msys64/mingw64/include -DNGHTTP2_LIBRARY=C:/msys64/mingw64/lib/libnghttp2.dll.a'
|
||||
export TEST_CMAKE_FLAGS_CONSUMER="${TEST_CMAKE_FLAGS_PROVIDER}"
|
||||
./tests/cmake/test.sh find_package ${TESTOPTS} -DCURL_USE_OPENSSL=ON
|
||||
|
||||
- name: 'via ExternalProject (old cmake)'
|
||||
if: ${{ contains(matrix.image, 'ubuntu') }}
|
||||
|
|
|
|||
|
|
@ -71,9 +71,17 @@ macro(curl_dependency_option _option_name _find_name _desc_name)
|
|||
set_property(CACHE ${_option_name} PROPERTY STRINGS "AUTO" "ON" "OFF")
|
||||
|
||||
if(${_option_name} STREQUAL "AUTO")
|
||||
find_package(${_find_name})
|
||||
if(_find_name STREQUAL "ZLIB")
|
||||
find_package(${_find_name})
|
||||
else()
|
||||
find_package(${_find_name} MODULE)
|
||||
endif()
|
||||
elseif(${_option_name})
|
||||
find_package(${_find_name} REQUIRED)
|
||||
if(_find_name STREQUAL "ZLIB")
|
||||
find_package(${_find_name} REQUIRED)
|
||||
else()
|
||||
find_package(${_find_name} MODULE REQUIRED)
|
||||
endif()
|
||||
else()
|
||||
string(TOUPPER "${_find_name}" _find_name_upper)
|
||||
set(${_find_name}_FOUND OFF) # cmake-lint: disable=C0103
|
||||
|
|
|
|||
|
|
@ -62,89 +62,89 @@ set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR} ${CMAKE_MODULE_PATH})
|
|||
set(_curl_libs "")
|
||||
|
||||
if("@HAVE_BROTLI@")
|
||||
find_dependency(Brotli)
|
||||
find_dependency(Brotli MODULE)
|
||||
list(APPEND _curl_libs CURL::brotli)
|
||||
endif()
|
||||
if("@USE_ARES@")
|
||||
find_dependency(Cares)
|
||||
find_dependency(Cares MODULE)
|
||||
list(APPEND _curl_libs CURL::cares)
|
||||
endif()
|
||||
if("@HAVE_GSSAPI@")
|
||||
find_dependency(GSS)
|
||||
find_dependency(GSS MODULE)
|
||||
list(APPEND _curl_libs CURL::gss)
|
||||
endif()
|
||||
if("@USE_BACKTRACE@")
|
||||
find_dependency(Libbacktrace)
|
||||
find_dependency(Libbacktrace MODULE)
|
||||
list(APPEND _curl_libs CURL::libbacktrace)
|
||||
endif()
|
||||
if("@USE_GSASL@")
|
||||
find_dependency(Libgsasl)
|
||||
find_dependency(Libgsasl MODULE)
|
||||
list(APPEND _curl_libs CURL::libgsasl)
|
||||
endif()
|
||||
if(NOT "@USE_WIN32_LDAP@" AND NOT "@CURL_DISABLE_LDAP@")
|
||||
find_dependency(LDAP)
|
||||
find_dependency(LDAP MODULE)
|
||||
list(APPEND _curl_libs CURL::ldap)
|
||||
endif()
|
||||
if("@HAVE_LIBIDN2@")
|
||||
find_dependency(Libidn2)
|
||||
find_dependency(Libidn2 MODULE)
|
||||
list(APPEND _curl_libs CURL::libidn2)
|
||||
endif()
|
||||
if("@USE_LIBPSL@")
|
||||
find_dependency(Libpsl)
|
||||
find_dependency(Libpsl MODULE)
|
||||
list(APPEND _curl_libs CURL::libpsl)
|
||||
endif()
|
||||
if("@USE_LIBRTMP@")
|
||||
find_dependency(Librtmp)
|
||||
find_dependency(Librtmp MODULE)
|
||||
list(APPEND _curl_libs CURL::librtmp)
|
||||
endif()
|
||||
if("@USE_LIBSSH@")
|
||||
find_dependency(Libssh)
|
||||
find_dependency(Libssh MODULE)
|
||||
list(APPEND _curl_libs CURL::libssh)
|
||||
endif()
|
||||
if("@USE_LIBSSH2@")
|
||||
find_dependency(Libssh2)
|
||||
find_dependency(Libssh2 MODULE)
|
||||
list(APPEND _curl_libs CURL::libssh2)
|
||||
endif()
|
||||
if("@USE_LIBUV@")
|
||||
find_dependency(Libuv)
|
||||
find_dependency(Libuv MODULE)
|
||||
list(APPEND _curl_libs CURL::libuv)
|
||||
endif()
|
||||
if("@USE_MBEDTLS@")
|
||||
find_dependency(MbedTLS)
|
||||
find_dependency(MbedTLS MODULE)
|
||||
list(APPEND _curl_libs CURL::mbedtls)
|
||||
endif()
|
||||
if("@USE_NGHTTP2@")
|
||||
find_dependency(NGHTTP2)
|
||||
find_dependency(NGHTTP2 MODULE)
|
||||
list(APPEND _curl_libs CURL::nghttp2)
|
||||
endif()
|
||||
if("@USE_NGHTTP3@")
|
||||
find_dependency(NGHTTP3)
|
||||
find_dependency(NGHTTP3 MODULE)
|
||||
list(APPEND _curl_libs CURL::nghttp3)
|
||||
endif()
|
||||
if("@USE_NGTCP2@")
|
||||
find_dependency(NGTCP2)
|
||||
find_dependency(NGTCP2 MODULE)
|
||||
list(APPEND _curl_libs CURL::ngtcp2)
|
||||
endif()
|
||||
if("@USE_GNUTLS@")
|
||||
find_dependency(GnuTLS)
|
||||
find_dependency(GnuTLS MODULE)
|
||||
list(APPEND _curl_libs CURL::gnutls)
|
||||
find_dependency(Nettle)
|
||||
find_dependency(Nettle MODULE)
|
||||
list(APPEND _curl_libs CURL::nettle)
|
||||
endif()
|
||||
if("@USE_QUICHE@")
|
||||
find_dependency(Quiche)
|
||||
find_dependency(Quiche MODULE)
|
||||
list(APPEND _curl_libs CURL::quiche)
|
||||
endif()
|
||||
if("@USE_RUSTLS@")
|
||||
find_dependency(Rustls)
|
||||
find_dependency(Rustls MODULE)
|
||||
list(APPEND _curl_libs CURL::rustls)
|
||||
endif()
|
||||
if("@USE_WOLFSSL@")
|
||||
find_dependency(WolfSSL)
|
||||
find_dependency(WolfSSL MODULE)
|
||||
list(APPEND _curl_libs CURL::wolfssl)
|
||||
endif()
|
||||
if("@HAVE_ZSTD@")
|
||||
find_dependency(Zstd)
|
||||
find_dependency(Zstd MODULE)
|
||||
list(APPEND _curl_libs CURL::zstd)
|
||||
endif()
|
||||
|
||||
|
|
|
|||
|
|
@ -401,7 +401,7 @@ set(CURL_LIBS "")
|
|||
|
||||
if(ENABLE_ARES)
|
||||
set(USE_ARES 1)
|
||||
find_package(Cares REQUIRED)
|
||||
find_package(Cares MODULE REQUIRED)
|
||||
list(APPEND CURL_LIBS CURL::cares)
|
||||
endif()
|
||||
|
||||
|
|
@ -848,7 +848,7 @@ if(CURL_USE_OPENSSL)
|
|||
endif()
|
||||
|
||||
if(CURL_USE_MBEDTLS)
|
||||
find_package(MbedTLS REQUIRED)
|
||||
find_package(MbedTLS MODULE REQUIRED)
|
||||
if(MBEDTLS_VERSION VERSION_LESS 3.2.0)
|
||||
message(FATAL_ERROR "mbedTLS v3.2.0 or newer is required.")
|
||||
endif()
|
||||
|
|
@ -873,7 +873,7 @@ if(CURL_USE_MBEDTLS)
|
|||
endif()
|
||||
|
||||
if(CURL_USE_WOLFSSL)
|
||||
find_package(WolfSSL REQUIRED)
|
||||
find_package(WolfSSL MODULE REQUIRED)
|
||||
set(_ssl_enabled ON)
|
||||
set(USE_WOLFSSL ON)
|
||||
list(APPEND CURL_LIBS CURL::wolfssl)
|
||||
|
|
@ -891,9 +891,9 @@ if(CURL_USE_WOLFSSL)
|
|||
endif()
|
||||
|
||||
if(CURL_USE_GNUTLS)
|
||||
find_package(GnuTLS REQUIRED)
|
||||
find_package(GnuTLS MODULE REQUIRED)
|
||||
list(APPEND CURL_LIBS CURL::gnutls)
|
||||
find_package(Nettle REQUIRED)
|
||||
find_package(Nettle MODULE REQUIRED)
|
||||
list(APPEND CURL_LIBS CURL::nettle)
|
||||
set(_ssl_enabled ON)
|
||||
set(USE_GNUTLS ON)
|
||||
|
|
@ -914,7 +914,7 @@ if(CURL_USE_GNUTLS)
|
|||
endif()
|
||||
|
||||
if(CURL_USE_RUSTLS)
|
||||
find_package(Rustls REQUIRED)
|
||||
find_package(Rustls MODULE REQUIRED)
|
||||
set(_ssl_enabled ON)
|
||||
set(USE_RUSTLS ON)
|
||||
list(APPEND CURL_LIBS CURL::rustls)
|
||||
|
|
@ -1088,7 +1088,7 @@ endif()
|
|||
|
||||
option(USE_NGHTTP2 "Use nghttp2 library" ON)
|
||||
if(USE_NGHTTP2)
|
||||
find_package(NGHTTP2)
|
||||
find_package(NGHTTP2 MODULE)
|
||||
if(NGHTTP2_FOUND)
|
||||
list(APPEND CURL_LIBS CURL::nghttp2)
|
||||
else()
|
||||
|
|
@ -1102,33 +1102,33 @@ if(USE_NGTCP2)
|
|||
message(FATAL_ERROR "MultiSSL cannot be enabled with HTTP/3 and vice versa.")
|
||||
elseif(USE_OPENSSL OR USE_WOLFSSL)
|
||||
if(USE_WOLFSSL)
|
||||
find_package(NGTCP2 REQUIRED COMPONENTS "wolfSSL")
|
||||
find_package(NGTCP2 MODULE REQUIRED COMPONENTS "wolfSSL")
|
||||
elseif(HAVE_BORINGSSL OR HAVE_AWSLC)
|
||||
find_package(NGTCP2 REQUIRED COMPONENTS "BoringSSL")
|
||||
find_package(NGTCP2 MODULE REQUIRED COMPONENTS "BoringSSL")
|
||||
elseif(OPENSSL_VERSION VERSION_GREATER_EQUAL 3.5.0)
|
||||
find_package(NGTCP2 REQUIRED COMPONENTS "ossl")
|
||||
find_package(NGTCP2 MODULE REQUIRED COMPONENTS "ossl")
|
||||
if(NGTCP2_VERSION VERSION_LESS 1.12.0)
|
||||
message(FATAL_ERROR "ngtcp2 1.12.0 or upper required for OpenSSL")
|
||||
endif()
|
||||
set(OPENSSL_QUIC_API2 1)
|
||||
elseif(HAVE_LIBRESSL)
|
||||
find_package(NGTCP2 COMPONENTS "LibreSSL")
|
||||
find_package(NGTCP2 MODULE COMPONENTS "LibreSSL")
|
||||
if(NOT NGTCP2_FOUND)
|
||||
find_package(NGTCP2 REQUIRED COMPONENTS "quictls") # for ngtcp2 <1.15.0
|
||||
find_package(NGTCP2 MODULE REQUIRED COMPONENTS "quictls") # for ngtcp2 <1.15.0
|
||||
endif()
|
||||
else()
|
||||
find_package(NGTCP2 REQUIRED COMPONENTS "quictls")
|
||||
find_package(NGTCP2 MODULE REQUIRED COMPONENTS "quictls")
|
||||
set(_openssl "quictls")
|
||||
endif()
|
||||
curl_openssl_check_quic()
|
||||
elseif(USE_GNUTLS)
|
||||
find_package(NGTCP2 REQUIRED "GnuTLS")
|
||||
find_package(NGTCP2 MODULE REQUIRED "GnuTLS")
|
||||
else()
|
||||
message(FATAL_ERROR "ngtcp2 requires a supported TLS-backend")
|
||||
endif()
|
||||
list(APPEND CURL_LIBS CURL::ngtcp2)
|
||||
|
||||
find_package(NGHTTP3 REQUIRED)
|
||||
find_package(NGHTTP3 MODULE REQUIRED)
|
||||
set(USE_NGHTTP3 ON)
|
||||
list(APPEND CURL_LIBS CURL::nghttp3)
|
||||
endif()
|
||||
|
|
@ -1140,7 +1140,7 @@ if(USE_QUICHE)
|
|||
elseif(CURL_WITH_MULTI_SSL)
|
||||
message(FATAL_ERROR "MultiSSL cannot be enabled with HTTP/3 and vice versa.")
|
||||
endif()
|
||||
find_package(Quiche REQUIRED)
|
||||
find_package(Quiche MODULE REQUIRED)
|
||||
if(NOT HAVE_BORINGSSL)
|
||||
message(FATAL_ERROR "quiche requires BoringSSL")
|
||||
endif()
|
||||
|
|
@ -1176,7 +1176,7 @@ if(NOT CURL_DISABLE_LDAP)
|
|||
if(USE_OPENSSL)
|
||||
list(APPEND CMAKE_REQUIRED_LIBRARIES OpenSSL::SSL OpenSSL::Crypto)
|
||||
endif()
|
||||
find_package(LDAP)
|
||||
find_package(LDAP MODULE)
|
||||
if(LDAP_FOUND)
|
||||
set(HAVE_LBER_H 1)
|
||||
set(CURL_LIBS CURL::ldap ${CURL_LIBS})
|
||||
|
|
@ -1244,7 +1244,7 @@ option(USE_LIBIDN2 "Use libidn2 for IDN support" ON)
|
|||
set(HAVE_IDN2_H OFF)
|
||||
set(HAVE_LIBIDN2 OFF)
|
||||
if(USE_LIBIDN2 AND NOT USE_APPLE_IDN AND NOT USE_WIN32_IDN)
|
||||
find_package(Libidn2)
|
||||
find_package(Libidn2 MODULE)
|
||||
if(LIBIDN2_FOUND)
|
||||
set(CURL_LIBS CURL::libidn2 ${CURL_LIBS})
|
||||
set(HAVE_IDN2_H 1)
|
||||
|
|
@ -1257,7 +1257,7 @@ option(CURL_USE_LIBPSL "Use libpsl" ON)
|
|||
mark_as_advanced(CURL_USE_LIBPSL)
|
||||
set(USE_LIBPSL OFF)
|
||||
if(CURL_USE_LIBPSL)
|
||||
find_package(Libpsl REQUIRED)
|
||||
find_package(Libpsl MODULE REQUIRED)
|
||||
list(APPEND CURL_LIBS CURL::libpsl)
|
||||
set(USE_LIBPSL ON)
|
||||
endif()
|
||||
|
|
@ -1267,7 +1267,7 @@ option(CURL_USE_LIBSSH2 "Use libssh2" ON)
|
|||
mark_as_advanced(CURL_USE_LIBSSH2)
|
||||
set(USE_LIBSSH2 OFF)
|
||||
if(CURL_USE_LIBSSH2)
|
||||
find_package(Libssh2)
|
||||
find_package(Libssh2 MODULE)
|
||||
if(LIBSSH2_FOUND)
|
||||
set(CURL_LIBS CURL::libssh2 ${CURL_LIBS}) # keep it before TLS-crypto, compression
|
||||
set(USE_LIBSSH2 ON)
|
||||
|
|
@ -1278,7 +1278,7 @@ endif()
|
|||
option(CURL_USE_LIBSSH "Use libssh" OFF)
|
||||
mark_as_advanced(CURL_USE_LIBSSH)
|
||||
if(NOT USE_LIBSSH2 AND CURL_USE_LIBSSH)
|
||||
find_package(Libssh REQUIRED)
|
||||
find_package(Libssh MODULE REQUIRED)
|
||||
set(CURL_LIBS CURL::libssh ${CURL_LIBS}) # keep it before TLS-crypto, compression
|
||||
set(USE_LIBSSH ON)
|
||||
endif()
|
||||
|
|
@ -1286,7 +1286,7 @@ endif()
|
|||
option(CURL_USE_GSASL "Use libgsasl" OFF)
|
||||
mark_as_advanced(CURL_USE_GSASL)
|
||||
if(CURL_USE_GSASL)
|
||||
find_package(Libgsasl REQUIRED)
|
||||
find_package(Libgsasl MODULE REQUIRED)
|
||||
list(APPEND CURL_LIBS CURL::libgsasl)
|
||||
set(USE_GSASL ON)
|
||||
endif()
|
||||
|
|
@ -1295,7 +1295,7 @@ option(CURL_USE_GSSAPI "Use GSSAPI implementation" OFF)
|
|||
mark_as_advanced(CURL_USE_GSSAPI)
|
||||
|
||||
if(CURL_USE_GSSAPI)
|
||||
find_package(GSS)
|
||||
find_package(GSS MODULE)
|
||||
|
||||
set(HAVE_GSSAPI ${GSS_FOUND})
|
||||
if(GSS_FOUND)
|
||||
|
|
@ -1321,7 +1321,7 @@ if(CURL_USE_LIBBACKTRACE)
|
|||
if(NOT CMAKE_BUILD_TYPE MATCHES "(Debug|RelWithDebInfo)")
|
||||
message(FATAL_ERROR "libbacktrace requires debug information")
|
||||
endif()
|
||||
find_package(Libbacktrace REQUIRED)
|
||||
find_package(Libbacktrace MODULE REQUIRED)
|
||||
list(APPEND CURL_LIBS CURL::libbacktrace)
|
||||
set(USE_BACKTRACE ON)
|
||||
endif()
|
||||
|
|
@ -1332,7 +1332,7 @@ if(CURL_USE_LIBUV)
|
|||
if(NOT ENABLE_DEBUG)
|
||||
message(FATAL_ERROR "Using libuv without debug support enabled is useless")
|
||||
endif()
|
||||
find_package(Libuv REQUIRED)
|
||||
find_package(Libuv MODULE REQUIRED)
|
||||
list(APPEND CURL_LIBS CURL::libuv)
|
||||
set(USE_LIBUV ON)
|
||||
set(HAVE_UV_H ON)
|
||||
|
|
@ -1340,7 +1340,7 @@ endif()
|
|||
|
||||
option(USE_LIBRTMP "Enable librtmp from rtmpdump" OFF)
|
||||
if(USE_LIBRTMP)
|
||||
find_package(Librtmp REQUIRED)
|
||||
find_package(Librtmp MODULE REQUIRED)
|
||||
list(APPEND CURL_LIBS CURL::librtmp)
|
||||
endif()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue