# Is there a way to download and include just a header from Boost?

**URL:** https://discourse.cmake.org/t/is-there-a-way-to-download-and-include-just-a-header-from-boost/11054
**Category:** Code
**Created:** [June 19, 2024, 10:11am UTC](https://discourse.cmake.org/t/is-there-a-way-to-download-and-include-just-a-header-from-boost/11054 "2024-06-19T10:11:38Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![rturrado](https://discourse.cmake.org/user_avatar/discourse.cmake.org/rturrado/32/3499_2.png) [@rturrado](https://discourse.cmake.org/u/rturrado)
#### Post date: [June 19, 2024, 10:11am UTC](https://discourse.cmake.org/t/is-there-a-way-to-download-and-include-just-a-header-from-boost/11054/1 "2024-06-19T10:11:38Z")

</div>

I am using `boost::dynamic_bitset` in one of my projects.

Is there a way to tell CMake to just download that header and have it available, without 1) having to download the whole of Boost, and 2) having to compile anything (I’m not going to link against anything)?

Then, later, I would `target_include_directories(my_target PRIVATE ${Boost_INCLUDE_HEADERS})`.

---

<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: [June 19, 2024, 12:04pm UTC](https://discourse.cmake.org/t/is-there-a-way-to-download-and-include-just-a-header-from-boost/11054/2 "2024-06-19T12:04:41Z")

</div>

- see discussions here [right now it's not possible to add boost properly using CPM · Issue #501 · cpm-cmake/CPM.cmake · GitHub](https://github.com/cpm-cmake/CPM.cmake/issues/501)
- and [FetchContent with Boost](https://discourse.cmake.org/t/fetchcontent-with-boost/6596)

---

<div class="post-metadata">

### Author: ![rturrado](https://discourse.cmake.org/user_avatar/discourse.cmake.org/rturrado/32/3499_2.png) [@rturrado](https://discourse.cmake.org/u/rturrado)
#### Post date: [June 19, 2024, 12:19pm UTC](https://discourse.cmake.org/t/is-there-a-way-to-download-and-include-just-a-header-from-boost/11054/3 "2024-06-19T12:19:43Z")

</div>

Many thanks @ClausKlein.

Just a confirmation, because I don’t really see it in those threads. Both with CPM and FetchContent with Boost you always have to download the whole of Boost, right?

---

<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: [June 19, 2024, 2:08pm UTC](https://discourse.cmake.org/t/is-there-a-way-to-download-and-include-just-a-header-from-boost/11054/4 "2024-06-19T14:08:22Z")

</div>

Yes, at least the source distribution without root `CMakeLists.txt`

Most boost libs depend on other boost libs!  
The `boost::dynamic_bitset` is not a standalone git submodule like `boost::asio`!

```bash
bash-5.2$ head -25 *.hpp */*.hpp | grep -w include | sort -u | grep -w boost
#include "boost/assert.hpp"
#include "boost/config.hpp"
#include "boost/detail/workaround.hpp"
#include "boost/dynamic_bitset/dynamic_bitset.hpp"
#include "boost/integer/integer_log2.hpp"
#include <boost/core/allocator_access.hpp>
#include <boost/core/nvp.hpp>
bash-5.2$ 

```

---

<div class="post-metadata">

### Author: ![rturrado](https://discourse.cmake.org/user_avatar/discourse.cmake.org/rturrado/32/3499_2.png) [@rturrado](https://discourse.cmake.org/u/rturrado)
#### Post date: [June 19, 2024, 2:38pm UTC](https://discourse.cmake.org/t/is-there-a-way-to-download-and-include-just-a-header-from-boost/11054/5 "2024-06-19T14:38:33Z")

</div>

Ah, OK, I understand. Thanks for the explanation @ClausKlein.

In that case, I will probably stick to what I’m doing now, that is to:

- request `boost/1.85.0` via Conan,
- indicating that I only want headers (option `boost/*:header_only=True`), i.e., that I don’t want to compile boost and link against anything, and
- add `Boost_INCLUDE_DIRS` to my target’s include directories.

So this in `conanfile.py`:

```auto
    def requirements(self):
        self.requires("boost/1.85.0")

```

This in a conan profile:

```auto
[options]
boost/*:header_only=True

```

Then this in `CMakeLists.txt`:

```auto
find_package(Boost REQUIRED)
target_include_directories(my_target PUBLIC
    "${Boost_INCLUDE_DIRS}"
)

```
