# add\_subdirectory() for Git Submodules without CMakeLists.txt?

**URL:** https://discourse.cmake.org/t/add-subdirectory-for-git-submodules-without-cmakelists-txt/14085
**Category:** Usage
**Tags:** gen:ninja
**Created:** [May 13, 2025, 5:58pm UTC](https://discourse.cmake.org/t/add-subdirectory-for-git-submodules-without-cmakelists-txt/14085 "2025-05-13T17:58:03Z")
**Posts on this page:** 1
**Showing post:** 1

<div class="post-metadata">

### Author: ![bmcdonnell-fb](https://discourse.cmake.org/user_avatar/discourse.cmake.org/bmcdonnell-fb/32/5561_2.png) [@bmcdonnell-fb](https://discourse.cmake.org/u/bmcdonnell-fb)
#### Post date: [May 13, 2025, 5:58pm UTC](https://discourse.cmake.org/t/add-subdirectory-for-git-submodules-without-cmakelists-txt/14085/1 "2025-05-13T17:58:03Z")

</div>

I have a CMake project using the Ninja generator and GNU Arm Embedded Toolchain, with libraries in Git submodules. I’d like to be able to add the libraries using `add_subdirectory()` or similar, with its scoping features, without needing a `CMakeLists.txt` in the subdirs. This would allow me to _use the repos unmodified from upstream_ (since they don’t have `CMakeLists.txt` files), and maintain my own `CMakeLists.txt` files in the main project.

To date, I’ve been using `add_subdirectory()` with forks of the library repos, with `CMakeLists.txt` added in each. Existing project structure is like this:

```auto
MyCMakeProject/
├── CMakeLists.txt
├── src/
│ ├── CMakeLists.txt
│ └── main.cpp
├── libs/
│ ├── CMakeLists.txt
│ ├── library1/
│ │ ├── CMakeLists.txt
│ │ └── library1.cpp
│ └── library2/
│ ├── CMakeLists.txt
│ └── library2.cpp

```

Using the upstream repos means `libs/library[12]/CMakeLists.txt` files will go away.

From what I’ve read, it seems like my options are:

1. Use `include()` instead of `add_subdirectory()`. This means no separate CMake scopes, and everything gets built directly into the main project.
2. Add extra subdirs for the upstream repos, such as shown below, to be able to continue to use `add_subdirectory()`.

```auto
MyCMakeProject/
├── CMakeLists.txt
├── src/
│ ├── CMakeLists.txt
│ └── main.cpp
├── libs/
│ ├── CMakeLists.txt
│ ├── library1/
│ │ ├── CMakeLists.txt
│ │ └── upstream-repo/
│ │ └── library1.cpp
│ └── library2/
│ ├── CMakeLists.txt
│ └── upstream-repo/
│ └── library2.cpp

```

Questions:

1. Is my analysis correct, that these are my options?
2. Is there a way to provide `CMakeLists.txt` to `add_subdirectory()` from outside the subdir?
3. If not, would developers consider adding such a feature?

---

_[View the full topic](https://discourse.cmake.org/t/add-subdirectory-for-git-submodules-without-cmakelists-txt/14085)._
