mirror of
https://github.com/libssh2/libssh2.git
synced 2026-10-24 03:48:58 +03:00
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 `libssh2-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, and builds faster due CMake performance improvements over time. 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, `--verbose` and `--install` options, `CMAKE_GENERATOR` env, last but not least unity mode and Ninja generator. Ref: https://github.com/curl/curl/discussions/18704 Closes #1839
This commit is contained in:
@@ -36,10 +36,10 @@
|
||||
#
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
cmake_minimum_required(VERSION 3.7...3.16 FATAL_ERROR)
|
||||
cmake_minimum_required(VERSION 3.18)
|
||||
message(STATUS "Using CMake version ${CMAKE_VERSION}")
|
||||
|
||||
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
|
||||
list(PREPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
|
||||
|
||||
include(CheckFunctionExists)
|
||||
include(CheckSymbolExists)
|
||||
|
||||
@@ -61,10 +61,6 @@ else()
|
||||
endif()
|
||||
|
||||
if(LIBGCRYPT_FOUND)
|
||||
if(CMAKE_VERSION VERSION_LESS 3.13)
|
||||
link_directories(${_libgcrypt_LIBRARY_DIRS})
|
||||
endif()
|
||||
|
||||
if(NOT TARGET libssh2::libgcrypt)
|
||||
add_library(libssh2::libgcrypt INTERFACE IMPORTED)
|
||||
set_target_properties(libssh2::libgcrypt PROPERTIES
|
||||
|
||||
@@ -64,10 +64,6 @@ else()
|
||||
endif()
|
||||
|
||||
if(MBEDTLS_FOUND)
|
||||
if(CMAKE_VERSION VERSION_LESS 3.13)
|
||||
link_directories(${_mbedtls_LIBRARY_DIRS})
|
||||
endif()
|
||||
|
||||
if(NOT TARGET libssh2::mbedcrypto)
|
||||
add_library(libssh2::mbedcrypto INTERFACE IMPORTED)
|
||||
set_target_properties(libssh2::mbedcrypto PROPERTIES
|
||||
|
||||
@@ -85,10 +85,6 @@ if(WOLFSSL_FOUND)
|
||||
mark_as_advanced(MATH_LIBRARY)
|
||||
endif()
|
||||
|
||||
if(CMAKE_VERSION VERSION_LESS 3.13)
|
||||
link_directories(${_wolfssl_LIBRARY_DIRS})
|
||||
endif()
|
||||
|
||||
if(NOT TARGET libssh2::wolfssl)
|
||||
add_library(libssh2::wolfssl INTERFACE IMPORTED)
|
||||
set_target_properties(libssh2::wolfssl PROPERTIES
|
||||
|
||||
@@ -12,7 +12,7 @@ endif()
|
||||
include(CMakeFindDependencyMacro)
|
||||
|
||||
set(_libssh2_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(_libssh2_libs "")
|
||||
if("@CRYPTO_BACKEND@" STREQUAL "OpenSSL")
|
||||
@@ -36,10 +36,6 @@ set(CMAKE_MODULE_PATH ${_libssh2_cmake_module_path_save})
|
||||
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@-targets.cmake")
|
||||
|
||||
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()
|
||||
|
||||
# Alias for either shared or static library
|
||||
if(NOT TARGET @PROJECT_NAME@::@LIB_NAME@)
|
||||
add_library(@PROJECT_NAME@::@LIB_NAME@ ALIAS @PROJECT_NAME@::@LIB_SELECTED@)
|
||||
@@ -49,24 +45,3 @@ endif()
|
||||
if(NOT TARGET Libssh2::@LIB_NAME@)
|
||||
add_library(Libssh2::@LIB_NAME@ ALIAS @PROJECT_NAME@::@LIB_SELECTED@)
|
||||
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 _libssh2_libs)
|
||||
set(_libssh2_libdirs "")
|
||||
foreach(_libssh2_lib IN LISTS _libssh2_libs)
|
||||
get_target_property(_libssh2_libdir "${_libssh2_lib}" INTERFACE_LINK_DIRECTORIES)
|
||||
if(_libssh2_libdir)
|
||||
list(APPEND _libssh2_libdirs "${_libssh2_libdir}")
|
||||
endif()
|
||||
endforeach()
|
||||
if(_libssh2_libdirs)
|
||||
target_link_directories(@PROJECT_NAME@::@LIB_STATIC@ INTERFACE ${_libssh2_libdirs})
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
@@ -68,11 +68,7 @@ list(APPEND LIBSSH2_LIBS ${LIBSSH2_LIBS_SOCKET})
|
||||
if(MSVC)
|
||||
set_property(DIRECTORY APPEND PROPERTY COMPILE_OPTIONS "$<$<CONFIG:Debug>:-Zi>")
|
||||
set_property(DIRECTORY APPEND PROPERTY COMPILE_OPTIONS "$<$<CONFIG:Debug>:-Od>")
|
||||
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.13)
|
||||
set_property(DIRECTORY APPEND PROPERTY LINK_OPTIONS "$<$<CONFIG:Debug>:-DEBUG>")
|
||||
else()
|
||||
set_property(DIRECTORY APPEND PROPERTY LINK_FLAGS "$<$<CONFIG:Debug>:-DEBUG>")
|
||||
endif()
|
||||
set_property(DIRECTORY APPEND PROPERTY LINK_OPTIONS "$<$<CONFIG:Debug>:-DEBUG>")
|
||||
endif()
|
||||
|
||||
## Sources
|
||||
@@ -126,27 +122,6 @@ if(BUILD_STATIC_LIBS OR BUILD_STATIC_FOR_TESTS)
|
||||
PUBLIC
|
||||
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>"
|
||||
"$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>")
|
||||
|
||||
# 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 LIBSSH2_LIBS)
|
||||
set(_libdirs "")
|
||||
foreach(_lib IN LISTS LIBSSH2_LIBS)
|
||||
if(TARGET "${_lib}")
|
||||
get_target_property(_libdir "${_lib}" INTERFACE_LINK_DIRECTORIES)
|
||||
if(_libdir)
|
||||
list(APPEND _libdirs "${_libdir}")
|
||||
endif()
|
||||
endif()
|
||||
endforeach()
|
||||
if(_libdirs)
|
||||
target_link_directories(${LIB_STATIC} INTERFACE ${_libdirs})
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
if(BUILD_SHARED_LIBS)
|
||||
list(APPEND _libssh2_export ${LIB_SHARED})
|
||||
|
||||
@@ -167,13 +167,8 @@ add_custom_target(coverage
|
||||
COMMAND gcovr --root "${PROJECT_SOURCE_DIR}" --exclude tests/* --html-details
|
||||
--output "${CMAKE_CURRENT_BINARY_DIR}/coverage/index.html")
|
||||
|
||||
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.17)
|
||||
add_custom_target(clean-coverage COMMAND ${CMAKE_COMMAND} -E rm -rf --
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/coverage")
|
||||
else()
|
||||
add_custom_target(clean-coverage COMMAND ${CMAKE_COMMAND} -E remove_directory
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/coverage")
|
||||
endif()
|
||||
add_custom_target(clean-coverage COMMAND ${CMAKE_COMMAND} -E rm -rf --
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/coverage")
|
||||
|
||||
libssh2_add_target_to_copy_dependencies(
|
||||
TARGET copy_test_dependencies
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# Copyright (C) Viktor Szakats
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
cmake_minimum_required(VERSION 3.7...3.16 FATAL_ERROR)
|
||||
cmake_minimum_required(VERSION 3.18)
|
||||
message(STATUS "Using CMake version ${CMAKE_VERSION}")
|
||||
|
||||
project(test-consumer C)
|
||||
@@ -36,9 +36,6 @@ if(TEST_INTEGRATION_MODE STREQUAL "find_package")
|
||||
elseif(TEST_INTEGRATION_MODE STREQUAL "add_subdirectory")
|
||||
add_subdirectory(libssh2)
|
||||
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)
|
||||
option(FROM_GIT_REPO "Git URL" "https://github.com/libssh2/libssh2.git")
|
||||
option(FROM_GIT_TAG "Git tag" "master")
|
||||
|
||||
@@ -14,19 +14,7 @@ mode="${1:-all}"; shift
|
||||
cmake_consumer="${TEST_CMAKE_CONSUMER:-cmake}"
|
||||
cmake_provider="${TEST_CMAKE_PROVIDER:-${cmake_consumer}}"
|
||||
|
||||
# 'modern': supports -S/-B (3.13+), --install (3.15+)
|
||||
"${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
|
||||
gen="${TEST_CMAKE_GENERATOR:-Ninja}"
|
||||
|
||||
cmake_opts='-DBUILD_EXAMPLES=OFF -DBUILD_TESTING=OFF -DENABLE_ZLIB_COMPRESSION=ON'
|
||||
|
||||
@@ -47,23 +35,14 @@ if [ "${mode}" = 'all' ] || [ "${mode}" = 'ExternalProject' ]; then
|
||||
sha="$(openssl dgst -sha256 "${src}" | grep -a -i -o -E '[0-9a-f]{64}$')"
|
||||
bldc='bld-externalproject'
|
||||
rm -rf "${bldc}"
|
||||
if [ -n "${cmake_consumer_modern:-}" ]; then # 3.15+
|
||||
"${cmake_consumer}" -B "${bldc}" -G "${gen}" ${TEST_CMAKE_FLAGS:-} -DLIBSSH2_TEST_OPTS="${cmake_opts} -DCMAKE_UNITY_BUILD=ON $*" \
|
||||
-DTEST_INTEGRATION_MODE=ExternalProject \
|
||||
-DFROM_ARCHIVE="${src}" -DFROM_HASH="${sha}"
|
||||
"${cmake_consumer}" --build "${bldc}" --verbose
|
||||
else
|
||||
mkdir "${bldc}"; cd "${bldc}"
|
||||
"${cmake_consumer}" .. -G "${gen}" ${TEST_CMAKE_FLAGS:-} -DLIBSSH2_TEST_OPTS="${cmake_opts} $*" \
|
||||
-DTEST_INTEGRATION_MODE=ExternalProject \
|
||||
-DFROM_ARCHIVE="${src}" -DFROM_HASH="${sha}"
|
||||
VERBOSE=1 "${cmake_consumer}" --build .
|
||||
cd ..
|
||||
fi
|
||||
"${cmake_consumer}" -B "${bldc}" -G "${gen}" ${TEST_CMAKE_FLAGS:-} -DLIBSSH2_TEST_OPTS="${cmake_opts} -DCMAKE_UNITY_BUILD=ON $*" \
|
||||
-DTEST_INTEGRATION_MODE=ExternalProject \
|
||||
-DFROM_ARCHIVE="${src}" -DFROM_HASH="${sha}"
|
||||
"${cmake_consumer}" --build "${bldc}" --verbose
|
||||
runresults "${bldc}"
|
||||
fi
|
||||
|
||||
if [ "${mode}" = 'all' ] || [ "${mode}" = 'FetchContent' ]; then # 3.14+
|
||||
if [ "${mode}" = 'all' ] || [ "${mode}" = 'FetchContent' ]; then
|
||||
src="${PWD}/${src}"
|
||||
bldc='bld-fetchcontent'
|
||||
rm -rf "${bldc}"
|
||||
@@ -83,19 +62,9 @@ if [ "${mode}" = 'all' ] || [ "${mode}" = 'add_subdirectory' ]; then
|
||||
fi
|
||||
bldc='bld-add_subdirectory'
|
||||
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:-} "$@" \
|
||||
-DTEST_INTEGRATION_MODE=add_subdirectory
|
||||
"${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} -DLIBSSH2_USE_PKGCONFIG=OFF ${TEST_CMAKE_FLAGS:-} "$@" \
|
||||
-DTEST_INTEGRATION_MODE=add_subdirectory
|
||||
VERBOSE=1 "${cmake_consumer}" --build .
|
||||
cd ..
|
||||
fi
|
||||
"${cmake_consumer}" -B "${bldc}" -G "${gen}" ${cmake_opts} -DCMAKE_UNITY_BUILD=ON ${TEST_CMAKE_FLAGS:-} "$@" \
|
||||
-DTEST_INTEGRATION_MODE=add_subdirectory
|
||||
"${cmake_consumer}" --build "${bldc}" --verbose
|
||||
PATH="${bldc}/libssh2/src:${PATH}"
|
||||
runresults "${bldc}"
|
||||
fi
|
||||
@@ -105,34 +74,16 @@ if [ "${mode}" = 'all' ] || [ "${mode}" = 'find_package' ]; then
|
||||
bldp='bld-libssh2'
|
||||
prefix="${PWD}/${bldp}/_pkg"
|
||||
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:-} "$@" \
|
||||
-DCMAKE_INSTALL_PREFIX="${prefix}"
|
||||
"${cmake_provider}" --build "${bldp}" --verbose
|
||||
"${cmake_provider}" --install "${bldp}"
|
||||
else
|
||||
mkdir "${bldp}"; cd "${bldp}"
|
||||
"${cmake_provider}" "${src}" -G "${gen}" ${cmake_opts} ${TEST_CMAKE_FLAGS:-} "$@" \
|
||||
-DCMAKE_INSTALL_PREFIX="${prefix}"
|
||||
VERBOSE=1 "${cmake_provider}" --build .
|
||||
make install
|
||||
cd ..
|
||||
fi
|
||||
"${cmake_provider}" -B "${bldp}" -S "${src}" -G "${gen}" ${cmake_opts} -DCMAKE_UNITY_BUILD=ON ${TEST_CMAKE_FLAGS:-} "$@" \
|
||||
-DCMAKE_INSTALL_PREFIX="${prefix}"
|
||||
"${cmake_provider}" --build "${bldp}" --verbose
|
||||
"${cmake_provider}" --install "${bldp}"
|
||||
bldc='bld-find_package'
|
||||
rm -rf "${bldc}"
|
||||
if [ -n "${cmake_consumer_modern:-}" ]; then # 3.15+
|
||||
"${cmake_consumer}" -B "${bldc}" -G "${gen}" ${TEST_CMAKE_FLAGS:-} \
|
||||
-DTEST_INTEGRATION_MODE=find_package \
|
||||
-DCMAKE_PREFIX_PATH="${prefix}/lib/cmake/libssh2"
|
||||
"${cmake_consumer}" --build "${bldc}" --verbose
|
||||
else
|
||||
mkdir "${bldc}"; cd "${bldc}"
|
||||
"${cmake_consumer}" .. -G "${gen}" ${TEST_CMAKE_FLAGS:-} \
|
||||
-DTEST_INTEGRATION_MODE=find_package \
|
||||
-DCMAKE_PREFIX_PATH="${prefix}/lib/cmake/libssh2"
|
||||
VERBOSE=1 "${cmake_consumer}" --build .
|
||||
cd ..
|
||||
fi
|
||||
"${cmake_consumer}" -B "${bldc}" -G "${gen}" ${TEST_CMAKE_FLAGS:-} \
|
||||
-DTEST_INTEGRATION_MODE=find_package \
|
||||
-DCMAKE_PREFIX_PATH="${prefix}/lib/cmake/libssh2"
|
||||
"${cmake_consumer}" --build "${bldc}" --verbose
|
||||
PATH="${prefix}/bin:${PATH}"
|
||||
runresults "${bldc}"
|
||||
fi
|
||||
|
||||
@@ -13,11 +13,7 @@ target_include_directories(ssh2_client_fuzzer PRIVATE
|
||||
"${PROJECT_SOURCE_DIR}/include")
|
||||
if(LIB_FUZZING_ENGINE)
|
||||
if(LIB_FUZZING_ENGINE STREQUAL "-fsanitize=fuzzer") # FIXME: compiler-specific
|
||||
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.13)
|
||||
set_property(TARGET ssh2_client_fuzzer APPEND PROPERTY LINK_OPTIONS "${LIB_FUZZING_ENGINE}")
|
||||
else()
|
||||
set_property(TARGET ssh2_client_fuzzer APPEND PROPERTY LINK_FLAGS "${LIB_FUZZING_ENGINE}")
|
||||
endif()
|
||||
set_property(TARGET ssh2_client_fuzzer APPEND PROPERTY LINK_OPTIONS "${LIB_FUZZING_ENGINE}")
|
||||
else()
|
||||
target_link_libraries(ssh2_client_fuzzer ${LIB_FUZZING_ENGINE})
|
||||
endif()
|
||||
|
||||
Reference in New Issue
Block a user