Can OBJECT libraries be EXCLUDED_FROM_ALL?

Hello,

Currently using version 3.14.4, and experimenting with OBJECT libraries (https://cmake.org/cmake/help/v3.14/command/add_library.html#object-libraries)

Just ran a few tests, but it seems that targets added via add_library(foo OBJECT <sources>) are added by default to the “all” target (at least by the make generator). Seems like a reasonable default, as it is the case for other add_library variants.

Now: Although it is not mentioned in the docs, it seems that add_library(foo OBJECT EXCLUDE_FROM_ALL <sources>) works as expected, i.e. that the “foo” target is not built by default, but will be built if another target “depends” on it via something like add_executable(Bar $<TARGET_OBJECTS:foo>)

The question: Can we rely on this behavior?

Probably. If you add a test for your use case to CMake itself, it will ensure it doesn’t get accidentally get broken in the future. (Tests/ObjectLibrary seems like the likely place to add it).

Adding this to the docs seems good. Though I’d be surprised if it were special for OBJECT libraries in particular.