# Should target\_link\_options(staticLib PRIVATE -lfoo) pierce through static libs to the head target?

**URL:** https://discourse.cmake.org/t/should-target-link-options-staticlib-private-lfoo-pierce-through-static-libs-to-the-head-target/3651
**Category:** Development
**Created:** [June 29, 2021, 8:04am UTC](https://discourse.cmake.org/t/should-target-link-options-staticlib-private-lfoo-pierce-through-static-libs-to-the-head-target/3651 "2021-06-29T08:04:49Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![alcroito](https://discourse.cmake.org/user_avatar/discourse.cmake.org/alcroito/32/186_2.png) [@alcroito](https://discourse.cmake.org/u/alcroito)
#### Post date: [June 29, 2021, 8:04am UTC](https://discourse.cmake.org/t/should-target-link-options-staticlib-private-lfoo-pierce-through-static-libs-to-the-head-target/3651/1 "2021-06-29T08:04:49Z")

</div>

Currently if one calls `target_link_libraries(staticLib PRIVATE myLib)` the implementation of `target_link_libraries` ensures to also add a `$<LINK_ONLY:myLib`\> on staticLib’s `INTERFACE_LINK_LIBRARIES`.

> <https://github.com/Kitware/CMake/blob/master/Source/cmTargetLinkLibrariesCommand.cxx#L496>

Should the same be done for link options as well, given that link options don’t make sense / are not used when archiving a static library?

From docs:  
[https://cmake.org/cmake/help/latest/command/target\_link\_options.html](https://cmake.org/cmake/help/latest/command/target_link_options.html)

> This command cannot be used to add options for static library targets, since they do not use a linker.

---

<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: [June 29, 2021, 1:34pm UTC](https://discourse.cmake.org/t/should-target-link-options-staticlib-private-lfoo-pierce-through-static-libs-to-the-head-target/3651/2 "2021-06-29T13:34:15Z")

</div>

Link options should be looked at when `$<LINK_ONLY:>` is used. Are they not?

@brad.king I would think it should, but I don’t see any tests for it. Would likely need a policy to change that though.

---

<div class="post-metadata">

### Author: ![brad.king](https://discourse.cmake.org/user_avatar/discourse.cmake.org/brad.king/32/11_2.png) [@brad.king](https://discourse.cmake.org/u/brad.king)
#### Post date: [June 29, 2021, 1:40pm UTC](https://discourse.cmake.org/t/should-target-link-options-staticlib-private-lfoo-pierce-through-static-libs-to-the-head-target/3651/3 "2021-06-29T13:40:18Z")

</div>

Cc: @marc.chevrier

See policy [CMP0099](https://cmake.org/cmake/help/latest/policy/CMP0099.html).

---

<div class="post-metadata">

### Author: ![alcroito](https://discourse.cmake.org/user_avatar/discourse.cmake.org/alcroito/32/186_2.png) [@alcroito](https://discourse.cmake.org/u/alcroito)
#### Post date: [June 29, 2021, 2:04pm UTC](https://discourse.cmake.org/t/should-target-link-options-staticlib-private-lfoo-pierce-through-static-libs-to-the-head-target/3651/4 "2021-06-29T14:04:05Z")

</div>

Right. I couldn’t find relevant mentions of the behaviour in the docs of target\_link\_options / target\_link\_libraries and the associated properties  
My test project was setting 3.14 as the minimum version.

Increasing the cmake minimum version which enables the policy does indeed propagate the link options.  
Thanks!
