diff --git a/cmake/libssh2-config.cmake.in b/cmake/libssh2-config.cmake.in new file mode 100644 index 00000000..84b98cb2 --- /dev/null +++ b/cmake/libssh2-config.cmake.in @@ -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@) diff --git a/docs/INSTALL_CMAKE.md b/docs/INSTALL_CMAKE.md index 65653ae4..1d6a988a 100644 --- a/docs/INSTALL_CMAKE.md +++ b/docs/INSTALL_CMAKE.md @@ -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 URL_HASH SHA256= INSTALL_COMMAND "") ExternalProject_Add( - MyProject DEPENDS Libssh2 + MyProject DEPENDS libssh2 SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src INSTALL_COMMAND "") diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3a2077d0..8638ac41 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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)