cmake: drop support for CMake 3.17 and older

Require CMake 3.18 (2020-07-15) or newer, up from 3.7 (2016-11-11)
prior to this patch.

This requirement also applies to the distributed `curl-config.cmake`.

To allow dropping compatibility code maintained for old versions, and to
use features which were unpractical in separate code paths. Also to make
testing, documentation and development easier, CI builds faster due to
CMake performance improvements over time. (e.g. integration tests on
macOS run 8x faster (10 minutes is now under 1.5m) in CI, 2.5x faster on
Windows.)

CMake offers pre-built binaries for major platforms. They work without
an install step, just by unpacking and pointing the cmake command to
them. Making upgrades easy in many cases:
https://cmake.org/download/
https://cmake.org/files/
https://github.com/Kitware/CMake/releases

CMake 3.18 brings these feature as generally available when building or
consuming curl/libcurl:

LTO support, improved performance, `pkg-config` and interface target
support, `OBJECT` target (for faster libcurl builds), modern invocation
with `-S`/`-B` options, better support for custom linker options,
FetchContent, `GnuTLS::GnuTLS` target, `--verbose` and `--install`
options, `CMAKE_GENERATOR` env, last but not least unity mode and Ninja
generator.

For maximum build speed, use:
`-DCMAKE_UNITY_BUILD=ON -DCURL_DROP_UNUSED=ON`

As for deprecations, C++11 is required to build CMake itself, which may
be a limit on some platforms. autotools continues to cover them.

Follow-up to 9bcdfb3809 #20408
Follow-up to a7c974e038 #19902
Follow-up to dfbe035c8b #10161
Discussion: https://github.com/curl/curl/discussions/18704

Closes #20407
This commit is contained in:
Viktor Szakats 2025-11-26 19:07:19 +01:00
parent d5014a2b95
commit 89043ba906
No known key found for this signature in database
35 changed files with 75 additions and 348 deletions

View File

@ -69,7 +69,7 @@ jobs:
sha256sum freexian-archive-keyring_2022.06.08_all.deb && dpkg -i freexian-archive-keyring_2022.06.08_all.deb sha256sum freexian-archive-keyring_2022.06.08_all.deb && dpkg -i freexian-archive-keyring_2022.06.08_all.deb
echo 'deb http://deb.freexian.com/extended-lts stretch-lts main contrib non-free' | tee /etc/apt/sources.list.d/extended-lts.list echo 'deb http://deb.freexian.com/extended-lts stretch-lts main contrib non-free' | tee /etc/apt/sources.list.d/extended-lts.list
apt-get -o Dpkg::Use-Pty=0 update apt-get -o Dpkg::Use-Pty=0 update
apt-get -o Dpkg::Use-Pty=0 install -y --no-install-suggests --no-install-recommends make automake autoconf libtool gcc pkg-config libpsl-dev libzstd-dev zlib1g-dev libc-ares-dev libkrb5-dev libldap2-dev librtmp-dev stunnel4 apt-get -o Dpkg::Use-Pty=0 install -y --no-install-suggests --no-install-recommends make automake autoconf libtool ninja-build gcc pkg-config libpsl-dev libzstd-dev zlib1g-dev libc-ares-dev libkrb5-dev libldap2-dev librtmp-dev stunnel4
# GitHub's actions/checkout needs newer glibc and libstdc++. The latter also depends on # GitHub's actions/checkout needs newer glibc and libstdc++. The latter also depends on
# gcc-8-base, but it does not actually seem used in our situation and is not available in # gcc-8-base, but it does not actually seem used in our situation and is not available in
# the main repo, so force the install. # the main repo, so force the install.
@ -79,8 +79,8 @@ jobs:
- name: 'install prereqs (cmake)' - name: 'install prereqs (cmake)'
env: env:
CMAKE_VERSION: 3.7.0 # Earliest version supported by curl CMAKE_VERSION: 3.18.0 # Earliest version supported by curl
CMAKE_SHA256: e075f63e6a9104b1c3d11666ae9546bc8812f7e791a49c4ce11effc063141b2a CMAKE_SHA256: 4d9a9d3351161073a67e49366d701b6fa4b0343781982dc5eef08a02a750d403
run: | run: |
cd ~ cd ~
fn="cmake-${CMAKE_VERSION}-linux-x86_64" fn="cmake-${CMAKE_VERSION}-linux-x86_64"
@ -94,13 +94,13 @@ jobs:
- name: 'CM build-only configure (out-of-tree)' - name: 'CM build-only configure (out-of-tree)'
run: | run: |
mkdir bld-1 ~/cmake/bin/cmake -B bld-1 -G Ninja -DCMAKE_UNITY_BUILD=ON -DCURL_WERROR=ON -DBUILD_SHARED_LIBS=ON \
cd bld-1
~/cmake/bin/cmake .. -DCMAKE_UNITY_BUILD=ON -DCURL_WERROR=ON -DBUILD_SHARED_LIBS=ON \
-DCURL_ENABLE_SSL=OFF -DENABLE_ARES=OFF -DCURL_ZSTD=OFF -DCURL_USE_GSSAPI=OFF -DCURL_USE_LIBSSH2=OFF -DCURL_USE_LIBSSH=OFF -DUSE_LIBRTMP=ON -DCURL_ENABLE_SSL=OFF -DENABLE_ARES=OFF -DCURL_ZSTD=OFF -DCURL_USE_GSSAPI=OFF -DCURL_USE_LIBSSH2=OFF -DCURL_USE_LIBSSH=OFF -DUSE_LIBRTMP=ON
- name: 'CM build-only build' - name: 'CM build-only build'
run: VERBOSE=1 make -C bld-1 install run: |
~/cmake/bin/cmake --build bld-1 --verbose
~/cmake/bin/cmake --install bld-1 --verbose
- name: 'CM build-only curl -V' - name: 'CM build-only curl -V'
run: bld-1/src/curl --disable --version run: bld-1/src/curl --disable --version
@ -118,9 +118,7 @@ jobs:
# that enabled again # that enabled again
- name: 'CM configure (out-of-tree, c-ares, zstd, gssapi)' - name: 'CM configure (out-of-tree, c-ares, zstd, gssapi)'
run: | run: |
mkdir bld-cares ~/cmake/bin/cmake -B bld-cares -G Ninja -DCMAKE_UNITY_BUILD=ON -DCURL_WERROR=ON -DBUILD_SHARED_LIBS=ON \
cd bld-cares
~/cmake/bin/cmake .. -DCMAKE_UNITY_BUILD=ON -DCURL_WERROR=ON -DBUILD_SHARED_LIBS=ON \
-DCURL_ENABLE_SSL=OFF -DENABLE_ARES=ON -DCURL_USE_GSSAPI=ON -DCURL_USE_LIBSSH2=OFF -DCURL_USE_LIBSSH=OFF -DUSE_LIBRTMP=ON \ -DCURL_ENABLE_SSL=OFF -DENABLE_ARES=ON -DCURL_USE_GSSAPI=ON -DCURL_USE_LIBSSH2=OFF -DCURL_USE_LIBSSH=OFF -DUSE_LIBRTMP=ON \
-DCURL_LIBCURL_VERSIONED_SYMBOLS=ON -DCURL_LIBCURL_VERSIONED_SYMBOLS=ON
@ -134,22 +132,22 @@ jobs:
grep -F '#define' bld-cares/lib/curl_config.h | sort || true grep -F '#define' bld-cares/lib/curl_config.h | sort || true
- name: 'CM build' - name: 'CM build'
run: make -C bld-cares run: ~/cmake/bin/cmake --build bld-cares
- name: 'CM curl -V' - name: 'CM curl -V'
run: bld-cares/src/curl --disable --version run: bld-cares/src/curl --disable --version
- name: 'CM install' - name: 'CM install'
run: make -C bld-cares install run: ~/cmake/bin/cmake --install bld-cares
- name: 'CM build tests' - name: 'CM build tests'
run: make -C bld-cares testdeps run: ~/cmake/bin/cmake --build bld-cares --target testdeps
- name: 'CM run tests' - name: 'CM run tests'
run: make -C bld-cares test-ci run: ~/cmake/bin/cmake --build bld-cares --target test-ci
- name: 'CM build examples' - name: 'CM build examples'
run: make -C bld-cares curl-examples-build run: ~/cmake/bin/cmake --build bld-cares --target curl-examples-build
- name: 'AM autoreconf' - name: 'AM autoreconf'
run: autoreconf -fi run: autoreconf -fi

