You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
In 1.11.0, there is now only Libssh2::libssh2_static or Libssh2::libssh2_shared.
The Libssh2::libssh2 which worked with 1.10.0 is no longer there.
To Reproduce
Build and install libssh2, use cmake config to import libssh2 into another CMake project
It can also contain additional cmake code, including the ALIAS libraries. In there, the exported targets are already namespaced, so it's possible to create alias in a different namespace.
Unfortunately, there is not much material on CMake best practices. One such source is Mastering CMake which documented this practice of Targets+Config, but it seems to be out-of-date. E.g. it doesn't mention CMakePackageConfigHelpers.
It's actually better to use plain configure_file instead of configure_package_config_file because the later adds installation prefix inside, making it non portable. The plain one will work in both build / install dirs. The additional macros provided by configure_package_config_file are not really needed in this case.
I've also renamed the files to libssh2-targets.cmake, libssh2-config.cmake, libssh2-config-version.cmake (i.e. lowercase variant). This should allow both find_package(libssh2) and find_package(Libssh2) because CMake normalizes the package name to lowercase when looking for the libssh2-config.cmake. I think this won't work with Libssh2Config.cmake.
Activity
cmake: re-add Libssh2:libssh2 for compatibiliy + switch to lowercase …
vszakats commentedon Jun 23, 2023
Thanks. I've made a PR, can you give it a test and suggest a way to finish it?: #1104
It's trying to implement your suggestion + #731, but it fails with a CMake error.
rbrich commentedon Jun 24, 2023
I think the ALIAS needs to be created directly in Libssh2Config. The package config is usually split into two parts:
export(TARGETS ... FILE Libssh2Targets.cmake)- export targets into another fileconfigure_package_config_file(see CMakePackageConfigHelpers) to create Libssh2Config.cmake from a templateThe config template should include the targets like this:
It can also contain additional cmake code, including the ALIAS libraries. In there, the exported targets are already namespaced, so it's possible to create alias in a different namespace.
Unfortunately, there is not much material on CMake best practices. One such source is Mastering CMake which documented this practice of Targets+Config, but it seems to be out-of-date. E.g. it doesn't mention CMakePackageConfigHelpers.
rbrich commentedon Jun 24, 2023
I've tried it here: libssh2:766bde9...rbrich:b7891fd
It's actually better to use plain
configure_fileinstead ofconfigure_package_config_filebecause the later adds installation prefix inside, making it non portable. The plain one will work in both build / install dirs. The additional macros provided byconfigure_package_config_fileare not really needed in this case.I've also renamed the files to libssh2-targets.cmake, libssh2-config.cmake, libssh2-config-version.cmake (i.e. lowercase variant). This should allow both
find_package(libssh2)andfind_package(Libssh2)because CMake normalizes the package name to lowercase when looking for the libssh2-config.cmake. I think this won't work withLibssh2Config.cmake.updates via rbrich + integration
vszakats commentedon Jun 24, 2023
I've updated the #1104 with your changes. It's building fine now and seems ready to merge.
cmake: re-add `Libssh2:libssh2` for compatibiliy + lowercase namespace
cmake: re-add `Libssh2:libssh2` for compatibiliy + lowercase namespace
cmake: re-add `Libssh2:libssh2` for compatibiliy + lowercase namespace