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:
10
cmake/libssh2-config.cmake.in
Normal file
10
cmake/libssh2-config.cmake.in
Normal 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@)
|
@@ -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
|
CMake will find libssh2 on your system, set up the necessary paths and
|
||||||
link the library with your binary.
|
link the library with your binary.
|
||||||
|
|
||||||
find_package(Libssh2 REQUIRED CONFIG)
|
find_package(libssh2 REQUIRED CONFIG)
|
||||||
target_link_libraries(my_project_target Libssh2::libssh2)
|
target_link_libraries(my_project_target libssh2::libssh2)
|
||||||
|
|
||||||
You still have to make libssh2 available on your system first. You can
|
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.
|
install it in the traditional way shown above, but you do not have to.
|
||||||
@@ -149,13 +149,13 @@ builds your project:
|
|||||||
include(ExternalProject)
|
include(ExternalProject)
|
||||||
|
|
||||||
ExternalProject_Add(
|
ExternalProject_Add(
|
||||||
Libssh2
|
libssh2
|
||||||
URL <libssh2 download location>
|
URL <libssh2 download location>
|
||||||
URL_HASH SHA256=<libssh2 archive SHA256>
|
URL_HASH SHA256=<libssh2 archive SHA256>
|
||||||
INSTALL_COMMAND "")
|
INSTALL_COMMAND "")
|
||||||
|
|
||||||
ExternalProject_Add(
|
ExternalProject_Add(
|
||||||
MyProject DEPENDS Libssh2
|
MyProject DEPENDS libssh2
|
||||||
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src
|
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src
|
||||||
INSTALL_COMMAND "")
|
INSTALL_COMMAND "")
|
||||||
|
|
||||||
|
@@ -143,14 +143,14 @@ install(FILES
|
|||||||
|
|
||||||
if(BUILD_STATIC_LIBS)
|
if(BUILD_STATIC_LIBS)
|
||||||
install(TARGETS ${LIB_STATIC}
|
install(TARGETS ${LIB_STATIC}
|
||||||
EXPORT Libssh2Config
|
EXPORT libssh2-targets
|
||||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||||
endif()
|
endif()
|
||||||
if(BUILD_SHARED_LIBS)
|
if(BUILD_SHARED_LIBS)
|
||||||
install(TARGETS ${LIB_SHARED}
|
install(TARGETS ${LIB_SHARED}
|
||||||
EXPORT Libssh2Config
|
EXPORT libssh2-targets
|
||||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||||
@@ -163,15 +163,21 @@ set(RUNTIME_DEPENDENCIES ${_RUNTIME_DEPENDENCIES} CACHE INTERNAL
|
|||||||
|
|
||||||
# Package config
|
# Package config
|
||||||
|
|
||||||
## During package installation, install Libssh2Config.cmake
|
## During package installation, install libssh2-targets.cmake
|
||||||
install(EXPORT Libssh2Config
|
install(EXPORT libssh2-targets
|
||||||
NAMESPACE Libssh2::
|
NAMESPACE libssh2::
|
||||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/libssh2)
|
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/libssh2)
|
||||||
|
|
||||||
## During build, register directly from build tree
|
## During build, register directly from build tree
|
||||||
# create Libssh2Config.cmake
|
# create libssh2-targets.cmake
|
||||||
export(TARGETS ${libssh2_export} NAMESPACE Libssh2:: FILE Libssh2Config.cmake)
|
export(TARGETS ${libssh2_export} NAMESPACE libssh2:: FILE libssh2-targets.cmake)
|
||||||
export(PACKAGE Libssh2) # register it
|
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
|
## Export a .pc file for client projects not using CMaek
|
||||||
if(PC_REQUIRES_PRIVATE)
|
if(PC_REQUIRES_PRIVATE)
|
||||||
@@ -209,9 +215,9 @@ endif()
|
|||||||
|
|
||||||
include(CMakePackageConfigHelpers)
|
include(CMakePackageConfigHelpers)
|
||||||
write_basic_package_version_file(
|
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}"
|
VERSION "${LIBSSH2_VERSION_MAJOR}.${LIBSSH2_VERSION_MINOR}.${LIBSSH2_VERSION_PATCH}"
|
||||||
COMPATIBILITY SameMajorVersion)
|
COMPATIBILITY SameMajorVersion)
|
||||||
install(
|
install(
|
||||||
FILES ${CMAKE_CURRENT_BINARY_DIR}/Libssh2ConfigVersion.cmake
|
FILES ${CMAKE_CURRENT_BINARY_DIR}/libssh2-config-version.cmake
|
||||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/libssh2)
|
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/libssh2)
|
||||||
|
Reference in New Issue
Block a user