# How to create ALIAS targets for all of my libs in one command?

**URL:** <https://discourse.cmake.org/t/how-to-create-alias-targets-for-all-of-my-libs-in-one-command/2200>\
**Category:** Code\
**Created:** [November 19, 2020, 2:47pm UTC](https://discourse.cmake.org/t/how-to-create-alias-targets-for-all-of-my-libs-in-one-command/2200 "2020-11-19T14:47:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![oliver](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/o/85f322/32.png) [@oliver](https://discourse.cmake.org/u/oliver)\
**Post date:** [November 19, 2020, 2:47pm UTC](https://discourse.cmake.org/t/how-to-create-alias-targets-for-all-of-my-libs-in-one-command/2200/1 "2020-11-19T14:47:04Z")

</div>

I’m in the process of porting my project from GNU Make to CMake, and am now creating the exported CMake file. I want to add all of my exported libraries into a namespace, since that appears to be good practice. However, my understanding is that for “best results” I should also create ALIAS targets for the exported libraries.

Does that mean I have to manually add a line like `add_library(MyProj::foo ALIAS foo)` for _every_ exported library? Or is there a way to have ALIAS targets created automatically for all of my libraries, with a few lines of code? Adding all of these ALIAS targets manually looks error-prone and wordy to me.

---

<div class="post-metadata">

**Author:** ![Angew](https://discourse.cmake.org/user_avatar/discourse.cmake.org/angew/32/229_2.png) [@Angew](https://discourse.cmake.org/u/Angew)\
**Post date:** [November 19, 2020, 2:58pm UTC](https://discourse.cmake.org/t/how-to-create-alias-targets-for-all-of-my-libs-in-one-command/2200/2 "2020-11-19T14:58:51Z")

</div>

You can use a loop:

```
foreach(lib IN ITEMS foo bar baz qux)
  add_library(MyProj::${lib} ALIAS ${lib})
endforeach()
```
