Skip to content

Fix non-portable opendhtConfig.cmake: use proper targets and find_dependency#860

Draft
aberaud with Copilot wants to merge 2 commits into
masterfrom
copilot/fix-portability-of-opendhtconfig
Draft

Fix non-portable opendhtConfig.cmake: use proper targets and find_dependency#860
aberaud with Copilot wants to merge 2 commits into
masterfrom
copilot/fix-portability-of-opendhtconfig

Conversation

Copilot AI commented May 15, 2026

Copy link
Copy Markdown
Contributor

The exported opendhtConfig.cmake contained non-portable references: absolute build paths for GnuTLS (D:/projects/.../gnutls.lib), locally-created imported targets (nettle_lib, hogweed_lib, tasn1_lib), a bare jsoncpp library name, and PkgConfig::* targets that don't exist for consumers.

Changes

  • Replace non-portable link targets in CMakeLists.txt

    • ${GNUTLS_LIBRARIES} (absolute paths) → GnuTLS::GnuTLS (available since CMake 3.16, we require 3.21+)
    • jsoncpp (bare name) → JsonCpp::JsonCpp (already found via find_package(jsoncpp CONFIG))
  • Split export into two-file pattern

    • install(EXPORT ... FILE opendhtConfig.cmake)FILE opendhtTargets.cmake
    • New opendhtConfig.cmake.in template generates a proper config via configure_package_config_file()
  • New opendhtConfig.cmake.in re-finds all dependencies before including targets:

    • MSVC/vcpkg: find_dependency() for GnuTLS/jsoncpp/fmt/simdutf/msgpack-cxx; recreates nettle_lib/hogweed_lib/tasn1_lib via find_library() for static builds
    • PkgConfig: pkg_search_module() for each PkgConfig::* target
    • Non-pkgconfig Unix: find_dependency() for GnuTLS, jsoncpp, fmt

Build options (OPENDHT_HTTP, OPENDHT_TOOLS, etc.) are baked into the generated config so only the relevant find_dependency calls are emitted.

Replace non-portable target references in exported CMake config:
- Use GnuTLS::GnuTLS target instead of ${GNUTLS_LIBRARIES} (absolute paths)
- Use JsonCpp::JsonCpp instead of plain 'jsoncpp' library name
- Create opendhtConfig.cmake.in template with find_dependency() calls
  to re-find all dependencies (PkgConfig::*, nettle_lib, etc.)
- Export targets to opendhtTargets.cmake, generate config from template
- Handles MSVC, pkgconfig, and non-pkgconfig Unix paths

Agent-Logs-Url: https://github.com/savoirfairelinux/opendht/sessions/d7522535-0905-41ec-a84e-b590d9613291

Co-authored-by: aberaud <101827+aberaud@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix portability issues in opendhtConfig.cmake Fix non-portable opendhtConfig.cmake: use proper targets and find_dependency May 15, 2026
Copilot AI requested a review from aberaud May 15, 2026 19:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Generated opendhtConfig.cmake config is not portable

2 participants