# Include upstream folders for header-only libraries

**URL:** <https://discourse.cmake.org/t/include-upstream-folders-for-header-only-libraries/15477>\
**Category:** Code\
**Created:** [January 26, 2026, 10:54am UTC](https://discourse.cmake.org/t/include-upstream-folders-for-header-only-libraries/15477 "2026-01-26T10:54:55Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![nicolamori](https://discourse.cmake.org/user_avatar/discourse.cmake.org/nicolamori/32/1278_2.png) [@nicolamori](https://discourse.cmake.org/u/nicolamori)\
**Post date:** [January 26, 2026, 10:54am UTC](https://discourse.cmake.org/t/include-upstream-folders-for-header-only-libraries/15477/1 "2026-01-26T10:54:55Z")

</div>

I’m writing two C++ project, the upstream one providing some header-only libraries. I wonder what is the right (i.e. modern-CMake) way to “export” the headers folder from upstream and use it in downstream. I know I can export some custom variables but I’d like to stick with a streamlined solution if it exists.

---

<div class="post-metadata">

**Author:** ![retif](https://discourse.cmake.org/user_avatar/discourse.cmake.org/retif/32/1776_2.png) [@retif](https://discourse.cmake.org/u/retif)\
**Post date:** [January 26, 2026, 11:24am UTC](https://discourse.cmake.org/t/include-upstream-folders-for-header-only-libraries/15477/2 "2026-01-26T11:24:33Z")

</div>

If those are two different projects, then I’d make a proper installable [CMake package](https://cmake.org/cmake/help/latest/manual/cmake-packages.7.html#creating-packages) for the upstream project, and then add it to the downstream project with the usual:

```cmake
find_package(UpstreamHeaders CONFIG REQUIRED)
target_link_libraries(${PROJECT_NAME}
    PRIVATE
        upstream::headers # or UpstreamHeaders, or whichever you choose
)

```

---

<div class="post-metadata">

**Author:** ![nicolamori](https://discourse.cmake.org/user_avatar/discourse.cmake.org/nicolamori/32/1278_2.png) [@nicolamori](https://discourse.cmake.org/u/nicolamori)\
**Post date:** [January 26, 2026, 11:52am UTC](https://discourse.cmake.org/t/include-upstream-folders-for-header-only-libraries/15477/3 "2026-01-26T11:52:47Z")

</div>

What I don’t understand is how to define the `upstream::headers` target in the upstream project. I guess that in your example it is an empty library which is used just to include the upstream header folder in downstream targets linking it, right? IF yes, then I cannot create something similar in my upstream project since defining no source file I get this error:

> CMake Error at src/common/CMakeLists.txt:7 (add\_library):  
> No SOURCES given to target: KM3NeTCommon

Or did I misunderstood your suggestion?

---

<div class="post-metadata">

**Author:** ![nicolamori](https://discourse.cmake.org/user_avatar/discourse.cmake.org/nicolamori/32/1278_2.png) [@nicolamori](https://discourse.cmake.org/u/nicolamori)\
**Post date:** [January 26, 2026, 12:05pm UTC](https://discourse.cmake.org/t/include-upstream-folders-for-header-only-libraries/15477/4 "2026-01-26T12:05:14Z")

</div>

Got it:

> add\_library(EmptyLib INTERFACE)  
> target\_include\_directories(EmptyLib INTERFACE $\<BUILD\_INTERFACE:${CMAKE\_SOURCE\_DIR}/include\>)

Thanks for your help!

---

<div class="post-metadata">

**Author:** ![retif](https://discourse.cmake.org/user_avatar/discourse.cmake.org/retif/32/1776_2.png) [@retif](https://discourse.cmake.org/u/retif)\
**Post date:** [January 26, 2026, 12:06pm UTC](https://discourse.cmake.org/t/include-upstream-folders-for-header-only-libraries/15477/5 "2026-01-26T12:06:00Z")

</div>

I didn’t get what you mean either.

A header-only library is declared with:

```cmake
add_library(UpstreamHeaders INTERFACE)

```

and it does not need to have sources. It will need to have `target_include_directories()` with `INTERFACE` scope though (_and the corresponding generator expressions for `BUILD_INTERFACE` and `INSTALL_INTERFACE`_), but that you seem to have figured out.

To make it “namespaced”, one usually does the following:

```cmake
add_library(upstream::headers ALIAS UpstreamHeaders)

```

and also(?) provide `NAMESPACE` argument for the `install()` command that exports target(s).

---

<div class="post-metadata">

**Author:** ![nicolamori](https://discourse.cmake.org/user_avatar/discourse.cmake.org/nicolamori/32/1278_2.png) [@nicolamori](https://discourse.cmake.org/u/nicolamori)\
**Post date:** [January 26, 2026, 2:49pm UTC](https://discourse.cmake.org/t/include-upstream-folders-for-header-only-libraries/15477/6 "2026-01-26T14:49:46Z")

</div>

Sorry for not being clear, my question was basically how to define a header-only library, thanks again for your help.
