# Automatically wrapping a static library in "whole-archive"/"no-whole-archive" when used during linking

**URL:** https://discourse.cmake.org/t/automatically-wrapping-a-static-library-in-whole-archive-no-whole-archive-when-used-during-linking/5883
**Category:** Code
**Created:** [June 17, 2022, 7:58am UTC](https://discourse.cmake.org/t/automatically-wrapping-a-static-library-in-whole-archive-no-whole-archive-when-used-during-linking/5883 "2022-06-17T07:58:16Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![marc.chevrier](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/ecb155/32.png) [@marc.chevrier](https://discourse.cmake.org/u/marc.chevrier)
#### Post date: [June 17, 2022, 8:08am UTC](https://discourse.cmake.org/t/automatically-wrapping-a-static-library-in-whole-archive-no-whole-archive-when-used-during-linking/5883/2 "2022-06-17T08:08:59Z")

</div>

Starting with `CMake` 3.24 (currently in RC1), you can use [$\<LINK\_LIBRARY\>](https://cmake.org/cmake/help/v3.24/manual/cmake-generator-expressions.7.html#output-related-expressions) generator expression with feature `WHOLE_ARCHIVE` to achieve what you want:

```cmake
add_library(L INTERFACE)
target_link_libraries(L INTERFACE "$<LINK_LIBRARY:WHOLE_ARCHIVE,internal_L>")

```

---

_[View the full topic](https://discourse.cmake.org/t/automatically-wrapping-a-static-library-in-whole-archive-no-whole-archive-when-used-during-linking/5883)._
