# How to add dynamically generated headers directory?

**URL:** https://discourse.cmake.org/t/how-to-add-dynamically-generated-headers-directory/11623
**Category:** Usage
**Created:** [September 9, 2024, 11:59am UTC](https://discourse.cmake.org/t/how-to-add-dynamically-generated-headers-directory/11623 "2024-09-09T11:59:43Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![arun.mani](https://discourse.cmake.org/user_avatar/discourse.cmake.org/arun.mani/32/3764_2.png) [@arun.mani](https://discourse.cmake.org/u/arun.mani)
#### Post date: [September 9, 2024, 11:59am UTC](https://discourse.cmake.org/t/how-to-add-dynamically-generated-headers-directory/11623/1 "2024-09-09T11:59:43Z")

</div>

Hii all.

I have a C project. This project has depends on a library named `bar`. `bar` is built using a custom command. However the issue is, the headers of the `bar` library is also available only after `bar` is built. In such a scenario, how would I let my top-level project refer to headers of `bar`?

```auto
$ tree .
.
├── bar
│ ├── baz
│ │ ├── baz.c
│ │ └── baz.h
│ ├── build.sh
│ └── CMakeLists.txt
├── CMakeLists.txt
└── foo.c

```

- My project - `foo` (`CMakeLists.txt`, `foo.c`)
- Library generated via custom command - `bar` (everything inside `bar/`).

The thing is, `bar`’s `CMakeLists.txt` calls `build.sh`. `build.sh` does _some magic_ and generates static library `libbar.a` and directory `include/` inside `bar/build` directory.

But since, the `include` directory is generated on-the-fly, I’m not able to set the include directories in `bar/CMakeLists.txt`.

From the top-level folder, if I do `cmake -S . -B build`, I get:

```sh
-- The C compiler identification is GNU 13.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Configuring done (0.3s)
CMake Error in CMakeLists.txt:
  Imported target "bar" includes non-existent path

    "/path/to/foo/bar/build/include"

  in its INTERFACE_INCLUDE_DIRECTORIES. Possible reasons include:

  * The path was deleted, renamed, or moved to another location.

  * An install or uninstall procedure did not complete successfully.

  * The installation package was faulty and references files it does not
  provide.
-- Generating done (0.0s)
CMake Generate step failed. Build files cannot be regenerated correctly.

```

A minimal reproducible example - [https://upload.disroot.org/r/aEsMT86V#ai/jUmC2bmro3BqRRD4KkNuDddajAt7+c+z1+YT32QQ=](https://upload.disroot.org/r/aEsMT86V#ai/jUmC2bmro3BqRRD4KkNuDddajAt7+c+z1+YT32QQ=)

Two solutions I could think of:

1. Force users to run `bar/build.sh` manually before configuring the project.
2. Include empty include directories in `bar/build`, so when CMake sees it, the paths at least exist.

The disadvantage of 1 is, users lose convenience of just running `cmake -S . -B build`.  
The disadvantage of 2 is, to enable cross-compilation of bar, I need to create empty directories for all the targets.

(CMake newbie here 😅)  
Thanks!

[In real life, the `bar` is a very big project in its own and the headers generated by it are multiple and nested…]
