How to specify a list of object in generation expression $<TARGET_OBJECTS:...>

I use cmake version 3.22.2
I have tried follow samples, all of them cannot work.

add_library(libFoo $<TARGET_OBJECTS: obj1 obj2 obj3>)
add_library(libFoo $<TARGET_OBJECTS:obj1;obj2;obj3>)
add_library(libFoo $<TARGET_OBJECTS:obj1\;obj2\;obj3>)

It seems it can only accept one object each time.


But the word “TARGET_OBJECTS” seems misleading…

It is the objects of a target.

Sorry, I can’t understand it, if $<TARGET_OBJECTS:…> can input multiple objects once, could you please show me an example?

It cannot. supports a single target’s object files. If you want multiple, use multiple $<TARGET_OBJECTS> genexes.

Ok, thank you.