# Conditional include for nested header

**URL:** https://discourse.cmake.org/t/conditional-include-for-nested-header/3212
**Category:** Usage
**Created:** [April 25, 2021, 10:47pm UTC](https://discourse.cmake.org/t/conditional-include-for-nested-header/3212 "2021-04-25T22:47:22Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![William\_Bright](https://discourse.cmake.org/user_avatar/discourse.cmake.org/william_bright/32/1408_2.png) [@William\_Bright](https://discourse.cmake.org/u/William_Bright)
#### Post date: [April 25, 2021, 10:47pm UTC](https://discourse.cmake.org/t/conditional-include-for-nested-header/3212/1 "2021-04-25T22:47:22Z")

</div>

I am running into an issue with a conditional include for a sub directory header. The structure is as follows:

```
project/
    include/foo.h
    src/
        baz.h
        foo.c
        modules/bar/bar.h

```

foo.c has the following import:

```
...
#ifdef ENABLE_MODULE_BAR
#include "modules/bar/bar.h"
#endif

```

bar.h has the following import:

```
...
#include "baz.h" /* <--- causing error */
...

```

So the issue I am having is that the compiler is unable to find “baz.h” as it appears I’d imagine is performing a relative search relative to “modules/bar” rather than underneath “src/”. Does anyone have a way to tackle this?

---

<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: [April 26, 2021, 12:31pm UTC](https://discourse.cmake.org/t/conditional-include-for-nested-header/3212/2 "2021-04-26T12:31:13Z")

</div>

C and C++ includes don’t inherit search directories. When `baz.h` is included from `bar.h`, it’s going to search beside `baz.h`, not the file that included `baz.h`. You can add `project/src` to the include search path explicitly though.
