Linking static libraries with custom object files

Hi everyone, something that looks basic and as a new one to cmake, I may miss:

Windows environment:
I have two directories A and B
B is a subdirectory of A
Both have their own cmake file:

A:
add_subdirectory(B)
add_library(lib-a a.cpp)
target_link_libraries(lib-a $<TARGET_OBJECTS:lib-b)

B:
add_library(lib-b OBJECT b1.cpp b2.obj)

and this is it. Very simple case
Remarks:
. lib-a is a static library that needs to be linked with lib-b
. lib-b has b1.cpp and b2.obj as source files because b2.obj is generated by a custom rule.
. lib-b is defined as OBJECT and not STATIC since there is no way to tell cmake to link it to lib-a.
You even can’t push the hard code library file path into target_link_library; OBJECT is the way to go.
. In the link command that builds lib-a I can see that b1.obj is included but not b2.obj just as if $<TARGET_OBJECTS:lib-b> includes b1.obj but does not include b2.obj such that finally lib-a is incomplete

There does not seem to be a way to pass a variable from directory B to directory A: this variable would
include the custom object files and I could have added the list to lib-a’s sources.

Am I missing some basic mechanism of cmake since this seems a basic construct?

Thanks in advance for any suggestion

In CMake, static libraries do not “link” (though some linkers will check symbol availability, there’s no actual copying of symbols between libraries; only object files get collected).

I believe that TARGET_OBJECTS is derived from the compilation commands CMake generates and manual .obj files are not considered. I don’t know that CMake provides this abstraction right now. This issue seems to be the one you’d be most interested in.

Thanks Ben for your answer.

And yes I can see that but then what is the recommended method to link those object files. This is not really a corner case.
I could finally solve this problem by defining a custom property on a target that lists all those object files. This is because you can not pass some global list variable from cmake to cmake file. It is cumbersome and ugly - is there some kind of nicer way to do that?

I’m not sure if there’s a supported way of doing it, but you could probably poke around the properties that get queried to see if you can inject you object anywhere. Listing it as an INTERFACE source file might work?

Yes, you can list the objs as sources.

If this is crossing project ‘install’ barrier, you can also install the OBJS and recreate an INTERFACE target with those objs as sources.