CMake configs: libssh v0.11.2 references OpenSSL::Crypto but is missing the needed find_dependency
This is a report from the attempt to add libssh v0.11.2 in vcpkg: https://github.com/microsoft/vcpkg/pull/46734
I believe https://git.libssh.org/projects/libssh.git/commit/src/CMakeLists.txt?id=6ad455a8acfe6032c2a87cf83f2d20463c30f8af replaced naming OpenSSL's library names in the generated configs with naming OpenSSL's target names. That's a lot more understandable for downstream customers and build systems, but means that the installed CMake configs need a find_dependency call to make those targets exist. See:
When projects have conditional dependencies, I believe the usual convention is to have install(EXPORT (as in https://gitlab.com/libssh/libssh-mirror/-/blob/master/src/CMakeLists.txt?ref_type=heads#L380-389 ) make files named Xxx-targets.cmake, and use configure_file to emit an Xxx-config.cmake with content like:
include(CMakeFindDependencyMacro)
if (@WITH_GCRYPT@) # I'm copying the structure from https://gitlab.com/libssh/libssh-mirror/-/blob/master/CMakeLists.txt?ref_type=heads#L51
find_dependency(GCrypt 1.5.0)
elseif(@WITH_MBEDTLS@)
find_dependency(MbedTLS)
else()
find_dependency(OpenSSL 1.1.1)
endif()
include(libssh-targets.cmake)
The find_dependency calls should match the find_package calls in the original sources, except REQUIRED should be omitted. The point of find_dependency is so that if someone does find_package(libssh QUIET), finding dependencies of libssh are also found QUIET. See https://cmake.org/cmake/help/latest/module/CMakeFindDependencyMacro.html
