1
0
mirror of https://github.com/libssh2/libssh2.git synced 2026-10-24 03:48:58 +03:00
Files
libssh2/cmake/FindLibgcrypt.cmake
Viktor Szakats ac7b9b214a 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
2026-04-10 21:59:24 +02:00

74 lines
2.5 KiB
CMake

# Copyright (C) The libssh2 project and its contributors.
# SPDX-License-Identifier: BSD-3-Clause
#
###########################################################################
# Find the Libgcrypt library
#
# Input variables:
#
# - `LIBGCRYPT_INCLUDE_DIR`: Absolute path to Libgcrypt include directory.
# - `LIBGCRYPT_LIBRARY`: Absolute path to `libgcrypt` library.
#
# Defines:
#
# - `LIBGCRYPT_FOUND`: System has Libgcrypt.
# - `LIBGCRYPT_VERSION`: Version of Libgcrypt.
# - `libssh2::libgcrypt`: libgcrypt library target.
set(_libgcrypt_pc_requires "libgcrypt")
if(LIBSSH2_USE_PKGCONFIG AND
NOT DEFINED LIBGCRYPT_INCLUDE_DIR AND
NOT DEFINED LIBGCRYPT_LIBRARY)
find_package(PkgConfig QUIET)
pkg_check_modules(_libgcrypt ${_libgcrypt_pc_requires})
endif()
if(_libgcrypt_FOUND)
set(Libgcrypt_FOUND TRUE)
set(LIBGCRYPT_FOUND TRUE)
set(LIBGCRYPT_VERSION ${_libgcrypt_VERSION})
message(STATUS "Found Libgcrypt (via pkg-config): ${_libgcrypt_INCLUDE_DIRS} (found version \"${LIBGCRYPT_VERSION}\")")
else()
find_path(LIBGCRYPT_INCLUDE_DIR NAMES "gcrypt.h")
find_library(LIBGCRYPT_LIBRARY NAMES "gcrypt" "libgcrypt")
unset(LIBGCRYPT_VERSION CACHE)
if(LIBGCRYPT_INCLUDE_DIR AND EXISTS "${LIBGCRYPT_INCLUDE_DIR}/gcrypt.h")
set(_version_regex "#[\t ]*define[\t ]+GCRYPT_VERSION[\t ]+\"([^\"]*)\"")
file(STRINGS "${LIBGCRYPT_INCLUDE_DIR}/gcrypt.h" _version_str REGEX "${_version_regex}")
string(REGEX REPLACE "${_version_regex}" "\\1" _version_str "${_version_str}")
set(LIBGCRYPT_VERSION "${_version_str}")
unset(_version_regex)
unset(_version_str)
endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Libgcrypt
REQUIRED_VARS
LIBGCRYPT_INCLUDE_DIR
LIBGCRYPT_LIBRARY
VERSION_VAR
LIBGCRYPT_VERSION
)
if(LIBGCRYPT_FOUND)
set(_libgcrypt_INCLUDE_DIRS ${LIBGCRYPT_INCLUDE_DIR})
set(_libgcrypt_LIBRARIES ${LIBGCRYPT_LIBRARY})
endif()
mark_as_advanced(LIBGCRYPT_INCLUDE_DIR LIBGCRYPT_LIBRARY)
endif()
if(LIBGCRYPT_FOUND)
if(NOT TARGET libssh2::libgcrypt)
add_library(libssh2::libgcrypt INTERFACE IMPORTED)
set_target_properties(libssh2::libgcrypt PROPERTIES
INTERFACE_LIBSSH2_PC_MODULES "${_libgcrypt_pc_requires}"
INTERFACE_COMPILE_OPTIONS "${_libgcrypt_CFLAGS}"
INTERFACE_INCLUDE_DIRECTORIES "${_libgcrypt_INCLUDE_DIRS}"
INTERFACE_LINK_DIRECTORIES "${_libgcrypt_LIBRARY_DIRS}"
INTERFACE_LINK_LIBRARIES "${_libgcrypt_LIBRARIES}")
endif()
endif()