1
0
mirror of https://github.com/libssh2/libssh2.git synced 2025-08-05 20:55:47 +03:00

cmake: re-add Libssh2:libssh2 for compatibiliy + lowercase namespace

- add `libssh2:libssh2` target that selects the shared lib if built,
  otherwise the static one.

- re-add `Libssh2:libssh2` target for compatibility with v1.10.0 and
  earlier. This is an alias for `libssh2:libssh2`.

- keep `libssh2:libssh2_shared` and `libssh2_libssh2_static` targets.

- allow using `find_package(libssh2)` in dependents as an alternative
  to `find_package(Libssh2)`.

Co-authored-by: Radek Brich
Suggested-by: Haowei Hsu

Fixes #1103
Fixes #731
Closes #1104
This commit is contained in:
Viktor Szakats
2023-06-23 16:40:01 +00:00
parent 279a2e57e5
commit 2da13c13e1
3 changed files with 30 additions and 14 deletions

View File

@@ -0,0 +1,10 @@
# Copyright (C) The libssh2 project and its contributors.
# SPDX-License-Identifier: BSD-3-Clause
include("${CMAKE_CURRENT_LIST_DIR}/libssh2-targets.cmake")
# Alias for either shared or static library
add_library(libssh2::libssh2 ALIAS libssh2::@LIB_SELECTED@)
# Compatibility alias
add_library(Libssh2::libssh2 ALIAS libssh2::@LIB_SELECTED@)

View File

@@ -134,8 +134,8 @@ setting it up with libssh2's location. Add the following lines and
CMake will find libssh2 on your system, set up the necessary paths and
link the library with your binary.
find_package(Libssh2 REQUIRED CONFIG)
target_link_libraries(my_project_target Libssh2::libssh2)
find_package(libssh2 REQUIRED CONFIG)
target_link_libraries(my_project_target libssh2::libssh2)
You still have to make libssh2 available on your system first. You can
install it in the traditional way shown above, but you do not have to.
@@ -149,13 +149,13 @@ builds your project:
include(ExternalProject)
ExternalProject_Add(
Libssh2
libssh2
URL <libssh2 download location>
URL_HASH SHA256=<libssh2 archive SHA256>
INSTALL_COMMAND "")
ExternalProject_Add(
MyProject DEPENDS Libssh2
MyProject DEPENDS libssh2
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src
INSTALL_COMMAND "")

View File

@@ -143,14 +143,14 @@ install(FILES
if(BUILD_STATIC_LIBS)
install(TARGETS ${LIB_STATIC}
EXPORT Libssh2Config
EXPORT libssh2-targets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif()
if(BUILD_SHARED_LIBS)
install(TARGETS ${LIB_SHARED}
EXPORT Libssh2Config
EXPORT libssh2-targets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
@@ -163,15 +163,21 @@ set(RUNTIME_DEPENDENCIES ${_RUNTIME_DEPENDENCIES} CACHE INTERNAL
# Package config
## During package installation, install Libssh2Config.cmake
install(EXPORT Libssh2Config
NAMESPACE Libssh2::
## During package installation, install libssh2-targets.cmake
install(EXPORT libssh2-targets
NAMESPACE libssh2::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/libssh2)
## During build, register directly from build tree
# create Libssh2Config.cmake
export(TARGETS ${libssh2_export} NAMESPACE Libssh2:: FILE Libssh2Config.cmake)
export(PACKAGE Libssh2) # register it
# create libssh2-targets.cmake
export(TARGETS ${libssh2_export} NAMESPACE libssh2:: FILE libssh2-targets.cmake)
export(PACKAGE libssh2) # register it
# Generate libssh2-config.cmake into build tree and install it
configure_file(${CMAKE_SOURCE_DIR}/cmake/libssh2-config.cmake.in libssh2-config.cmake @ONLY)
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/libssh2-config.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/libssh2)
## Export a .pc file for client projects not using CMaek
if(PC_REQUIRES_PRIVATE)
@@ -209,9 +215,9 @@ endif()
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/Libssh2ConfigVersion.cmake
${CMAKE_CURRENT_BINARY_DIR}/libssh2-config-version.cmake
VERSION "${LIBSSH2_VERSION_MAJOR}.${LIBSSH2_VERSION_MINOR}.${LIBSSH2_VERSION_PATCH}"
COMPATIBILITY SameMajorVersion)
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/Libssh2ConfigVersion.cmake
FILES ${CMAKE_CURRENT_BINARY_DIR}/libssh2-config-version.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/libssh2)