# How to properly include header files

**URL:** https://discourse.cmake.org/t/how-to-properly-include-header-files/4762
**Category:** Code
**Tags:** os:windows
**Created:** [January 2, 2022, 6:20pm UTC](https://discourse.cmake.org/t/how-to-properly-include-header-files/4762 "2022-01-02T18:20:27Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![kartachovd](https://discourse.cmake.org/user_avatar/discourse.cmake.org/kartachovd/32/2069_2.png) [@kartachovd](https://discourse.cmake.org/u/kartachovd)
#### Post date: [January 2, 2022, 6:20pm UTC](https://discourse.cmake.org/t/how-to-properly-include-header-files/4762/1 "2022-01-02T18:20:27Z")

</div>

I’m so sorry if this has been asked before but I’ve scoured around and I can’t find a suitable answer for my question! Let’s say my project structure is as follows:

- **Engine**
  - **Components**
    - _bunch of .h files_

  - **Tools**
    - Vector.cpp
    - Vector.h

  - main.cpp

I want CMake to build a Visual Studio project from this called “Engine” with the exact same folder structure and set the “include directories” to point to **C:/Projects/Engine**. That way all I have to do is `#include Tools/Vector.h` for instance in any .cpp file. I don’t want to make a library for each of my “tools”. How can this be done?

---

<div class="post-metadata">

### Author: ![petwu](https://discourse.cmake.org/user_avatar/discourse.cmake.org/petwu/32/1399_2.png) [@petwu](https://discourse.cmake.org/u/petwu)
#### Post date: [January 4, 2022, 1:09pm UTC](https://discourse.cmake.org/t/how-to-properly-include-header-files/4762/2 "2022-01-04T13:09:31Z")

</div>

I assume you are building an executable (because of `main.cpp`) and that your `CMakeLists.txt` resides in the `Engine/` directory. Then setting the include paths should be as easy as:

```cmake
target_include_directories(Engine PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}")

```

If your building a library instead or your executable provides any `INTERFACE`/`PUBLIC` headers (e.g. for plugins) then once you intend to package/install your artifacts you need to use the `$<BUILD_INTERFACE:...>` and `$<INSTALL_INTERFACE:...>` generator expressions as documented for the [target\_include\_directories()](https://cmake.org/cmake/help/latest/command/target_include_directories.html) command.

For managing the folder structure of the generated Visual Studio project have a look at the [source\_group()](https://cmake.org/cmake/help/latest/command/source_group.html) command. But since Visual Studio has [built-in support for CMake](https://docs.microsoft.com/cpp/build/cmake-projects-in-visual-studio) since 2015 (IMHO pretty decent one since 2019), I would recommend using that instead of generating solution and project files. With the built-in support you have a direct view onto your directory structure, have to bother less about IDE-specific things and can leverage many nice features like presets or faster builds with Ninja.
