# How to include a generated header without referencing the buidl directory manually?

**URL:** https://discourse.cmake.org/t/how-to-include-a-generated-header-without-referencing-the-buidl-directory-manually/2573
**Category:** Usage
**Tags:** gen:vs
**Created:** [January 19, 2021, 2:34pm UTC](https://discourse.cmake.org/t/how-to-include-a-generated-header-without-referencing-the-buidl-directory-manually/2573 "2021-01-19T14:34:58Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![MichaWiedenmann](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/a9adbd/32.png) [@MichaWiedenmann](https://discourse.cmake.org/u/MichaWiedenmann)
#### Post date: [January 19, 2021, 2:34pm UTC](https://discourse.cmake.org/t/how-to-include-a-generated-header-without-referencing-the-buidl-directory-manually/2573/1 "2021-01-19T14:34:58Z")

</div>

I have a idl-file. During the build a header gets generated in the intermediate directory. How can I include this header in my source?

Currently I am including the header with the path to the intermediate directory. This is suboptimal and fails if another build directory is chosen. I am looking for a way to avoid listing the build/intermediate directory in the include.

My minimal version looks like this:

```
// CMakeList.txt
cmake_minimum_required (VERSION 3.1.2)
project (IDL-TestCase)
add_executable (idl-testcase main.cpp foo.idl)

// main.cpp
#include "../out/idl-testcase.dir/Debug/foo.h" // How to avoid the build directory?

int main() { /* code using IFoo */ }

// foo.idl
import "oaidl.idl";

[
    object,
    uuid(889992c7-3eb5-43d0-a5cf-e733511b87aa),
    version(1.0)
]
interface IFoo
{
    HRESULT foo();
}

```

Thank you for your consideration.

---

<div class="post-metadata">

### Author: ![Angew](https://discourse.cmake.org/user_avatar/discourse.cmake.org/angew/32/229_2.png) [@Angew](https://discourse.cmake.org/u/Angew)
#### Post date: [January 19, 2021, 4:59pm UTC](https://discourse.cmake.org/t/how-to-include-a-generated-header-without-referencing-the-buidl-directory-manually/2573/2 "2021-01-19T16:59:05Z")

</div>

Add the appropriate binary directory to your include search path, e.g.

```
include_directories(${CMAKE_CURRENT_BINARY_DIR})

```

or

```
target_include_directories(idl-testcase PRIVATE ${CMAKE_CURRENT_BINARY_DIR})

```

If the files are not directly in the binary dir, but some subdirectory thereof, modify the path accordingly,. In your case, it seems `${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>` might be required.

---

<div class="post-metadata">

### Author: ![MichaWiedenmann](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/a9adbd/32.png) [@MichaWiedenmann](https://discourse.cmake.org/u/MichaWiedenmann)
#### Post date: [January 25, 2021, 10:05am UTC](https://discourse.cmake.org/t/how-to-include-a-generated-header-without-referencing-the-buidl-directory-manually/2573/3 "2021-01-25T10:05:32Z")

</div>

> [@Angew](#):
>
> ```
> ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>
> 
> ```

results in `out/Debug`. That means the `idl-testcase.dir` part of `out/idl-testcase.dir/Debug/foo.h` is still missing. It seems the “intermediate directory” (`idl-testcase.dir`) is difficult to get hold of. So I use

```
include_directories(${CMAKE_CURRENT_BINARY_DIR}/idl-testcase.dir/$<CONFIG>)

```

Ideally I would get rid of the `idl-testcase.dir` though.
