irods / irods_docs

iRODS Documentation
3 stars 17 forks source link

Developer documentation: ObjectTargetHelpers.cmake: target_link_objects #210

Open SwooshyCueb opened 1 year ago

SwooshyCueb commented 1 year ago

iRODS makes heavy use of object library targets to group compilation units and cut down on redundant recompilation. Since object library targets are typically intermediate targets used for building executables, shared libraries, and static libraries, they are usually not packaged or exported into CMake targets files. Unfortunately, this makes passing dependencies down from object library targets tricky. Using target_link_libraries like normal is problematic when generating CMake targets files, as all non-import, non-interface targets passed in for linking must be exported along with the linked target. Conversely, using the generator expression $<TARGET_OBJECTS> to specify the object files as source files for the final target does not pass down dependencies from the object library target.

In order to elegantly solve this conundrum, I have written the CMake module ObjectTargetHelpers that includes the function target_link_objects. It works very similarly to target_link_libraries. We should document when and how this function should be used.