I appologize for the dig, but @Leon0402 I was wondering if in the end you just ended up sticking with the file(GET_RUNTIME_DEPENDENCIES
approach in the end.
I’m in a similar situation where I use FetchContent as much as possible and thus simply installing the targets within the build tree would result in everything pouring in to the install directory, most of which I don’t want. I already use a technique in which any projects that are not the top-level project automatically have EXCLUDE_FROM_ALL
appended to their calls to install(...)
, which has worked great for static builds, but now for shared builds I need to somehow specifically allow the runtime dependencies through.
I can of course do this by making the exclude statement not apply to the RUNTIME category, but then I’d also need to add a switch to AND that against as in my lib only projects I still wouldn’t want the runtimes to be installed, only on projects that feature executables. Then finally, the biggest flaw as you pointed out is that this only works for my own projects and doesn’t apply to other’s that don’t follow the exact same design pattern (i.e. 0), unless you get lucky and can bodge something together using FetchContent arguments and creating custom imported targets/installs, but that still is pretty crude.
I find it more idiomatic and desirable to have the install of the runtimes “pulled” by an executable itself rather than to “just install the library”, in the context of the library being a subproject. In that context, I essentially don’t care about the library’s install contents and only want what the executable needs, so in these projects I never actually install the library directly, not through the default install component nor the named one I made for it. It’s the executable that necessitates the installation of the some of the library’s components, not the library itself.
install(TARGET ... RUNTIME_DEPENDENCIES)
seemed perfect until I learned that to my chagrin it forcefully excludes in-tree targets as you noted. IMO there should just be a switch argument for that.
It seems to me the only real downside of included in-tree targets is that if you do happen to install a library directly (maybe one that’s part of the top-level project) then any of it’s runtimes that an executable is dependent on will cause them to them be queued for installation twice. While I get that in really large and complex projects this can add a siginificant time waste, for smaller or even medium sized ones this just means a few extra potential “Up-to-date” messages in the console with an insignificant extra amount of time spent, especially in my case where I guarantee that sub-project targets are not installed as part of ‘all’.
Personally I’d much rather take that trade-off than the mass of changes I’d have to perform on my own projects and hackery I’d have to attempt on other’s when fetching them.
So basically, I’m just curious if this approach ended up working out for you.