# Creating subdirectories within \`\_deps\` when using FetchContent

**URL:** https://discourse.cmake.org/t/creating-subdirectories-within-deps-when-using-fetchcontent/10108
**Category:** Usage
**Created:** [February 15, 2024, 5:19pm UTC](https://discourse.cmake.org/t/creating-subdirectories-within-deps-when-using-fetchcontent/10108 "2024-02-15T17:19:50Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Vink](https://discourse.cmake.org/user_avatar/discourse.cmake.org/vink/32/4315_2.png) [@Vink](https://discourse.cmake.org/u/Vink)
#### Post date: [February 15, 2024, 5:19pm UTC](https://discourse.cmake.org/t/creating-subdirectories-within-deps-when-using-fetchcontent/10108/1 "2024-02-15T17:19:50Z")

</div>

Hello,

I am developing a small embedded system project, and have chosen CMake to be our build generator. I have a bunch of components being developed independently, and brought into the main project using the FetchContent command. The current problem I’m facing (more of an annoyance) is that each target is being installed under `build/Debug/_deps`. Is there a way to create subdirectories within the `_deps` directory to better organize all my dependencies? For example, creating a `build/Debug/_deps/uart_deps` for my UART components?

Thanks,  
Vink

---

<div class="post-metadata">

### Author: ![ClausKlein](https://discourse.cmake.org/user_avatar/discourse.cmake.org/clausklein/32/352_2.png) [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)
#### Post date: [February 15, 2024, 6:38pm UTC](https://discourse.cmake.org/t/creating-subdirectories-within-deps-when-using-fetchcontent/10108/2 "2024-02-15T18:38:22Z")

</div>

- Do you want to control were `libs` and `exe` are build?
- Or do you meean, were the sources are cloned?

For first one, this helps:

```cmake
set(stageDir ${CMAKE_CURRENT_BINARY_DIR}/stage)
include(GNUInstallDirs)

if(NOT CMAKE_RUNTIME_OUTPUT_DIRECTORY)
  set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${stageDir}/${CMAKE_INSTALL_BINDIR})
endif()
if(NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY)
  set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${stageDir}/${CMAKE_INSTALL_LIBDIR})
endif()
if(NOT CMAKE_ARCHIVE_OUTPUT_DIRECTORY)
  set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${stageDir}/${CMAKE_INSTALL_LIBDIR})
endif()

```

---

<div class="post-metadata">

### Author: ![Vink](https://discourse.cmake.org/user_avatar/discourse.cmake.org/vink/32/4315_2.png) [@Vink](https://discourse.cmake.org/u/Vink)
#### Post date: [February 16, 2024, 5:53pm UTC](https://discourse.cmake.org/t/creating-subdirectories-within-deps-when-using-fetchcontent/10108/3 "2024-02-16T17:53:20Z")

</div>

Hi Claus,

Thanks for your reply, I mean where the sources are cloned.

---

<div class="post-metadata">

### Author: ![ClausKlein](https://discourse.cmake.org/user_avatar/discourse.cmake.org/clausklein/32/352_2.png) [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)
#### Post date: [February 16, 2024, 6:27pm UTC](https://discourse.cmake.org/t/creating-subdirectories-within-deps-when-using-fetchcontent/10108/4 "2024-02-16T18:27:50Z")

</div>

[FetchContent — CMake 3.29.0-rc1 Documentation](https://cmake.org/cmake/help/latest/module/FetchContent.html#variable:FETCHCONTENT_SOURCE_DIR_%3CuppercaseName%3E)

see `FETCHCONTENT_BASE_DIR`

---

<div class="post-metadata">

### Author: ![ClausKlein](https://discourse.cmake.org/user_avatar/discourse.cmake.org/clausklein/32/352_2.png) [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)
#### Post date: [February 16, 2024, 8:26pm UTC](https://discourse.cmake.org/t/creating-subdirectories-within-deps-when-using-fetchcontent/10108/5 "2024-02-16T20:26:38Z")

</div>

With CPM.cmake you would have more options:

- With `CPM.cmake`, you may use a central cache for the cloned external projects.
- Wo it is very fast, if found in `cpm_source_cache`.
- And you have the option to use local installed packages if found (`CPM_USE_LOCAL_PACKAGES`).

see [CPM.cmake options](https://github.com/cpm-cmake/CPM.cmake/tree/master?tab=readme-ov-file#cpm_source_cache)

---

<div class="post-metadata">

### Author: ![Vink](https://discourse.cmake.org/user_avatar/discourse.cmake.org/vink/32/4315_2.png) [@Vink](https://discourse.cmake.org/u/Vink)
#### Post date: [February 16, 2024, 8:32pm UTC](https://discourse.cmake.org/t/creating-subdirectories-within-deps-when-using-fetchcontent/10108/6 "2024-02-16T20:32:19Z")

</div>

Setting the `FETCHCONTENT_BASE_DIR` var solved my problem, but it seems that the CPM.cmake tool makes everything a lot cleaner! Thanks for the recommendation!
