# Can OBJECT libraries be EXCLUDED\_FROM\_ALL?

**URL:** <https://discourse.cmake.org/t/can-object-libraries-be-excluded-from-all/357>\
**Category:** Code\
**Created:** [December 12, 2019, 6:25am UTC](https://discourse.cmake.org/t/can-object-libraries-be-excluded-from-all/357 "2019-12-12T06:25:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eric\_Malenfant](https://discourse.cmake.org/user_avatar/discourse.cmake.org/eric_malenfant/32/244_2.png) [@Eric\_Malenfant](https://discourse.cmake.org/u/Eric_Malenfant)\
**Post date:** [December 12, 2019, 6:25am UTC](https://discourse.cmake.org/t/can-object-libraries-be-excluded-from-all/357/1 "2019-12-12T06:25:34Z")

</div>

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](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?

---

<div class="post-metadata">

**Author:** ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)\
**Post date:** [December 12, 2019, 1:19pm UTC](https://discourse.cmake.org/t/can-object-libraries-be-excluded-from-all/357/2 "2019-12-12T13:19:25Z")

</div>

> [@Eric\_Malenfant](#):
>
> 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).

> [@Eric\_Malenfant](#):
>
> Although it is not mentioned in the docs, it seems that `add_library(foo OBJECT EXCLUDE_FROM_ALL <sources>)` works as expected

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