# Include directories for target\_precompile\_headers

**URL:** https://discourse.cmake.org/t/include-directories-for-target-precompile-headers/2607
**Category:** Usage
**Created:** [January 22, 2021, 9:56pm UTC](https://discourse.cmake.org/t/include-directories-for-target-precompile-headers/2607 "2021-01-22T21:56:23Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![pauljurczak](https://discourse.cmake.org/user_avatar/discourse.cmake.org/pauljurczak/32/1418_2.png) [@pauljurczak](https://discourse.cmake.org/u/pauljurczak)
#### Post date: [January 22, 2021, 9:56pm UTC](https://discourse.cmake.org/t/include-directories-for-target-precompile-headers/2607/1 "2021-01-22T21:56:23Z")

</div>

I have this `CMakeLists.txt`:

```auto
cmake_minimum_required(VERSION 3.18)
project(ocv VERSION 0.1.0)

find_package(fmt REQUIRED)
find_package(OpenCV REQUIRED)

add_executable(ocv main.cpp grid.cpp)

include_directories(
  /home/paul/include
)

target_precompile_headers(ocv PRIVATE cppCommon.hpp subtCommon.hpp)
...

```

which produces this error on build:

```auto
[build] /home/paul/st/ocv/build/CMakeFiles/ocv.dir/cmake_pch.hxx:5:10: fatal error: /home/paul/st/ocv/cppCommon.hpp: No such file or directory

```

What is the way to define include directories for precompiled headers, if they are located in a different directory than `CMakeLists.txt`? I thought that `include_directories` will do that, and `cppCommon.hpp` is going to be found in `/home/paul/include`. It doesn’t in this case.

---

<div class="post-metadata">

### Author: ![McMartin](https://discourse.cmake.org/user_avatar/discourse.cmake.org/mcmartin/32/150_2.png) [@McMartin](https://discourse.cmake.org/u/McMartin)
#### Post date: [January 23, 2021, 9:29am UTC](https://discourse.cmake.org/t/include-directories-for-target-precompile-headers/2607/2 "2021-01-23T09:29:05Z")

</div>

Quoting [https://cmake.org/cmake/help/git-stage/command/target\_precompile\_headers.html:](https://cmake.org/cmake/help/git-stage/command/target_precompile_headers.html:)

> Header file names specified with angle brackets (e.g. `<unordered_map>` ) or explicit double quotes (escaped for the [`cmake-language(7)`](https://cmake.org/cmake/help/git-stage/manual/cmake-language.7.html#manual:cmake-language(7)), e.g. `[["other_header.h"]]` ) will be treated as is, and include directories must be available for the compiler to find them. Other header file names (e.g. `project_header.h` ) are interpreted as being relative to the current source directory (e.g. [`CMAKE_CURRENT_SOURCE_DIR`](https://cmake.org/cmake/help/git-stage/variable/CMAKE_CURRENT_SOURCE_DIR.html#variable:CMAKE_CURRENT_SOURCE_DIR)) and will be included by absolute path.

So you need to write:

```auto
target_precompile_headers(ocv PRIVATE <cppCommon.hpp> <subtCommon.hpp>)

```

or

```auto
target_precompile_headers(ocv PRIVATE [["cppCommon.hpp"]] [["subtCommon.hpp"]])

```

or

```auto
target_precompile_headers(ocv PRIVATE
  ../../include/cppCommon.hpp
  ../../include/subtCommon.hpp
)

```

---

<div class="post-metadata">

### Author: ![pauljurczak](https://discourse.cmake.org/user_avatar/discourse.cmake.org/pauljurczak/32/1418_2.png) [@pauljurczak](https://discourse.cmake.org/u/pauljurczak)
#### Post date: [January 23, 2021, 6:23pm UTC](https://discourse.cmake.org/t/include-directories-for-target-precompile-headers/2607/3 "2021-01-23T18:23:24Z")

</div>

Thank you. I should have parsed that documentation page more carefully.