View File

@ -84,10 +84,6 @@ else()
endif() endif()
if(BROTLI_FOUND) if(BROTLI_FOUND)
if(CMAKE_VERSION VERSION_LESS 3.13)
link_directories(${_brotli_LIBRARY_DIRS})
endif()
if(NOT TARGET CURL::brotli) if(NOT TARGET CURL::brotli)
add_library(CURL::brotli INTERFACE IMPORTED) add_library(CURL::brotli INTERFACE IMPORTED)
set_target_properties(CURL::brotli PROPERTIES set_target_properties(CURL::brotli PROPERTIES

View File

@ -106,10 +106,6 @@ if(CARES_FOUND)
list(APPEND _cares_LIBRARIES "iphlpapi") # for if_indextoname and others list(APPEND _cares_LIBRARIES "iphlpapi") # for if_indextoname and others
endif() endif()
if(CMAKE_VERSION VERSION_LESS 3.13)
link_directories(${_cares_LIBRARY_DIRS})
endif()
if(NOT TARGET CURL::cares) if(NOT TARGET CURL::cares)
add_library(CURL::cares INTERFACE IMPORTED) add_library(CURL::cares INTERFACE IMPORTED)
set_target_properties(CURL::cares PROPERTIES set_target_properties(CURL::cares PROPERTIES

View File

@ -258,10 +258,6 @@ mark_as_advanced(
) )
if(GSS_FOUND) if(GSS_FOUND)
if(CMAKE_VERSION VERSION_LESS 3.13)
link_directories(${_gss_LIBRARY_DIRS})
endif()
if(NOT TARGET CURL::gss) if(NOT TARGET CURL::gss)
add_library(CURL::gss INTERFACE IMPORTED) add_library(CURL::gss INTERFACE IMPORTED)
set_target_properties(CURL::gss PROPERTIES set_target_properties(CURL::gss PROPERTIES

View File

@ -80,10 +80,6 @@ else()
endif() endif()
if(GNUTLS_FOUND) if(GNUTLS_FOUND)
if(CMAKE_VERSION VERSION_LESS 3.13)
link_directories(${_gnutls_LIBRARY_DIRS})
endif()
if(NOT TARGET CURL::gnutls) if(NOT TARGET CURL::gnutls)
add_library(CURL::gnutls INTERFACE IMPORTED) add_library(CURL::gnutls INTERFACE IMPORTED)
set_target_properties(CURL::gnutls PROPERTIES set_target_properties(CURL::gnutls PROPERTIES

View File

@ -103,10 +103,6 @@ else()
endif() endif()
if(LDAP_FOUND) if(LDAP_FOUND)
if(CMAKE_VERSION VERSION_LESS 3.13)
link_directories(${_ldap_LIBRARY_DIRS})
endif()
if(NOT TARGET CURL::ldap) if(NOT TARGET CURL::ldap)
add_library(CURL::ldap INTERFACE IMPORTED) add_library(CURL::ldap INTERFACE IMPORTED)
set_target_properties(CURL::ldap PROPERTIES set_target_properties(CURL::ldap PROPERTIES

View File

@ -47,10 +47,6 @@ if(LIBBACKTRACE_FOUND)
set(_libbacktrace_INCLUDE_DIRS ${LIBBACKTRACE_INCLUDE_DIR}) set(_libbacktrace_INCLUDE_DIRS ${LIBBACKTRACE_INCLUDE_DIR})
set(_libbacktrace_LIBRARIES ${LIBBACKTRACE_LIBRARY}) set(_libbacktrace_LIBRARIES ${LIBBACKTRACE_LIBRARY})
if(CMAKE_VERSION VERSION_LESS 3.13)
link_directories(${_libbacktrace_LIBRARY_DIRS})
endif()
if(NOT TARGET CURL::libbacktrace) if(NOT TARGET CURL::libbacktrace)
add_library(CURL::libbacktrace INTERFACE IMPORTED) add_library(CURL::libbacktrace INTERFACE IMPORTED)
set_target_properties(CURL::libbacktrace PROPERTIES set_target_properties(CURL::libbacktrace PROPERTIES

View File

@ -79,10 +79,6 @@ else()
endif() endif()
if(LIBGSASL_FOUND) if(LIBGSASL_FOUND)
if(CMAKE_VERSION VERSION_LESS 3.13)
link_directories(${_libgsasl_LIBRARY_DIRS})
endif()
if(NOT TARGET CURL::libgsasl) if(NOT TARGET CURL::libgsasl)
add_library(CURL::libgsasl INTERFACE IMPORTED) add_library(CURL::libgsasl INTERFACE IMPORTED)
set_target_properties(CURL::libgsasl PROPERTIES set_target_properties(CURL::libgsasl PROPERTIES

View File

@ -80,10 +80,6 @@ else()
endif() endif()
if(LIBIDN2_FOUND) if(LIBIDN2_FOUND)
if(CMAKE_VERSION VERSION_LESS 3.13)
link_directories(${_libidn2_LIBRARY_DIRS})
endif()
if(NOT TARGET CURL::libidn2) if(NOT TARGET CURL::libidn2)
add_library(CURL::libidn2 INTERFACE IMPORTED) add_library(CURL::libidn2 INTERFACE IMPORTED)
set_target_properties(CURL::libidn2 PROPERTIES set_target_properties(CURL::libidn2 PROPERTIES

View File

@ -80,10 +80,6 @@ else()
endif() endif()
if(LIBPSL_FOUND) if(LIBPSL_FOUND)
if(CMAKE_VERSION VERSION_LESS 3.13)
link_directories(${_libpsl_LIBRARY_DIRS})
endif()
if(NOT TARGET CURL::libpsl) if(NOT TARGET CURL::libpsl)
add_library(CURL::libpsl INTERFACE IMPORTED) add_library(CURL::libpsl INTERFACE IMPORTED)
set_target_properties(CURL::libpsl PROPERTIES set_target_properties(CURL::libpsl PROPERTIES

View File

@ -58,14 +58,8 @@ else()
file(STRINGS "${LIBRTMP_INCLUDE_DIR}/librtmp/rtmp.h" _version_str REGEX "${_version_regex}") file(STRINGS "${LIBRTMP_INCLUDE_DIR}/librtmp/rtmp.h" _version_str REGEX "${_version_regex}")
string(REGEX REPLACE "${_version_regex}" "\\1" _version_str1 "${_version_str}") string(REGEX REPLACE "${_version_regex}" "\\1" _version_str1 "${_version_str}")
string(REGEX REPLACE "${_version_regex}" "\\2" _version_str2 "${_version_str}") string(REGEX REPLACE "${_version_regex}" "\\2" _version_str2 "${_version_str}")
if(CMAKE_VERSION VERSION_LESS 3.13) math(EXPR _version_str1 "0x${_version_str1}" OUTPUT_FORMAT DECIMAL)
# No support for hex version numbers, just strip leading zeroes math(EXPR _version_str2 "0x${_version_str2}" OUTPUT_FORMAT DECIMAL)
string(REGEX REPLACE "^0" "" _version_str1 "${_version_str1}")
string(REGEX REPLACE "^0" "" _version_str2 "${_version_str2}")
else()
math(EXPR _version_str1 "0x${_version_str1}" OUTPUT_FORMAT DECIMAL)
math(EXPR _version_str2 "0x${_version_str2}" OUTPUT_FORMAT DECIMAL)
endif()
set(LIBRTMP_VERSION "${_version_str1}.${_version_str2}") set(LIBRTMP_VERSION "${_version_str1}.${_version_str2}")
unset(_version_regex) unset(_version_regex)
unset(_version_str1) unset(_version_str1)
@ -100,10 +94,6 @@ if(LIBRTMP_FOUND)
list(APPEND _librtmp_LIBRARIES "winmm") list(APPEND _librtmp_LIBRARIES "winmm")
endif() endif()
if(CMAKE_VERSION VERSION_LESS 3.13)
link_directories(${_librtmp_LIBRARY_DIRS})
endif()
if(NOT TARGET CURL::librtmp) if(NOT TARGET CURL::librtmp)
add_library(CURL::librtmp INTERFACE IMPORTED) add_library(CURL::librtmp INTERFACE IMPORTED)
set_target_properties(CURL::librtmp PROPERTIES set_target_properties(CURL::librtmp PROPERTIES

View File

@ -106,10 +106,6 @@ if(LIBSSH_FOUND)
list(APPEND _libssh_LIBRARIES "iphlpapi") # for if_nametoindex list(APPEND _libssh_LIBRARIES "iphlpapi") # for if_nametoindex
endif() endif()
if(CMAKE_VERSION VERSION_LESS 3.13)
link_directories(${_libssh_LIBRARY_DIRS})
endif()
if(NOT TARGET CURL::libssh) if(NOT TARGET CURL::libssh)
add_library(CURL::libssh INTERFACE IMPORTED) add_library(CURL::libssh INTERFACE IMPORTED)
set_target_properties(CURL::libssh PROPERTIES set_target_properties(CURL::libssh PROPERTIES

View File

@ -91,10 +91,6 @@ else()
endif() endif()
if(LIBSSH2_FOUND) if(LIBSSH2_FOUND)
if(CMAKE_VERSION VERSION_LESS 3.13)
link_directories(${_libssh2_LIBRARY_DIRS})
endif()
if(NOT TARGET CURL::libssh2) if(NOT TARGET CURL::libssh2)
add_library(CURL::libssh2 INTERFACE IMPORTED) add_library(CURL::libssh2 INTERFACE IMPORTED)
set_target_properties(CURL::libssh2 PROPERTIES set_target_properties(CURL::libssh2 PROPERTIES

View File

@ -90,10 +90,6 @@ else()
endif() endif()
if(LIBUV_FOUND) if(LIBUV_FOUND)
if(CMAKE_VERSION VERSION_LESS 3.13)
link_directories(${_libuv_LIBRARY_DIRS})
endif()
if(NOT TARGET CURL::libuv) if(NOT TARGET CURL::libuv)
add_library(CURL::libuv INTERFACE IMPORTED) add_library(CURL::libuv INTERFACE IMPORTED)
set_target_properties(CURL::libuv PROPERTIES set_target_properties(CURL::libuv PROPERTIES

View File

@ -110,10 +110,6 @@ else()
endif() endif()
if(MBEDTLS_FOUND) if(MBEDTLS_FOUND)
if(CMAKE_VERSION VERSION_LESS 3.13)
link_directories(${_mbedtls_LIBRARY_DIRS})
endif()
if(NOT TARGET CURL::mbedtls) if(NOT TARGET CURL::mbedtls)
add_library(CURL::mbedtls INTERFACE IMPORTED) add_library(CURL::mbedtls INTERFACE IMPORTED)
set_target_properties(CURL::mbedtls PROPERTIES set_target_properties(CURL::mbedtls PROPERTIES

View File

@ -91,10 +91,6 @@ else()
endif() endif()
if(NGHTTP2_FOUND) if(NGHTTP2_FOUND)
if(CMAKE_VERSION VERSION_LESS 3.13)
link_directories(${_nghttp2_LIBRARY_DIRS})
endif()
if(NOT TARGET CURL::nghttp2) if(NOT TARGET CURL::nghttp2)
add_library(CURL::nghttp2 INTERFACE IMPORTED) add_library(CURL::nghttp2 INTERFACE IMPORTED)
set_target_properties(CURL::nghttp2 PROPERTIES set_target_properties(CURL::nghttp2 PROPERTIES

View File

@ -91,10 +91,6 @@ else()
endif() endif()
if(NGHTTP3_FOUND) if(NGHTTP3_FOUND)
if(CMAKE_VERSION VERSION_LESS 3.13)
link_directories(${_nghttp3_LIBRARY_DIRS})
endif()
if(NOT TARGET CURL::nghttp3) if(NOT TARGET CURL::nghttp3)
add_library(CURL::nghttp3 INTERFACE IMPORTED) add_library(CURL::nghttp3 INTERFACE IMPORTED)
set_target_properties(CURL::nghttp3 PROPERTIES set_target_properties(CURL::nghttp3 PROPERTIES

View File

@ -155,10 +155,6 @@ else()
endif() endif()
if(NGTCP2_FOUND) if(NGTCP2_FOUND)
if(CMAKE_VERSION VERSION_LESS 3.13)
link_directories(${_ngtcp2_LIBRARY_DIRS})
endif()
if(NOT TARGET CURL::ngtcp2) if(NOT TARGET CURL::ngtcp2)
add_library(CURL::ngtcp2 INTERFACE IMPORTED) add_library(CURL::ngtcp2 INTERFACE IMPORTED)
set_target_properties(CURL::ngtcp2 PROPERTIES set_target_properties(CURL::ngtcp2 PROPERTIES

View File

@ -85,10 +85,6 @@ else()
endif() endif()
if(NETTLE_FOUND) if(NETTLE_FOUND)
if(CMAKE_VERSION VERSION_LESS 3.13)
link_directories(${_nettle_LIBRARY_DIRS})
endif()
if(NOT TARGET CURL::nettle) if(NOT TARGET CURL::nettle)
add_library(CURL::nettle INTERFACE IMPORTED) add_library(CURL::nettle INTERFACE IMPORTED)
set_target_properties(CURL::nettle PROPERTIES set_target_properties(CURL::nettle PROPERTIES

View File

@ -68,10 +68,6 @@ else()
endif() endif()
if(QUICHE_FOUND) if(QUICHE_FOUND)
if(CMAKE_VERSION VERSION_LESS 3.13)
link_directories(${_quiche_LIBRARY_DIRS})
endif()
if(NOT TARGET CURL::quiche) if(NOT TARGET CURL::quiche)
add_library(CURL::quiche INTERFACE IMPORTED) add_library(CURL::quiche INTERFACE IMPORTED)
set_target_properties(CURL::quiche PROPERTIES set_target_properties(CURL::quiche PROPERTIES

View File

@ -104,10 +104,6 @@ if(RUSTLS_FOUND)
mark_as_advanced(MATH_LIBRARY) mark_as_advanced(MATH_LIBRARY)
endif() endif()
if(CMAKE_VERSION VERSION_LESS 3.13)
link_directories(${_rustls_LIBRARY_DIRS})
endif()
if(NOT TARGET CURL::rustls) if(NOT TARGET CURL::rustls)
add_library(CURL::rustls INTERFACE IMPORTED) add_library(CURL::rustls INTERFACE IMPORTED)
set_target_properties(CURL::rustls PROPERTIES set_target_properties(CURL::rustls PROPERTIES

View File

@ -113,10 +113,6 @@ if(WOLFSSL_FOUND)
mark_as_advanced(MATH_LIBRARY) mark_as_advanced(MATH_LIBRARY)
endif() endif()
if(CMAKE_VERSION VERSION_LESS 3.13)
link_directories(${_wolfssl_LIBRARY_DIRS})
endif()
if(NOT TARGET CURL::wolfssl) if(NOT TARGET CURL::wolfssl)
add_library(CURL::wolfssl INTERFACE IMPORTED) add_library(CURL::wolfssl INTERFACE IMPORTED)
set_target_properties(CURL::wolfssl PROPERTIES set_target_properties(CURL::wolfssl PROPERTIES

View File

@ -110,10 +110,6 @@ else()
endif() endif()
if(ZSTD_FOUND) if(ZSTD_FOUND)
if(CMAKE_VERSION VERSION_LESS 3.13)
link_directories(${_zstd_LIBRARY_DIRS})
endif()
if(NOT TARGET CURL::zstd) if(NOT TARGET CURL::zstd)
add_library(CURL::zstd INTERFACE IMPORTED) add_library(CURL::zstd INTERFACE IMPORTED)
set_target_properties(CURL::zstd PROPERTIES set_target_properties(CURL::zstd PROPERTIES

View File

@ -55,7 +55,7 @@ if("@HAVE_LIBZ@")
endif() endif()
set(_curl_cmake_module_path_save ${CMAKE_MODULE_PATH}) set(_curl_cmake_module_path_save ${CMAKE_MODULE_PATH})
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR} ${CMAKE_MODULE_PATH}) list(PREPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR})
set(_curl_libs "") set(_curl_libs "")
@ -158,35 +158,9 @@ include("${CMAKE_CURRENT_LIST_DIR}/@TARGETS_EXPORT_NAME@.cmake")
# Alias for either shared or static library # Alias for either shared or static library
if(NOT TARGET @PROJECT_NAME@::@LIB_NAME@) if(NOT TARGET @PROJECT_NAME@::@LIB_NAME@)
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.11 AND CMAKE_VERSION VERSION_LESS 3.18)
set_target_properties(@PROJECT_NAME@::@LIB_SELECTED@ PROPERTIES IMPORTED_GLOBAL TRUE)
endif()
add_library(@PROJECT_NAME@::@LIB_NAME@ ALIAS @PROJECT_NAME@::@LIB_SELECTED@) add_library(@PROJECT_NAME@::@LIB_NAME@ ALIAS @PROJECT_NAME@::@LIB_SELECTED@)
endif() endif()
if(TARGET @PROJECT_NAME@::@LIB_STATIC@)
# CMake before CMP0099 (CMake 3.17 2020-03-20) did not propagate libdirs to
# targets. It expected libs to have an absolute filename. As a workaround,
# manually apply dependency libdirs, for CMake consumers without this policy.
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.17)
cmake_policy(GET CMP0099 _has_CMP0099) # https://cmake.org/cmake/help/latest/policy/CMP0099.html
endif()
if(NOT _has_CMP0099 AND CMAKE_VERSION VERSION_GREATER_EQUAL 3.13 AND _curl_libs)
set(_curl_libdirs "")
foreach(_curl_lib IN LISTS _curl_libs)
if(TARGET "${_curl_lib}")
get_target_property(_curl_libdir "${_curl_lib}" INTERFACE_LINK_DIRECTORIES)
if(_curl_libdir)
list(APPEND _curl_libdirs "${_curl_libdir}")
endif()
endif()
endforeach()
if(_curl_libdirs)
target_link_directories(@PROJECT_NAME@::@LIB_STATIC@ INTERFACE ${_curl_libdirs})
endif()
endif()
endif()
# For compatibility with CMake's FindCURL.cmake # For compatibility with CMake's FindCURL.cmake
set(CURL_VERSION_STRING "@CURLVERSION@") set(CURL_VERSION_STRING "@CURLVERSION@")
set(CURL_LIBRARIES @PROJECT_NAME@::@LIB_NAME@) set(CURL_LIBRARIES @PROJECT_NAME@::@LIB_NAME@)

View File

@ -22,7 +22,7 @@
# #
########################################################################### ###########################################################################
cmake_minimum_required(VERSION 3.7...3.16 FATAL_ERROR) cmake_minimum_required(VERSION 3.18 FATAL_ERROR)
message(STATUS "Using CMake version ${CMAKE_VERSION}") message(STATUS "Using CMake version ${CMAKE_VERSION}")
# Collect command-line arguments for buildinfo.txt. # Collect command-line arguments for buildinfo.txt.
@ -45,7 +45,7 @@ if(NOT "$ENV{CURL_BUILDINFO}$ENV{CURL_CI}$ENV{CI}" STREQUAL "")
endforeach() endforeach()
endif() endif()
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake" ${CMAKE_MODULE_PATH}) list(PREPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake")
include(Utilities) include(Utilities)
include(Macros) include(Macros)
include(CMakeDependentOption) include(CMakeDependentOption)
@ -324,18 +324,10 @@ set(CURL_CFLAGS "") # C flags set for libcurl and curl tool (aka public binarie
option(CURL_DROP_UNUSED "Drop unused code and data from built binaries" OFF) option(CURL_DROP_UNUSED "Drop unused code and data from built binaries" OFF)
if(CURL_DROP_UNUSED) if(CURL_DROP_UNUSED)
if(APPLE) if(APPLE)
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.13) set_property(DIRECTORY APPEND PROPERTY LINK_OPTIONS "-Wl,-dead_strip")
set_property(DIRECTORY APPEND PROPERTY LINK_OPTIONS "-Wl,-dead_strip")
else()
set_property(DIRECTORY APPEND PROPERTY LINK_FLAGS "-Wl,-dead_strip")
endif()
elseif(MSVC) # Options below are toolchain defaults in Release configurations. elseif(MSVC) # Options below are toolchain defaults in Release configurations.
# This option does not seem to have an effect with VS2010: # This option does not seem to have an effect with VS2010:
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.13) set_property(DIRECTORY APPEND PROPERTY LINK_OPTIONS "-OPT:REF")
set_property(DIRECTORY APPEND PROPERTY LINK_OPTIONS "-OPT:REF")
else()
set_property(DIRECTORY APPEND PROPERTY LINK_FLAGS "-OPT:REF")
endif()
# Optional, but reduces binary size further, with the cost of larger objects/static libraries: # Optional, but reduces binary size further, with the cost of larger objects/static libraries:
list(APPEND CURL_CFLAGS "-Gy") list(APPEND CURL_CFLAGS "-Gy")
elseif(CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID MATCHES "Clang") elseif(CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID MATCHES "Clang")
@ -343,11 +335,7 @@ if(CURL_DROP_UNUSED)
# To make -Wl,--gc-sections work on Windows: https://sourceware.org/bugzilla/show_bug.cgi?id=11539 # To make -Wl,--gc-sections work on Windows: https://sourceware.org/bugzilla/show_bug.cgi?id=11539
set_property(DIRECTORY APPEND PROPERTY COMPILE_OPTIONS "-fno-asynchronous-unwind-tables") set_property(DIRECTORY APPEND PROPERTY COMPILE_OPTIONS "-fno-asynchronous-unwind-tables")
endif() endif()
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.13) set_property(DIRECTORY APPEND PROPERTY LINK_OPTIONS "-Wl,--gc-sections")
set_property(DIRECTORY APPEND PROPERTY LINK_OPTIONS "-Wl,--gc-sections")
else()
set_property(DIRECTORY APPEND PROPERTY LINK_FLAGS "-Wl,--gc-sections")
endif()
# Optional, but reduces binary size further, with the cost of larger objects/static libraries: # Optional, but reduces binary size further, with the cost of larger objects/static libraries:
list(APPEND CURL_CFLAGS "-ffunction-sections" "-fdata-sections") list(APPEND CURL_CFLAGS "-ffunction-sections" "-fdata-sections")
endif() endif()
@ -678,7 +666,7 @@ elseif(AMIGA)
elseif(NOT WIN32 AND NOT APPLE) elseif(NOT WIN32 AND NOT APPLE)
check_library_exists("socket" "connect" "" HAVE_LIBSOCKET) check_library_exists("socket" "connect" "" HAVE_LIBSOCKET)
if(HAVE_LIBSOCKET) if(HAVE_LIBSOCKET)
set(CURL_NETWORK_AND_TIME_LIBS "socket" ${CURL_NETWORK_AND_TIME_LIBS}) list(PREPEND CURL_NETWORK_AND_TIME_LIBS "socket")
endif() endif()
endif() endif()
@ -1194,7 +1182,7 @@ if(NOT CURL_DISABLE_LDAP)
find_package(LDAP MODULE) find_package(LDAP MODULE)
if(LDAP_FOUND) if(LDAP_FOUND)
set(HAVE_LBER_H 1) set(HAVE_LBER_H 1)
set(CURL_LIBS CURL::ldap ${CURL_LIBS}) list(PREPEND CURL_LIBS CURL::ldap)
# LDAP feature checks # LDAP feature checks
@ -1261,7 +1249,7 @@ set(HAVE_LIBIDN2 OFF)
if(USE_LIBIDN2 AND NOT USE_APPLE_IDN AND NOT USE_WIN32_IDN) if(USE_LIBIDN2 AND NOT USE_APPLE_IDN AND NOT USE_WIN32_IDN)
find_package(Libidn2 MODULE) find_package(Libidn2 MODULE)
if(LIBIDN2_FOUND) if(LIBIDN2_FOUND)
set(CURL_LIBS CURL::libidn2 ${CURL_LIBS}) list(PREPEND CURL_LIBS CURL::libidn2)
set(HAVE_IDN2_H 1) set(HAVE_IDN2_H 1)
set(HAVE_LIBIDN2 1) set(HAVE_LIBIDN2 1)
endif() endif()
@ -1284,7 +1272,7 @@ set(USE_LIBSSH2 OFF)
if(CURL_USE_LIBSSH2) if(CURL_USE_LIBSSH2)
find_package(Libssh2 MODULE) find_package(Libssh2 MODULE)
if(LIBSSH2_FOUND) if(LIBSSH2_FOUND)
set(CURL_LIBS CURL::libssh2 ${CURL_LIBS}) # keep it before TLS-crypto, compression list(PREPEND CURL_LIBS CURL::libssh2) # keep it before TLS-crypto, compression
set(USE_LIBSSH2 ON) set(USE_LIBSSH2 ON)
endif() endif()
endif() endif()
@ -1294,7 +1282,7 @@ option(CURL_USE_LIBSSH "Use libssh" OFF)
mark_as_advanced(CURL_USE_LIBSSH) mark_as_advanced(CURL_USE_LIBSSH)
if(NOT USE_LIBSSH2 AND CURL_USE_LIBSSH) if(NOT USE_LIBSSH2 AND CURL_USE_LIBSSH)
find_package(Libssh MODULE REQUIRED) find_package(Libssh MODULE REQUIRED)
set(CURL_LIBS CURL::libssh ${CURL_LIBS}) # keep it before TLS-crypto, compression list(PREPEND CURL_LIBS CURL::libssh) # keep it before TLS-crypto, compression
set(USE_LIBSSH ON) set(USE_LIBSSH ON)
endif() endif()
@ -1870,12 +1858,6 @@ if(CMAKE_C_COMPILER_ID STREQUAL "MSVC") # MSVC but exclude clang-cl
endif() endif()
if(CURL_LTO) if(CURL_LTO)
if(CMAKE_VERSION VERSION_LESS 3.9)
message(FATAL_ERROR "LTO has been requested, but your cmake version ${CMAKE_VERSION} is to old. You need at least 3.9")
endif()
cmake_policy(SET CMP0069 NEW)
include(CheckIPOSupported) include(CheckIPOSupported)
check_ipo_supported(RESULT CURL_HAS_LTO OUTPUT _lto_error LANGUAGES C) check_ipo_supported(RESULT CURL_HAS_LTO OUTPUT _lto_error LANGUAGES C)
if(CURL_HAS_LTO) if(CURL_HAS_LTO)
@ -2051,11 +2033,7 @@ curl_add_if("SSLS-EXPORT" _ssl_enabled AND USE_SSLS_EXPORT)
curl_add_if("AppleSecTrust" USE_APPLE_SECTRUST AND _ssl_enabled AND (USE_OPENSSL OR USE_GNUTLS)) curl_add_if("AppleSecTrust" USE_APPLE_SECTRUST AND _ssl_enabled AND (USE_OPENSSL OR USE_GNUTLS))
curl_add_if("NativeCA" NOT USE_APPLE_SECTRUST AND _ssl_enabled AND CURL_CA_NATIVE) curl_add_if("NativeCA" NOT USE_APPLE_SECTRUST AND _ssl_enabled AND CURL_CA_NATIVE)
if(_items) if(_items)
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.13) list(SORT _items CASE INSENSITIVE)
list(SORT _items CASE INSENSITIVE)
else()
list(SORT _items)
endif()
endif() endif()
set(CURL_SUPPORTED_FEATURES_LIST "${_items}") set(CURL_SUPPORTED_FEATURES_LIST "${_items}")
string(REPLACE ";" " " SUPPORT_FEATURES "${_items}") string(REPLACE ";" " " SUPPORT_FEATURES "${_items}")
@ -2071,11 +2049,7 @@ curl_add_if("GnuTLS" _ssl_enabled AND USE_GNUTLS)
curl_add_if("Rustls" _ssl_enabled AND USE_RUSTLS) curl_add_if("Rustls" _ssl_enabled AND USE_RUSTLS)
if(_items) if(_items)
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.13) list(SORT _items CASE INSENSITIVE)
list(SORT _items CASE INSENSITIVE)
else()
list(SORT _items)
endif()
endif() endif()
string(REPLACE ";" " " SSL_BACKENDS "${_items}") string(REPLACE ";" " " SSL_BACKENDS "${_items}")
message(STATUS "Enabled SSL backends: ${SSL_BACKENDS}") message(STATUS "Enabled SSL backends: ${SSL_BACKENDS}")

View File

@ -70,28 +70,17 @@ if [ -n "${CMAKE_GENERATOR:-}" ]; then
[ "${_chkprefill}" = '_chkprefill' ] && options+=' -D_CURL_PREFILL=OFF' [ "${_chkprefill}" = '_chkprefill' ] && options+=' -D_CURL_PREFILL=OFF'
[[ "${CMAKE_GENERATE:-}" = *'-A ARM64'* ]] && SKIP_RUN='ARM64 architecture' [[ "${CMAKE_GENERATE:-}" = *'-A ARM64'* ]] && SKIP_RUN='ARM64 architecture'
[[ "${CMAKE_GENERATE:-}" = *'-DCURL_USE_OPENSSL=ON'* ]] && options+=" -DOPENSSL_ROOT_DIR=${openssl_root_win}" [[ "${CMAKE_GENERATE:-}" = *'-DCURL_USE_OPENSSL=ON'* ]] && options+=" -DOPENSSL_ROOT_DIR=${openssl_root_win}"
if [ "${APPVEYOR_BUILD_WORKER_IMAGE}" = 'Visual Studio 2013' ]; then
mkdir "_bld${_chkprefill}"
cd "_bld${_chkprefill}"
options+=' ..'
root='..'
else
options+=" -B _bld${_chkprefill}"
options+=' -DCMAKE_VS_GLOBALS=TrackFileAccess=false'
options+=' -DCMAKE_UNITY_BUILD=ON'
root='.'
fi
# CMAKE_GENERATOR env requires CMake 3.15+, pass it manually to make it work with older versions.
# shellcheck disable=SC2086 # shellcheck disable=SC2086
time cmake -G "${CMAKE_GENERATOR}" \ time cmake -B "_bld${_chkprefill}" \
-DENABLE_DEBUG=ON -DCURL_WERROR=ON \ -DENABLE_DEBUG=ON \
-DCMAKE_UNITY_BUILD=ON -DCURL_WERROR=ON \
-DCMAKE_VS_GLOBALS=TrackFileAccess=false \
-DCURL_STATIC_CRT=ON \ -DCURL_STATIC_CRT=ON \
-DCURL_DROP_UNUSED=ON \ -DCURL_DROP_UNUSED=ON \
-DCURL_USE_SCHANNEL=ON -DCURL_USE_LIBPSL=OFF \ -DCURL_USE_SCHANNEL=ON -DCURL_USE_LIBPSL=OFF \
${options} \
${CMAKE_GENERATE:-} \ ${CMAKE_GENERATE:-} \
|| { cat "${root}"/_bld/CMakeFiles/CMake* 2>/dev/null; false; } ${options} \
[ "${APPVEYOR_BUILD_WORKER_IMAGE}" = 'Visual Studio 2013' ] && cd .. || { cat _bld/CMakeFiles/CMake* 2>/dev/null; false; }
done done
if [ -d _bld_chkprefill ] && ! diff -u _bld/lib/curl_config.h _bld_chkprefill/lib/curl_config.h; then if [ -d _bld_chkprefill ] && ! diff -u _bld/lib/curl_config.h _bld_chkprefill/lib/curl_config.h; then
cat _bld_chkprefill/CMakeFiles/CMake* 2>/dev/null || true cat _bld_chkprefill/CMakeFiles/CMake* 2>/dev/null || true

View File

@ -45,12 +45,16 @@ environment:
CMAKE_GENERATE: '-A ARM64 -DENABLE_DEBUG=OFF -DBUILD_SHARED_LIBS=OFF' CMAKE_GENERATE: '-A ARM64 -DENABLE_DEBUG=OFF -DBUILD_SHARED_LIBS=OFF'
- job_name: 'CM VS2010, Debug, x64, Schannel, Shared, Build-tests & examples' - job_name: 'CM VS2010, Debug, x64, Schannel, Shared, Build-tests & examples'
APPVEYOR_BUILD_WORKER_IMAGE: 'Visual Studio 2013' APPVEYOR_BUILD_WORKER_IMAGE: 'Visual Studio 2015'
CMAKE_VERSION: 3.18.4
CMAKE_SHA256: a932bc0c8ee79f1003204466c525b38a840424d4ae29f9e5fb88959116f2407d
CMAKE_GENERATOR: 'Visual Studio 10 2010' CMAKE_GENERATOR: 'Visual Studio 10 2010'
CMAKE_GENERATE: '-A x64' CMAKE_GENERATE: '-A x64'
- job_name: 'CM VS2012, Release, x86, Schannel, Shared, Build-tests' - job_name: 'CM VS2012, Release, x86, Schannel, Shared, Build-tests'
APPVEYOR_BUILD_WORKER_IMAGE: 'Visual Studio 2015' APPVEYOR_BUILD_WORKER_IMAGE: 'Visual Studio 2015'
CMAKE_VERSION: 3.21.7
CMAKE_SHA256: 4c4840e2dc2bf82e8a16081ff506bba54f3a228b91ce36317129fed4035ef2e3
CMAKE_GENERATOR: 'Visual Studio 11 2012' CMAKE_GENERATOR: 'Visual Studio 11 2012'
CMAKE_GENERATE: '-A Win32' CMAKE_GENERATE: '-A Win32'

View File

@ -28,12 +28,6 @@ RTMP in curl is powered by the 3rd party library librtmp.
Support for RTMP in libcurl gets removed in April 2026. Support for RTMP in libcurl gets removed in April 2026.
## CMake 3.17 and earlier
We remove support for CMake <3.18 in April 2026.
CMake 3.18 was released on 2020-07-15.
## TLS-SRP Authentication ## TLS-SRP Authentication
Transport Layer Security Secure Remote Password is a TLS feature that does not Transport Layer Security Secure Remote Password is a TLS feature that does not
@ -78,3 +72,4 @@ After curl 8.19.0 NTLM support becomes opt-in.
- OpenSSL 1.1.1 and older (removed in 8.18.0) - OpenSSL 1.1.1 and older (removed in 8.18.0)
- Support for Windows XP (removed in 8.19.0) - Support for Windows XP (removed in 8.19.0)
- OpenSSL-QUIC (removed in 8.19.0) - OpenSSL-QUIC (removed in 8.19.0)
- CMake 3.17 and older (removed in 8.21.0)

View File

@ -43,20 +43,6 @@ that is apart from the source tree.
For the full list of CMake build configuration variables see For the full list of CMake build configuration variables see
[the corresponding section](#cmake-build-options). [the corresponding section](#cmake-build-options).
### Fallback for CMake before version 3.13
CMake before version 3.13 does not support the `-B` option. In that case,
you must create the build directory yourself, `cd` to it and run `cmake`
from there:
$ mkdir ../curl-build
$ cd ../curl-build
$ cmake ../curl
If you want to build in the source tree, it is enough to do this:
$ cmake .
### Build system generator selection ### Build system generator selection
You can override CMake's default by using `-G <generator-name>`. For example You can override CMake's default by using `-G <generator-name>`. For example

View File

@ -50,7 +50,7 @@ we use a few "build tools" and we make sure that we remain functional with
these versions: these versions:
- clang-tidy 17.0.0 (2023-09-19), recommended: 19.1.0 or later (2024-09-17) - clang-tidy 17.0.0 (2023-09-19), recommended: 19.1.0 or later (2024-09-17)
- cmake 3.7 (2016-11-11) - cmake 3.18 (2020-07-15)
- GNU autoconf 2.59 (2003-11-06) - GNU autoconf 2.59 (2003-11-06)
- GNU automake 1.7 (2002-09-25) - GNU automake 1.7 (2002-09-25)
- GNU libtool 1.4.2 (2001-09-11) - GNU libtool 1.4.2 (2001-09-11)

View File

@ -41,21 +41,13 @@ foreach(_target IN LISTS COMPLICATED_MAY_BUILD check_PROGRAMS _all) # keep 'COM
set(_more_libs "") set(_more_libs "")
set(_target_name "curl-example-${_target}") set(_target_name "curl-example-${_target}")
if(_target STREQUAL "all") if(_target STREQUAL "all")
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.12) add_library(${_target_name} OBJECT EXCLUDE_FROM_ALL ${_all_src})
add_library(${_target_name} OBJECT EXCLUDE_FROM_ALL ${_all_src}) if(CMAKE_C_COMPILER_ID STREQUAL "MSVC") # MSVC but exclude clang-cl
if(CMAKE_C_COMPILER_ID STREQUAL "MSVC") # MSVC but exclude clang-cl # CMake generates a static library for the OBJECT target. Silence these 'lib.exe' warnings:
# CMake generates a static library for the OBJECT target. Silence these 'lib.exe' warnings: # warning LNK4006: main already defined in ....obj; second definition ignored
# warning LNK4006: main already defined in ....obj; second definition ignored # warning LNK4221: This object file does not define any previously undefined public symbols,
# warning LNK4221: This object file does not define any previously undefined public symbols, # [...] not be used by any link operation that consumes this library
# [...] not be used by any link operation that consumes this library set_target_properties(${_target_name} PROPERTIES STATIC_LIBRARY_OPTIONS "-ignore:4006;-ignore:4221")
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.13)
set_target_properties(${_target_name} PROPERTIES STATIC_LIBRARY_OPTIONS "-ignore:4006;-ignore:4221")
else()
set_target_properties(${_target_name} PROPERTIES STATIC_LIBRARY_FLAGS "-ignore:4006 -ignore:4221")
endif()
endif()
else()
add_library(${_target_name} STATIC EXCLUDE_FROM_ALL ${_all_src})
endif() endif()
if(_with_deps) if(_with_deps)
set(_more_libs ${CURL_LIBS}) # If any examples required dependencies, link them set(_more_libs ${CURL_LIBS}) # If any examples required dependencies, link them

View File

@ -99,9 +99,9 @@ if(NOT DEFINED SHARE_LIB_OBJECT)
endif() endif()
endif() endif()
if(SHARE_LIB_OBJECT AND CMAKE_VERSION VERSION_GREATER_EQUAL 3.12) if(SHARE_LIB_OBJECT)
set(LIB_OBJECT "libcurl_object") set(LIB_OBJECT "libcurl_object")
add_library(${LIB_OBJECT} OBJECT ${HHEADERS} ${CSOURCES}) # Requires CMake 3.12 add_library(${LIB_OBJECT} OBJECT ${HHEADERS} ${CSOURCES})
if(WIN32) if(WIN32)
# Define CURL_STATICLIB always, to disable __declspec(dllexport) for # Define CURL_STATICLIB always, to disable __declspec(dllexport) for
# exported libcurl symbols. We handle exports via libcurl.def instead. # exported libcurl symbols. We handle exports via libcurl.def instead.
@ -194,27 +194,6 @@ if(BUILD_STATIC_LIBS)
target_include_directories(${LIB_STATIC} INTERFACE target_include_directories(${LIB_STATIC} INTERFACE
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>" "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>") "$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>")
# CMake before CMP0099 (CMake 3.17 2020-03-20) did not propagate libdirs to
# targets. It expected libs to have an absolute filename. As a workaround,
# manually apply dependency libdirs, for CMake consumers without this policy.
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.17)
cmake_policy(GET CMP0099 _has_CMP0099) # https://cmake.org/cmake/help/latest/policy/CMP0099.html
endif()
if(NOT _has_CMP0099 AND CMAKE_VERSION VERSION_GREATER_EQUAL 3.13 AND CURL_LIBS)
set(_curl_libdirs "")
foreach(_curl_lib IN LISTS CURL_LIBS)
if(TARGET "${_curl_lib}")
get_target_property(_curl_libdir "${_curl_lib}" INTERFACE_LINK_DIRECTORIES)
if(_curl_libdir)
list(APPEND _curl_libdirs "${_curl_libdir}")
endif()
endif()
endforeach()
if(_curl_libdirs)
target_link_directories(${LIB_STATIC} INTERFACE ${_curl_libdirs})
endif()
endif()
endif() endif()
if(BUILD_SHARED_LIBS) if(BUILD_SHARED_LIBS)
@ -258,11 +237,7 @@ if(BUILD_SHARED_LIBS)
if(CURL_CODE_COVERAGE) if(CURL_CODE_COVERAGE)
set_property(TARGET ${LIB_SHARED} APPEND PROPERTY COMPILE_DEFINITIONS ${CURL_COVERAGE_MACROS}) set_property(TARGET ${LIB_SHARED} APPEND PROPERTY COMPILE_DEFINITIONS ${CURL_COVERAGE_MACROS})
set_property(TARGET ${LIB_SHARED} APPEND PROPERTY COMPILE_OPTIONS ${CURL_COVERAGE_CFLAGS}) set_property(TARGET ${LIB_SHARED} APPEND PROPERTY COMPILE_OPTIONS ${CURL_COVERAGE_CFLAGS})
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.13) set_property(TARGET ${LIB_SHARED} APPEND PROPERTY LINK_OPTIONS ${CURL_COVERAGE_LDFLAGS})
set_property(TARGET ${LIB_SHARED} APPEND PROPERTY LINK_OPTIONS ${CURL_COVERAGE_LDFLAGS})
else()
set_property(TARGET ${LIB_SHARED} APPEND PROPERTY LINK_FLAGS ${CURL_COVERAGE_LDFLAGS})
endif()
endif() endif()
target_include_directories(${LIB_SHARED} INTERFACE target_include_directories(${LIB_SHARED} INTERFACE
@ -337,11 +312,7 @@ if(BUILD_SHARED_LIBS)
set(CMAKE_REQUIRED_LINK_OPTIONS "-Wl,--version-script=${CMAKE_CURRENT_BINARY_DIR}/libcurl.vers") set(CMAKE_REQUIRED_LINK_OPTIONS "-Wl,--version-script=${CMAKE_CURRENT_BINARY_DIR}/libcurl.vers")
check_c_source_compiles("int main(void) { return 0; }" HAVE_VERSIONED_SYMBOLS) check_c_source_compiles("int main(void) { return 0; }" HAVE_VERSIONED_SYMBOLS)
if(HAVE_VERSIONED_SYMBOLS) if(HAVE_VERSIONED_SYMBOLS)
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.13) set_property(TARGET ${LIB_SHARED} APPEND PROPERTY LINK_OPTIONS "${CMAKE_REQUIRED_LINK_OPTIONS}")
set_property(TARGET ${LIB_SHARED} APPEND PROPERTY LINK_OPTIONS "${CMAKE_REQUIRED_LINK_OPTIONS}")
else()
set_property(TARGET ${LIB_SHARED} APPEND PROPERTY LINK_FLAGS "${CMAKE_REQUIRED_LINK_OPTIONS}")
endif()
else() else()
message(WARNING "Versioned symbols requested, but not supported by the toolchain.") message(WARNING "Versioned symbols requested, but not supported by the toolchain.")
endif() endif()

View File

@ -130,21 +130,13 @@ if(CURL_ANALYZER_CFLAGS)
endif() endif()
if(ENABLE_UNICODE AND MINGW) if(ENABLE_UNICODE AND MINGW)
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.13) set_property(TARGET ${EXE_NAME} APPEND PROPERTY LINK_OPTIONS "-municode")
set_property(TARGET ${EXE_NAME} APPEND PROPERTY LINK_OPTIONS "-municode")
else()
set_property(TARGET ${EXE_NAME} APPEND PROPERTY LINK_FLAGS "-municode")
endif()
endif() endif()
if(CURL_CODE_COVERAGE) if(CURL_CODE_COVERAGE)
set_property(TARGET ${EXE_NAME} APPEND PROPERTY COMPILE_DEFINITIONS ${CURL_COVERAGE_MACROS}) set_property(TARGET ${EXE_NAME} APPEND PROPERTY COMPILE_DEFINITIONS ${CURL_COVERAGE_MACROS})
set_property(TARGET ${EXE_NAME} APPEND PROPERTY COMPILE_OPTIONS ${CURL_COVERAGE_CFLAGS}) set_property(TARGET ${EXE_NAME} APPEND PROPERTY COMPILE_OPTIONS ${CURL_COVERAGE_CFLAGS})
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.13) set_property(TARGET ${EXE_NAME} APPEND PROPERTY LINK_OPTIONS ${CURL_COVERAGE_LDFLAGS})
set_property(TARGET ${EXE_NAME} APPEND PROPERTY LINK_OPTIONS ${CURL_COVERAGE_LDFLAGS})
else()
set_property(TARGET ${EXE_NAME} APPEND PROPERTY LINK_FLAGS ${CURL_COVERAGE_LDFLAGS})
endif()
endif() endif()
################################################################################ ################################################################################

View File

@ -22,7 +22,7 @@
# #
########################################################################### ###########################################################################
cmake_minimum_required(VERSION 3.7...3.16 FATAL_ERROR) cmake_minimum_required(VERSION 3.18 FATAL_ERROR)
message(STATUS "Using CMake version ${CMAKE_VERSION}") message(STATUS "Using CMake version ${CMAKE_VERSION}")
option(TEST_CPP "Test C++" OFF) option(TEST_CPP "Test C++" OFF)
@ -70,9 +70,6 @@ elseif(TEST_INTEGRATION_MODE STREQUAL "add_subdirectory")
set(BUILD_STATIC_LIBS ON CACHE BOOL "") set(BUILD_STATIC_LIBS ON CACHE BOOL "")
add_subdirectory(curl) add_subdirectory(curl)
elseif(TEST_INTEGRATION_MODE STREQUAL "FetchContent") elseif(TEST_INTEGRATION_MODE STREQUAL "FetchContent")
if(CMAKE_VERSION VERSION_LESS 3.14)
message(FATAL_ERROR "This test requires CMake 3.14 or upper")
endif()
include(FetchContent) include(FetchContent)
option(FROM_GIT_REPO "Git URL" "https://github.com/curl/curl.git") option(FROM_GIT_REPO "Git URL" "https://github.com/curl/curl.git")
option(FROM_GIT_TAG "Git tag" "master") option(FROM_GIT_TAG "Git tag" "master")
@ -82,7 +79,7 @@ elseif(TEST_INTEGRATION_MODE STREQUAL "FetchContent")
GIT_SHALLOW) GIT_SHALLOW)
set(BUILD_SHARED_LIBS ON CACHE BOOL "") set(BUILD_SHARED_LIBS ON CACHE BOOL "")
set(BUILD_STATIC_LIBS ON CACHE BOOL "") set(BUILD_STATIC_LIBS ON CACHE BOOL "")
FetchContent_MakeAvailable(curl) # Requires CMake 3.14 FetchContent_MakeAvailable(curl)
elseif(TEST_INTEGRATION_MODE STREQUAL "ExternalProject") elseif(TEST_INTEGRATION_MODE STREQUAL "ExternalProject")
include(ExternalProject) include(ExternalProject)
set(_curl_install_dir "${CMAKE_BINARY_DIR}/curl-external-install") set(_curl_install_dir "${CMAKE_BINARY_DIR}/curl-external-install")

View File

@ -14,19 +14,7 @@ mode="${1:-all}"; shift
cmake_consumer="${TEST_CMAKE_CONSUMER:-cmake}" cmake_consumer="${TEST_CMAKE_CONSUMER:-cmake}"
cmake_provider="${TEST_CMAKE_PROVIDER:-${cmake_consumer}}" cmake_provider="${TEST_CMAKE_PROVIDER:-${cmake_consumer}}"
# 'modern': supports -S/-B (3.13+), --install (3.15+) gen="${TEST_CMAKE_GENERATOR:-Ninja}"
"${cmake_consumer}" --help | grep -q -- '--install' && cmake_consumer_modern=1
"${cmake_provider}" --help | grep -q -- '--install' && cmake_provider_modern=1
if [ -n "${TEST_CMAKE_GENERATOR:-}" ]; then
gen="${TEST_CMAKE_GENERATOR}"
elif [ -n "${cmake_consumer_modern:-}" ] && \
[ -n "${cmake_provider_modern:-}" ] && \
command -v ninja >/dev/null; then
gen='Ninja' # 3.17+
else
gen='Unix Makefiles'
fi
cmake_opts='-DBUILD_CURL_EXE=OFF -DBUILD_LIBCURL_DOCS=OFF -DBUILD_MISC_DOCS=OFF -DENABLE_CURL_MANUAL=OFF' cmake_opts='-DBUILD_CURL_EXE=OFF -DBUILD_LIBCURL_DOCS=OFF -DBUILD_MISC_DOCS=OFF -DENABLE_CURL_MANUAL=OFF'
@ -47,23 +35,14 @@ if [ "${mode}" = 'all' ] || [ "${mode}" = 'ExternalProject' ]; then
sha="$(sha256sum "${src}" | grep -a -i -o -w -E '[0-9a-f]{64}')" sha="$(sha256sum "${src}" | grep -a -i -o -w -E '[0-9a-f]{64}')"
bldc='bld-externalproject' bldc='bld-externalproject'
rm -rf "${bldc}" rm -rf "${bldc}"
if [ -n "${cmake_consumer_modern:-}" ]; then # 3.15+ "${cmake_consumer}" -B "${bldc}" -G "${gen}" ${TEST_CMAKE_FLAGS:-} -DCURL_TEST_OPTS="${cmake_opts} -DCMAKE_UNITY_BUILD=ON $*" \
"${cmake_consumer}" -B "${bldc}" -G "${gen}" ${TEST_CMAKE_FLAGS:-} -DCURL_TEST_OPTS="${cmake_opts} -DCMAKE_UNITY_BUILD=ON $*" \ -DTEST_INTEGRATION_MODE=ExternalProject \
-DTEST_INTEGRATION_MODE=ExternalProject \ -DFROM_ARCHIVE="${src}" -DFROM_HASH="${sha}"
-DFROM_ARCHIVE="${src}" -DFROM_HASH="${sha}" "${cmake_consumer}" --build "${bldc}" --verbose
"${cmake_consumer}" --build "${bldc}" --verbose
else
mkdir "${bldc}"; cd "${bldc}"
"${cmake_consumer}" .. -G "${gen}" ${TEST_CMAKE_FLAGS:-} -DCURL_TEST_OPTS="${cmake_opts} $*" \
-DTEST_INTEGRATION_MODE=ExternalProject \
-DFROM_ARCHIVE="${src}" -DFROM_HASH="${sha}"
VERBOSE=1 "${cmake_consumer}" --build .
cd ..
fi
runresults "${bldc}" runresults "${bldc}"
fi fi
if [ "${mode}" = 'all' ] || [ "${mode}" = 'FetchContent' ]; then # 3.14+ if [ "${mode}" = 'all' ] || [ "${mode}" = 'FetchContent' ]; then
src="${PWD}/${src}" src="${PWD}/${src}"
bldc='bld-fetchcontent' bldc='bld-fetchcontent'
rm -rf "${bldc}" rm -rf "${bldc}"
@ -83,19 +62,9 @@ if [ "${mode}" = 'all' ] || [ "${mode}" = 'add_subdirectory' ]; then
fi fi
bldc='bld-add_subdirectory' bldc='bld-add_subdirectory'
rm -rf "${bldc}" rm -rf "${bldc}"
if [ -n "${cmake_consumer_modern:-}" ]; then # 3.15+ "${cmake_consumer}" -B "${bldc}" -G "${gen}" ${cmake_opts} -DCMAKE_UNITY_BUILD=ON ${TEST_CMAKE_FLAGS:-} "$@" \
"${cmake_consumer}" -B "${bldc}" -G "${gen}" ${cmake_opts} -DCMAKE_UNITY_BUILD=ON ${TEST_CMAKE_FLAGS:-} "$@" \ -DTEST_INTEGRATION_MODE=add_subdirectory
-DTEST_INTEGRATION_MODE=add_subdirectory "${cmake_consumer}" --build "${bldc}" --verbose
"${cmake_consumer}" --build "${bldc}" --verbose
else
mkdir "${bldc}"; cd "${bldc}"
# Disable `pkg-config` for CMake <= 3.12. These versions cannot propagate
# library directories to the consumer project.
"${cmake_consumer}" .. -G "${gen}" ${cmake_opts} -DCURL_USE_PKGCONFIG=OFF ${TEST_CMAKE_FLAGS:-} "$@" \
-DTEST_INTEGRATION_MODE=add_subdirectory
VERBOSE=1 "${cmake_consumer}" --build .
cd ..
fi
PATH="${bldc}/curl/lib:${PATH}" PATH="${bldc}/curl/lib:${PATH}"
runresults "${bldc}" runresults "${bldc}"
fi fi
@ -105,41 +74,21 @@ if [ "${mode}" = 'all' ] || [ "${mode}" = 'find_package' ]; then
bldp='bld-curl' bldp='bld-curl'
prefix="${PWD}/${bldp}/_pkg" prefix="${PWD}/${bldp}/_pkg"
rm -rf "${bldp}" rm -rf "${bldp}"
if [ -n "${cmake_provider_modern:-}" ]; then # 3.15+ "${cmake_provider}" -B "${bldp}" -S "${src}" -G "${gen}" ${cmake_opts} -DCMAKE_UNITY_BUILD=ON ${TEST_CMAKE_FLAGS:-} ${TEST_CMAKE_FLAGS_PROVIDER:-} "$@" \
"${cmake_provider}" -B "${bldp}" -S "${src}" -G "${gen}" ${cmake_opts} -DCMAKE_UNITY_BUILD=ON ${TEST_CMAKE_FLAGS:-} ${TEST_CMAKE_FLAGS_PROVIDER:-} "$@" \ -DBUILD_SHARED_LIBS=ON \
-DBUILD_SHARED_LIBS=ON \ -DBUILD_STATIC_LIBS=ON \
-DBUILD_STATIC_LIBS=ON \ -DCMAKE_INSTALL_PREFIX="${prefix}"
-DCMAKE_INSTALL_PREFIX="${prefix}" "${cmake_provider}" --build "${bldp}" --verbose
"${cmake_provider}" --build "${bldp}" --verbose "${cmake_provider}" --install "${bldp}"
"${cmake_provider}" --install "${bldp}"
else
mkdir "${bldp}"; cd "${bldp}"
"${cmake_provider}" "${src}" -G "${gen}" ${cmake_opts} ${TEST_CMAKE_FLAGS:-} ${TEST_CMAKE_FLAGS_PROVIDER:-} "$@" \
-DBUILD_SHARED_LIBS=ON \
-DBUILD_STATIC_LIBS=ON \
-DCMAKE_INSTALL_PREFIX="${prefix}"
VERBOSE=1 "${cmake_provider}" --build .
make install
cd ..
fi
echo '::group::libcurl.pc'; cat "${prefix}"/lib/pkgconfig/*.pc || true; echo '::endgroup::' echo '::group::libcurl.pc'; cat "${prefix}"/lib/pkgconfig/*.pc || true; echo '::endgroup::'
echo '::group::curl-config.cmake'; cat "${prefix}"/lib/cmake/CURL/CURL* || true; echo '::endgroup::' echo '::group::curl-config.cmake'; cat "${prefix}"/lib/cmake/CURL/CURL* || true; echo '::endgroup::'
echo '::group::curl-config'; cat "${prefix}"/bin/curl-config || true; echo '::endgroup::' echo '::group::curl-config'; cat "${prefix}"/bin/curl-config || true; echo '::endgroup::'
bldc='bld-find_package' bldc='bld-find_package'
rm -rf "${bldc}" rm -rf "${bldc}"
if [ -n "${cmake_consumer_modern:-}" ]; then # 3.15+ "${cmake_consumer}" -B "${bldc}" -G "${gen}" ${TEST_CMAKE_FLAGS:-} ${TEST_CMAKE_FLAGS_CONSUMER:-} \
"${cmake_consumer}" -B "${bldc}" -G "${gen}" ${TEST_CMAKE_FLAGS:-} ${TEST_CMAKE_FLAGS_CONSUMER:-} \ -DTEST_INTEGRATION_MODE=find_package \
-DTEST_INTEGRATION_MODE=find_package \ -DCMAKE_PREFIX_PATH="${prefix}/lib/cmake/CURL"
-DCMAKE_PREFIX_PATH="${prefix}/lib/cmake/CURL" "${cmake_consumer}" --build "${bldc}" --verbose
"${cmake_consumer}" --build "${bldc}" --verbose
else
mkdir "${bldc}"; cd "${bldc}"
"${cmake_consumer}" .. -G "${gen}" ${TEST_CMAKE_FLAGS:-} ${TEST_CMAKE_FLAGS_CONSUMER:-} \
-DTEST_INTEGRATION_MODE=find_package \
-DCMAKE_PREFIX_PATH="${prefix}/lib/cmake/CURL"
VERBOSE=1 "${cmake_consumer}" --build .
cd ..
fi
PATH="${prefix}/bin:${PATH}" PATH="${prefix}/bin:${PATH}"
runresults "${bldc}" runresults "${bldc}"
fi fi