# RFC: add a NAMESPACE arg to add\_subdirectory()

**URL:** https://discourse.cmake.org/t/rfc-add-a-namespace-arg-to-add-subdirectory/2804
**Category:** Development
**Created:** [February 20, 2021, 9:44am UTC](https://discourse.cmake.org/t/rfc-add-a-namespace-arg-to-add-subdirectory/2804 "2021-02-20T09:44:28Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![leha-bot](https://discourse.cmake.org/user_avatar/discourse.cmake.org/leha-bot/32/921_2.png) [@leha-bot](https://discourse.cmake.org/u/leha-bot)
#### Post date: [February 20, 2021, 9:44am UTC](https://discourse.cmake.org/t/rfc-add-a-namespace-arg-to-add-subdirectory/2804/1 "2021-02-20T09:44:28Z")

</div>

Sometimes we could get a targets names clash while using add\_subdirectory()  
So the most logical way is to add all inner targets at the namespace (as it was solved in C++ at the language level).  
I propose a new syntax for `add_subdirectory(<subdir> NAMESPACE <namespace>)` to adding all created targets inside that directory to the namespace , e.g., consider this tree hierarchy:

```auto
CMakeLists.txt
main.cpp
liba/CMakeLists.txt
libb/CMakeLists.txt

```

CMakeLists:

```auto
# liba and libb both contain the targets "client", so it will be an error in CMake to use it simultaneously.
# But with the NAMESPACEs this problem seems to be solved.
add_subdirectory(liba NAMESPACE LibA)
add_subdirectory(libb NAMESPACE LibB)
add_executable(exec_with_ab main.cpp)
target_link_libraries(exec_with_ab LibA::client LibB::client)

```

N.B.: inside the subdir there are no any introduced namespaces!

It also could be extended to some another commands which could add the targets with the same names, e.g. fetch\_content()

---

<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: [February 20, 2021, 1:52pm UTC](https://discourse.cmake.org/t/rfc-add-a-namespace-arg-to-add-subdirectory/2804/2 "2021-02-20T13:52:55Z")

</div>

Please see [this issue](https://gitlab.kitware.com/cmake/cmake/-/issues/16414) which is basically asking for the same thing.
