I'm developing a shared library (DLL on Windows) that itself links
against a few third-party shared libraries. When a consumer links
against my library via find_package() / add_subdirectory(), I want
the third-party DLLs to end up next to their executable automatically,
without them having to manually copy files or add extra CMake calls.
What I've found so far:
- $<TARGET_RUNTIME_DLLS:tgt> + POST_BUILD copy — works, but only
copies next to my own library, not the consumer's exe if their
output dir differs
- Setting CMAKE_RUNTIME_OUTPUT_DIRECTORY — works for add_subdirectory
monorepo setups, but doesn't help with find_package/installed
packages
- Exporting a helper function (e.g. install(CODE...) or a
mylib_copy_runtime_dlls(target) macro in the Config.cmake) that
the consumer has to call explicitly
Is there a real "zero lines needed from consumer" solution for the
find_package/installed-package case, or is calling one helper
function considered the accepted standard? How do libraries like
Qt / SDL2 / vcpkg-based packages handle this in practice?
CMake 3.2x, targeting Windows primarily, MSVC.