# CMake installing or exporting in monorepo

**URL:** <https://discourse.cmake.org/t/cmake-installing-or-exporting-in-monorepo/6454>\
**Category:** Code\
**Created:** [September 9, 2022, 11:12pm UTC](https://discourse.cmake.org/t/cmake-installing-or-exporting-in-monorepo/6454 "2022-09-09T23:12:30Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![technic](https://discourse.cmake.org/user_avatar/discourse.cmake.org/technic/32/2761_2.png) [@technic](https://discourse.cmake.org/u/technic)\
**Post date:** [September 9, 2022, 11:12pm UTC](https://discourse.cmake.org/t/cmake-installing-or-exporting-in-monorepo/6454/1 "2022-09-09T23:12:30Z")

</div>

What is the difference between installing and exporting? I have a monorepo with few libs and apps added with add\_subdirectory() to root CMakeLists.txt. I want to be able to open a single app project separately (without need for clangd to read all libs and other apps). But this project should be able to link and find headers to existing libs set as a dependencies with target\_link\_libraries(). What is the best solution here?

---

<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:** [September 10, 2022, 11:37am UTC](https://discourse.cmake.org/t/cmake-installing-or-exporting-in-monorepo/6454/2 "2022-09-10T11:37:15Z")

</div>

Installing places your build artifacts in some “prefix” in a (hopefully) standard layout relevant for the platform. Exporting, in CMake, is putting information about the targets your build makes in a form that other projects can use them (usually through a `find_package()` call). You can export to the build tree (the `export()` command) or to the install tree (using `install(EXPORT)`). They are different because they each have different paths in them (e.g., where headers live).

---

<div class="post-metadata">

**Author:** ![technic](https://discourse.cmake.org/user_avatar/discourse.cmake.org/technic/32/2761_2.png) [@technic](https://discourse.cmake.org/u/technic)\
**Post date:** [September 12, 2022, 9:45pm UTC](https://discourse.cmake.org/t/cmake-installing-or-exporting-in-monorepo/6454/3 "2022-09-12T21:45:19Z")

</div>

Ok, so if I want to edit file in place I should use export() ?

---

<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:** [September 14, 2022, 8:52pm UTC](https://discourse.cmake.org/t/cmake-installing-or-exporting-in-monorepo/6454/4 "2022-09-14T20:52:57Z")

</div>

What do you mean? These files are written by CMake and not meant to be edited afterwards.

---

<div class="post-metadata">

**Author:** ![technic](https://discourse.cmake.org/user_avatar/discourse.cmake.org/technic/32/2761_2.png) [@technic](https://discourse.cmake.org/u/technic)\
**Post date:** [September 14, 2022, 9:30pm UTC](https://discourse.cmake.org/t/cmake-installing-or-exporting-in-monorepo/6454/5 "2022-09-14T21:30:30Z")

</div>

No, I mean I have

```auto
MyMonorepo/
├── LibA/
│ ├── CMakeLists.txt
│ ├── include/
│ │ └── libA.hpp
│ └── src/
│ └── ...
└── AppFoo/
    ├── CMakeLists.txt
    └── src/
        ├── main.cpp
        └── ...

```

Then I want to run CMake against LibA once which should install or export this library, and then open only AppFoo/CMakeLists.txt in my IDE. Then I ctrl+click on the LibA::SomeClass in the main.cpp and jump to LibA/libA.hpp file inside MyMonorepo, but not inside some temporary build directory. Does this makes sense?

---

<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:** [September 15, 2022, 1:54pm UTC](https://discourse.cmake.org/t/cmake-installing-or-exporting-in-monorepo/6454/6 "2022-09-15T13:54:26Z")

</div>

That sounds more like an IDE support thing. However, exports don’t contain that kind of information (sources are generally not mentioned in exported targets).

---

<div class="post-metadata">

**Author:** ![technic](https://discourse.cmake.org/user_avatar/discourse.cmake.org/technic/32/2761_2.png) [@technic](https://discourse.cmake.org/u/technic)\
**Post date:** [September 15, 2022, 3:01pm UTC](https://discourse.cmake.org/t/cmake-installing-or-exporting-in-monorepo/6454/7 "2022-09-15T15:01:56Z")

</div>

Include paths must be mentioned in the exported targets.

---

<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:** [September 15, 2022, 3:19pm UTC](https://discourse.cmake.org/t/cmake-installing-or-exporting-in-monorepo/6454/8 "2022-09-15T15:19:28Z")

</div>

Ah, yes, that will get you headers. If you use the build tree, you’ll get the actual headers. If you use the installed export, you’ll get the installed header copies.

---

<div class="post-metadata">

**Author:** ![technic](https://discourse.cmake.org/user_avatar/discourse.cmake.org/technic/32/2761_2.png) [@technic](https://discourse.cmake.org/u/technic)\
**Post date:** [September 15, 2022, 4:09pm UTC](https://discourse.cmake.org/t/cmake-installing-or-exporting-in-monorepo/6454/9 "2022-09-15T16:09:59Z")

</div>

@ben.boeckel yes that’s clear now thanks! So using export() instead of install() in the use-case I’ve explained above make sense, right?
