Linking a shared library using only objects from an object library

I am following the instructions from the manual to correctly propagate object files from an object library and usage dependencies according to: target_link_libraries — CMake 3.27.0-rc3 Documentation

So I have some CMake logic along the following lines:

add_library(foo OBJECT)
target_sources(foo ...)

add_library(foo-interface INTERFACE)
target_link_libraries(foo-interface INTERFACE foo $<TARGET_OBJECTS:foo>)

add_library(foo-shared SHARED)
target_link_libraries(foo-shared PUBLIC foo-interface)

This does not work, since CMake complains about the library foo-shared being added without having any sources associated with it. It can be solved by specifying target_sources() separately but it sort of defeats the purpose of defining the targets objects on the intermediate interface library. Am I missing something here or is this some missing corner-case or feature?

Target objects should be in the sources of foo-interface.

You should be able to add a dummy.c file or something to it. It’s mainly needed to know what compiler frontend to use for the linking of the library.