Feature Request: Explicit Tracking of Runtime Requirements
Following on from Issue 20416: Inheritance for Custom Targets Properties. Here's a specific request for tracking runtime requirements, such as the paths to actual .dll or .so files needed at runtime by a target:
It would greatly simplify shared lib (.dll/.so) usage in CMake if there was a property called RUNTIME_REQUIREMENTS, or similar, on targets to which paths to any .dlls etc. could be added which I would like to be copied alongside any executable during a post build step. The RUNTIME_REQUIREMENTS property on each target would need to inherit its values from targets linked via target_link_libraries similarly to how INTERFACE_COMPILE_DEFINITIONS currently does.
This setup would allow the .dll/.so requirements to be specified alongside each individual library and be automatically propagated up to the executable targets appropriately.
This would be similar to the RUNTIME_DIRECTORIES suggestion in issue 19874 except it would copy the files next to the executable rather than reference the paths meaning you would be able to run the executable without any special runtime environment wrappers.
Reasoning for the Request
There have also been several requests for achieving this via existing properties eg. issue 16462 but it seems that there are complications with that approach which would be avoided via the method proposed here.
Another common suggestion when this issue is raised is to use the CMake's Install functionality. This is also not viable for projects with very large codebases including many top level executables as Install requires the full project to be built and installed prior to running any individual app within the project - which is impractical as it takes a long time to do. Also unless you copy the runtime requirements at build time you cannot debug in Visual Studio using the usual build->run cycle expected by most developers as you just get a missing .dll error.
Finally there is a suggestion to add a runtime context to CMake which handles this Issue 19874 which would also potentially be a workable solution if implemented.
I have not found a discussion on this topic which ended with a viable solution being proposed (accepting the restrictions stated above) within CMake as it stands (version 3.17). If there is one I have missed, please add a comment.
The only solutions I can think of using CMake 3.17 are:
- Hard code the runtime requirements in each executable (ie. list them explicitly in post build copy commands). Workable but seems such a shame as CMake has all the information I need to not need to do this!
- Find a way to interrogate the generated executable (using something like Dependencies) to extract them in a post build step - This does not seem like a good idea to me!
- Manually walk the dependency tree in CMake and generate them. This is almost workable though it generates a lot CMake code and CMake complains if you try and read LINK_LIBRARIES on an INTERFACE library during the walk - and I haven't yet worked out how to work around this.