Object library fails to propagate object files transitively
Reproducer: https://github.com/friendlyanon/object-repro
Failing build output: https://github.com/friendlyanon/object-repro/actions/runs/1190316860
Error:
/usr/bin/ld: CMakeFiles/main_lib.dir/source/lib.c.o: in function `function':
lib.c:(.text+0x9): undefined reference to `function_impl'
collect2: error: ld returned 1 exit status
Fix: https://github.com/friendlyanon/object-repro/commit/ed9427956d2b858f6870fe991097e35d6e672274
Object Libraries may "link" to other object libraries to get usage requirements, but since they do not have a link step nothing is done with their object files. Continuing from the above example, the code:
[...]
compiles obj2.c with -DA -DOBJ, creates executable main2 with object files from main2.c and obj2.c, and links main2 to A.In other words, when Object Libraries appear in a target's INTERFACE_LINK_LIBRARIES property they will be treated as Interface Libraries, but when they appear in a target's LINK_LIBRARIES property their object files will be included in the link too.
My use-case is to seal off platform dependent implementations in its own object library, which is a part of the library component of an executable. The library component itself is an object library, so it can be used to test the library component of the executable.
Code: https://github.com/friendlyanon/adhoc-server/blob/c3311cc1c3b9e7d54a2a1cbc7abe5b50ad32782e/CMakeLists.txt#L20