# How to make a subproject to be inside a project?

**URL:** https://discourse.cmake.org/t/how-to-make-a-subproject-to-be-inside-a-project/5365
**Category:** Code
**Created:** [April 4, 2022, 2:48pm UTC](https://discourse.cmake.org/t/how-to-make-a-subproject-to-be-inside-a-project/5365 "2022-04-04T14:48:04Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![kvpfs](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/k/76d3ee/32.png) [@kvpfs](https://discourse.cmake.org/u/kvpfs)
#### Post date: [April 4, 2022, 2:48pm UTC](https://discourse.cmake.org/t/how-to-make-a-subproject-to-be-inside-a-project/5365/1 "2022-04-04T14:48:04Z")

</div>

Hello. Let’s imagine a situation - there is a main project MainPrj and a subroject SubPrj, which is fetched as git submodule. SubPrj is self-sufficient cmake project with its own install target. MainPrj is mine, SubPrj is someone else’s, i can not modify it. If i add SubPrj to MainPrj via add\_subdirectory(), then the install target will populate a destination as if the projects are independent of each other, each in its own directory. I would like SubPrj to be installed under some MainPrj install directory. For exapmle - desired install layout:

```auto
usr/
└── include
    └── MainPrj
        ├── main.h
        └── SubPrj
            └── sub.h

```

I.e, I would like to somehow set the prefix for SubPrj, so that SubPrj is used exclusive by MainPrj and does not create any name collisions in the global space. Do I have any options besides installing in /opt or rewriting CMakeLists.txt for SubPrj? I have considered ExternalProject\_add() and execut\_process(), but I don’t think that it is what i need . Thank you in advance.

---

<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: [April 4, 2022, 3:22pm UTC](https://discourse.cmake.org/t/how-to-make-a-subproject-to-be-inside-a-project/5365/2 "2022-04-04T15:22:17Z")

</div>

If `SubPj` doesn’t allow for manipulation of its install prefixes through variables (such as `GNUInstallDirs`) or other means, you’ll have to patch it. Said another way, if a project just says `DESTINATION "include/me"` literally, there’s no override available for it.
