cmake: add CMake Config-based dependency detection
No binary (build failed)
—
(log yok)
| @@ -52,7 +52,7 @@ jobs: | |
| mkdir bld-am && cd bld-am && ../configure --enable-static=no --with-openssl --without-libpsl | |
| - name: 'run cmake' | |
| - | run: cmake -B bld-cm -DCURL_WERROR=ON -DCURL_USE_LIBPSL=OFF |
| + | run: cmake -B bld-cm -DCURL_WERROR=ON -DCURL_USE_CMAKECONFIG=OFF -DCURL_USE_LIBPSL=OFF |
| - name: 'configure log' | |
| run: cat bld-am/config.log 2>/dev/null || true | |
| @@ -101,7 +101,7 @@ jobs: | |
| - name: 'run cmake' | |
| run: | | |
| - | cmake -B bld-cm -DCURL_WERROR=ON -DCURL_USE_LIBPSL=OFF -DCURL_DISABLE_LDAP=ON \ |
| + | cmake -B bld-cm -DCURL_WERROR=ON -DCURL_USE_CMAKECONFIG=OFF -DCURL_USE_LIBPSL=OFF -DCURL_DISABLE_LDAP=ON \ |
| -DCMAKE_C_COMPILER_TARGET="$(uname -m | sed 's/arm64/aarch64/')-apple-darwin$(uname -r)" \ | |
| -DCURL_USE_LIBSSH2=OFF -DUSE_APPLE_SECTRUST=ON | |
| @@ -148,7 +148,7 @@ jobs: | |
| - name: 'run cmake' | |
| run: | | |
| - | cmake -B bld-cm -DCURL_WERROR=ON -DCURL_USE_SCHANNEL=ON -DCURL_USE_LIBPSL=OFF \ |
| + | cmake -B bld-cm -DCURL_WERROR=ON -DCURL_USE_CMAKECONFIG=OFF -DCURL_USE_SCHANNEL=ON -DCURL_USE_LIBPSL=OFF \ |
| -DCMAKE_SYSTEM_NAME=Windows \ | |
| -DCMAKE_C_COMPILER_TARGET="${TRIPLET}" \ | |
| -DCMAKE_C_COMPILER="${TRIPLET}-gcc" | |
| @@ -37,11 +37,15 @@ | |
| set(_libssh2_pc_requires "libssh2") | |
| - | if(CURL_USE_PKGCONFIG AND |
| - | NOT DEFINED LIBSSH2_INCLUDE_DIR AND |
| + | if(NOT DEFINED LIBSSH2_INCLUDE_DIR AND |
| NOT DEFINED LIBSSH2_LIBRARY) | |
| - | find_package(PkgConfig QUIET) |
| - | pkg_check_modules(_libssh2 ${_libssh2_pc_requires}) |
| + | if(CURL_USE_PKGCONFIG) |
| + | find_package(PkgConfig QUIET) |
| + | pkg_check_modules(_libssh2 ${_libssh2_pc_requires}) |
| + | endif() |
| + | if(NOT _libssh2_FOUND AND CURL_USE_CMAKECONFIG) |
| + | find_package(libssh2 CONFIG QUIET) |
| + | endif() |
| endif() | |
| if(_libssh2_FOUND AND _libssh2_INCLUDE_DIRS) | |
| @@ -55,6 +59,16 @@ if(_libssh2_FOUND AND _libssh2_INCLUDE_DIRS) | |
| set(_libssh2_LIBRARIES "${_libssh2_STATIC_LIBRARIES}") | |
| endif() | |
| message(STATUS "Found Libssh2 (via pkg-config): ${_libssh2_INCLUDE_DIRS} (found version \"${LIBSSH2_VERSION}\")") | |
| + | elseif(libssh2_CONFIG) |
| + | set(Libssh2_FOUND TRUE) |
| + | set(LIBSSH2_FOUND TRUE) |
| + | set(LIBSSH2_VERSION ${libssh2_VERSION}) |
| + | if(LIBSSH2_USE_STATIC_LIBS) |
| + | set(_libssh2_LIBRARIES libssh2::libssh2_static) |
| + | else() |
| + | set(_libssh2_LIBRARIES libssh2::libssh2) |
| + | endif() |
| + | message(STATUS "Found Libssh2 (via CMake Config): ${libssh2_CONFIG} (found version \"${LIBSSH2_VERSION}\")") |
| else() | |
| find_path(LIBSSH2_INCLUDE_DIR NAMES "libssh2.h") | |
| if(LIBSSH2_USE_STATIC_LIBS) | |
| @@ -45,13 +45,17 @@ endif() | |
| set(_mbedtls_pc_requires "mbedtls" "mbedx509" "mbedcrypto") | |
| - | if(CURL_USE_PKGCONFIG AND |
| - | NOT DEFINED MBEDTLS_INCLUDE_DIR AND |
| + | if(NOT DEFINED MBEDTLS_INCLUDE_DIR AND |
| NOT DEFINED MBEDTLS_LIBRARY AND | |
| NOT DEFINED MBEDX509_LIBRARY AND | |
| NOT DEFINED MBEDCRYPTO_LIBRARY) | |
| - | find_package(PkgConfig QUIET) |
| - | pkg_check_modules(_mbedtls ${_mbedtls_pc_requires}) |
| + | if(CURL_USE_PKGCONFIG) |
| + | find_package(PkgConfig QUIET) |
| + | pkg_check_modules(_mbedtls ${_mbedtls_pc_requires}) |
| + | endif() |
| + | if(NOT _mbedtls_FOUND AND CURL_USE_CMAKECONFIG) |
| + | find_package(MbedTLS CONFIG QUIET) |
| + | endif() |
| endif() | |
| if(_mbedtls_FOUND) | |
| @@ -65,6 +69,17 @@ if(_mbedtls_FOUND) | |
| set(_mbedtls_LIBRARIES "${_mbedtls_STATIC_LIBRARIES}") | |
| endif() | |
| message(STATUS "Found MbedTLS (via pkg-config): ${_mbedtls_INCLUDE_DIRS} (found version \"${MBEDTLS_VERSION}\")") | |
| + | elseif(MbedTLS_CONFIG) |
| + | set(MbedTLS_FOUND TRUE) |
| + | set(MBEDTLS_FOUND TRUE) |
| + | set(MBEDTLS_VERSION ${MbedTLS_VERSION}) |
| + | if(MBEDTLS_VERSION GREATER_EQUAL 4.0.0) |
| + | set(_mbedtls_LIBRARIES MbedTLS::tfpsacrypto) |
| + | else() |
| + | set(_mbedtls_LIBRARIES MbedTLS::mbedcrypto) |
| + | endif() |
| + | list(APPEND _mbedtls_LIBRARIES MbedTLS::mbedx509 MbedTLS::mbedtls) |
| + | message(STATUS "Found MbedTLS (via CMake Config): ${MbedTLS_CONFIG} (found version \"${MBEDTLS_VERSION}\")") |
| else() | |
| set(_mbedtls_pc_requires "") # Depend on pkg-config only when found via pkg-config | |
| @@ -37,11 +37,15 @@ | |
| set(_nghttp2_pc_requires "libnghttp2") | |
| - | if(CURL_USE_PKGCONFIG AND |
| - | NOT DEFINED NGHTTP2_INCLUDE_DIR AND |
| + | if(NOT DEFINED NGHTTP2_INCLUDE_DIR AND |
| NOT DEFINED NGHTTP2_LIBRARY) | |
| - | find_package(PkgConfig QUIET) |
| - | pkg_check_modules(_nghttp2 ${_nghttp2_pc_requires}) |
| + | if(CURL_USE_PKGCONFIG) |
| + | find_package(PkgConfig QUIET) |
| + | pkg_check_modules(_nghttp2 ${_nghttp2_pc_requires}) |
| + | endif() |
| + | if(NOT _nghttp2_FOUND AND CURL_USE_CMAKECONFIG) |
| + | find_package(nghttp2 CONFIG QUIET) |
| + | endif() |
| endif() | |
| if(_nghttp2_FOUND) | |
| @@ -54,6 +58,15 @@ if(_nghttp2_FOUND) | |
| set(_nghttp2_LIBRARIES "${_nghttp2_STATIC_LIBRARIES}") | |
| endif() | |
| message(STATUS "Found NGHTTP2 (via pkg-config): ${_nghttp2_INCLUDE_DIRS} (found version \"${NGHTTP2_VERSION}\")") | |
| + | elseif(nghttp2_CONFIG) |
| + | set(NGHTTP2_FOUND TRUE) |
| + | set(NGHTTP2_VERSION ${nghttp2_VERSION}) |
| + | if(NGHTTP2_USE_STATIC_LIBS) |
| + | set(_nghttp2_LIBRARIES nghttp2::nghttp2_static) |
| + | else() |
| + | set(_nghttp2_LIBRARIES nghttp2::nghttp2) |
| + | endif() |
| + | message(STATUS "Found NGHTTP2 (via CMake Config): ${nghttp2_CONFIG} (found version \"${NGHTTP2_VERSION}\")") |
| else() | |
| find_path(NGHTTP2_INCLUDE_DIR NAMES "nghttp2/nghttp2.h") | |
| if(NGHTTP2_USE_STATIC_LIBS) | |
| @@ -37,11 +37,15 @@ | |
| set(_nghttp3_pc_requires "libnghttp3") | |
| - | if(CURL_USE_PKGCONFIG AND |
| - | NOT DEFINED NGHTTP3_INCLUDE_DIR AND |
| + | if(NOT DEFINED NGHTTP3_INCLUDE_DIR AND |
| NOT DEFINED NGHTTP3_LIBRARY) | |
| - | find_package(PkgConfig QUIET) |
| - | pkg_check_modules(_nghttp3 ${_nghttp3_pc_requires}) |
| + | if(CURL_USE_PKGCONFIG) |
| + | find_package(PkgConfig QUIET) |
| + | pkg_check_modules(_nghttp3 ${_nghttp3_pc_requires}) |
| + | endif() |
| + | if(NOT _nghttp3_FOUND AND CURL_USE_CMAKECONFIG) |
| + | find_package(nghttp3 CONFIG QUIET) |
| + | endif() |
| endif() | |
| if(_nghttp3_FOUND) | |
| @@ -54,6 +58,15 @@ if(_nghttp3_FOUND) | |
| set(_nghttp3_LIBRARIES "${_nghttp3_STATIC_LIBRARIES}") | |
| endif() | |
| message(STATUS "Found NGHTTP3 (via pkg-config): ${_nghttp3_INCLUDE_DIRS} (found version \"${NGHTTP3_VERSION}\")") | |
| + | elseif(nghttp3_CONFIG) |
| + | set(NGHTTP3_FOUND TRUE) |
| + | set(NGHTTP3_VERSION ${nghttp3_VERSION}) |
| + | if(NGHTTP3_USE_STATIC_LIBS) |
| + | set(_nghttp3_LIBRARIES nghttp3::nghttp3_static) |
| + | else() |
| + | set(_nghttp3_LIBRARIES nghttp3::nghttp3) |
| + | endif() |
| + | message(STATUS "Found NGHTTP3 (via CMake Config): ${nghttp3_CONFIG} (found version \"${NGHTTP3_VERSION}\")") |
| else() | |
| find_path(NGHTTP3_INCLUDE_DIR NAMES "nghttp3/nghttp3.h") | |
| if(NGHTTP3_USE_STATIC_LIBS) | |
| @@ -74,12 +74,22 @@ if(_ngtcp2_crypto_backend) | |
| endif() | |
| set(_tried_pkgconfig FALSE) | |
| - | if(CURL_USE_PKGCONFIG AND |
| - | NOT DEFINED NGTCP2_INCLUDE_DIR AND |
| + | if(NOT DEFINED NGTCP2_INCLUDE_DIR AND |
| NOT DEFINED NGTCP2_LIBRARY) | |
| - | find_package(PkgConfig QUIET) |
| - | pkg_check_modules(_ngtcp2 ${_ngtcp2_pc_requires}) |
| - | set(_tried_pkgconfig TRUE) |
| + | if(CURL_USE_PKGCONFIG) |
| + | find_package(PkgConfig QUIET) |
| + | pkg_check_modules(_ngtcp2 ${_ngtcp2_pc_requires}) |
| + | set(_tried_pkgconfig TRUE) |
| + | endif() |
| + | if(NOT _ngtcp2_FOUND AND CURL_USE_CMAKECONFIG) |
| + | find_package(ngtcp2 CONFIG QUIET) |
| + | # Skip using it if the crypto library target is not available |
| + | if(ngtcp2_CONFIG AND |
| + | NOT TARGET ngtcp2::${_crypto_library_lower}_static AND |
| + | NOT TARGET ngtcp2::${_crypto_library_lower}) |
| + | unset(ngtcp2_CONFIG) |
| + | endif() |
| + | endif() |
| endif() | |
| if(_ngtcp2_FOUND) | |
| @@ -92,6 +102,15 @@ if(_ngtcp2_FOUND) | |
| set(_ngtcp2_LIBRARIES "${_ngtcp2_STATIC_LIBRARIES}") | |
| endif() | |
| message(STATUS "Found NGTCP2 (via pkg-config): ${_ngtcp2_INCLUDE_DIRS} (found version \"${NGTCP2_VERSION}\")") | |
| + | elseif(ngtcp2_CONFIG) |
| + | set(NGTCP2_FOUND TRUE) |
| + | set(NGTCP2_VERSION ${ngtcp2_VERSION}) |
| + | if(NGTCP2_USE_STATIC_LIBS) |
| + | set(_ngtcp2_LIBRARIES ngtcp2::ngtcp2_static ngtcp2::${_crypto_library_lower}_static) |
| + | else() |
| + | set(_ngtcp2_LIBRARIES ngtcp2::ngtcp2 ngtcp2::${_crypto_library_lower}) |
| + | endif() |
| + | message(STATUS "Found NGTCP2 (via CMake Config): ${ngtcp2_CONFIG} (found version \"${NGTCP2_VERSION}\")") |
| else() | |
| find_path(NGTCP2_INCLUDE_DIR NAMES "ngtcp2/ngtcp2.h") | |
| if(NGTCP2_USE_STATIC_LIBS) | |
| @@ -46,11 +46,21 @@ endif() | |
| set(_zstd_pc_requires "libzstd") | |
| - | if(CURL_USE_PKGCONFIG AND |
| - | NOT DEFINED ZSTD_INCLUDE_DIR AND |
| + | if(NOT DEFINED ZSTD_INCLUDE_DIR AND |
| NOT DEFINED ZSTD_LIBRARY) | |
| - | find_package(PkgConfig QUIET) |
| - | pkg_check_modules(_zstd ${_zstd_pc_requires}) |
| + | if(CURL_USE_PKGCONFIG) |
| + | find_package(PkgConfig QUIET) |
| + | pkg_check_modules(_zstd ${_zstd_pc_requires}) |
| + | endif() |
| + | if(NOT _zstd_FOUND AND CURL_USE_CMAKECONFIG) |
| + | find_package(Zstd CONFIG QUIET) |
| + | # Skip using if older than v1.4.5 |
| + | if(Zstd_CONFIG AND |
| + | NOT TARGET zstd::libzstd_static AND |
| + | NOT TARGET zstd::libzstd_shared) |
| + | unset(Zstd_CONFIG) |
| + | endif() |
| + | endif() |
| endif() | |
| if(_zstd_FOUND) | |
| @@ -64,6 +74,17 @@ if(_zstd_FOUND) | |
| set(_zstd_LIBRARIES "${_zstd_STATIC_LIBRARIES}") | |
| endif() | |
| message(STATUS "Found Zstd (via pkg-config): ${_zstd_INCLUDE_DIRS} (found version \"${ZSTD_VERSION}\")") | |
| + | elseif(Zstd_CONFIG) |
| + | set(ZSTD_FOUND TRUE) |
| + | set(ZSTD_VERSION ${Zstd_VERSION}) |
| + | if(ZSTD_USE_STATIC_LIBS) |
| + | set(_zstd_LIBRARIES zstd::libzstd_static) |
| + | elseif(TARGET zstd::libzstd) |
| + | set(_zstd_LIBRARIES zstd::libzstd) # v1.5.6+ |
| + | else() |
| + | set(_zstd_LIBRARIES zstd::libzstd_shared) |
| + | endif() |
| + | message(STATUS "Found Zstd (via CMake Config): ${Zstd_CONFIG} (found version \"${ZSTD_VERSION}\")") |
| else() | |
| find_path(ZSTD_INCLUDE_DIR NAMES "zstd.h") | |
| if(ZSTD_USE_STATIC_LIBS) | |
| @@ -23,6 +23,8 @@ | |
| ########################################################################### | |
| @PACKAGE_INIT@ | |
| + | option(CURL_USE_CMAKECONFIG "Enable detecting @PROJECT_NAME@ dependencies via CMake Config. Default: @CURL_USE_CMAKECONFIG@" |
| + | "@CURL_USE_CMAKECONFIG@") |
| option(CURL_USE_PKGCONFIG "Enable pkg-config to detect @PROJECT_NAME@ dependencies. Default: @CURL_USE_PKGCONFIG@" | |
| "@CURL_USE_PKGCONFIG@") | |
| @@ -385,6 +385,14 @@ if(WIN32) | |
| endif() | |
| endif() | |
| + | # Override to force-disable or force-enable the use of CMake Configs. |
| + | if(MSVC AND NOT VCPKG_TOOLCHAIN AND NOT CMAKE_CROSSCOMPILING) |
| + | set(_curl_use_cmakeconfig_default ON) |
| + | else() |
| + | set(_curl_use_cmakeconfig_default OFF) |
| + | endif() |
| + | option(CURL_USE_CMAKECONFIG "Enable detecting dependencies via CMake Config" ${_curl_use_cmakeconfig_default}) |
| + | |
| # Override to force-disable or force-enable the use of pkg-config. | |
| if((UNIX AND NOT ANDROID AND (NOT APPLE OR CMAKE_SYSTEM_NAME STREQUAL "Darwin")) OR | |
| VCPKG_TOOLCHAIN OR | |
| @@ -2325,6 +2333,7 @@ if(NOT CURL_DISABLE_INSTALL) | |
| # TARGETS_EXPORT_NAME | |
| # CURL_SUPPORTED_FEATURES_LIST | |
| # CURL_SUPPORTED_PROTOCOLS_LIST | |
| + | # CURL_USE_CMAKECONFIG |
| # CURL_USE_PKGCONFIG | |
| # HAVE_BROTLI | |
| # HAVE_GSSAPI | |
| @@ -347,6 +347,7 @@ Details via CMake | |
| ## Dependencies | |
| - `CURL_BROTLI`: Use brotli (`ON`, `OFF` or `AUTO`). Default: `AUTO` | |
| + | - `CURL_USE_CMAKECONFIG`: Enable detecting dependencies via CMake Config. Default: `ON` for MSVC (except under vcpkg), if not cross-compiling. (experimental) |
| - `CURL_USE_GNUTLS`: Enable GnuTLS for SSL/TLS. Default: `OFF` | |
| - `CURL_USE_GSASL`: Use libgsasl. Default: `OFF` | |
| - `CURL_USE_GSSAPI`: Use GSSAPI implementation. Default: `OFF` | |
| @@ -383,6 +384,11 @@ Details via CMake | |
| - `ZLIB_INCLUDE_DIR`: Absolute path to zlib include directory. | |
| - `ZLIB_LIBRARY`: Absolute path to `zlib` library. | |
| - `ZLIB_USE_STATIC_LIBS`: Look for static `zlib` library (requires CMake v3.24). | |
| + | - `<PackageName>_DIR`: Absolute path to `<PackageName>` CMake Config directory where `*.cmake` files reside. Used when `CURL_USE_CMAKECONFIG` is enabled. |
| + | `<PackageName>` may be: |
| + | `Libssh2`, `MbedTLS`, `NGHTTP2`, `NGHTTP3`, |
| + | `NGTCP2` 1.19.0+ (with non-fork OpenSSL only), |
| + | `Zstd` 1.4.5+. |
| ## Dependency options (tools) | |
| @@ -92,7 +92,8 @@ elseif(TEST_INTEGRATION_MODE STREQUAL "ExternalProject") | |
| URL "${FROM_ARCHIVE}" URL_HASH "SHA256=${FROM_HASH}" | |
| ${_download_extract_timestamp} | |
| PREFIX "${CMAKE_BINARY_DIR}/curl-external" | |
| - | CMAKE_ARGS "-DCMAKE_INSTALL_PREFIX=${_curl_install_dir}" -DBUILD_SHARED_LIBS=OFF -DCURL_USE_LIBPSL=OFF -DCURL_USE_PKGCONFIG=OFF |
| + | CMAKE_ARGS "-DCMAKE_INSTALL_PREFIX=${_curl_install_dir}" -DBUILD_SHARED_LIBS=OFF -DCURL_USE_LIBPSL=OFF |
| + | -DCURL_USE_CMAKECONFIG=OFF -DCURL_USE_PKGCONFIG=OFF |
| -DCURL_ENABLE_SSL=OFF -DCURL_ENABLE_SSL=OFF -DCURL_DISABLE_LDAP=ON -DCURL_USE_LIBSSH2=OFF -DUSE_NGHTTP2=OFF | |
| -DCURL_BROTLI=OFF -DCURL_ZLIB=OFF -DCURL_ZSTD=OFF -DUSE_LIBIDN2=OFF -DENABLE_IPV6=OFF | |
| ${CURL_TEST_OPTS} | |