# cmake: check\_include\_files failing despite setting CMAKE\_REQUIRED\_INCLUDES

**URL:** https://discourse.cmake.org/t/cmake-check-include-files-failing-despite-setting-cmake-required-includes/2998
**Category:** Usage
**Created:** [March 23, 2021, 4:53pm UTC](https://discourse.cmake.org/t/cmake-check-include-files-failing-despite-setting-cmake-required-includes/2998 "2021-03-23T16:53:03Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![s837jhc](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/s/87869e/32.png) [@s837jhc](https://discourse.cmake.org/u/s837jhc)
#### Post date: [March 23, 2021, 4:53pm UTC](https://discourse.cmake.org/t/cmake-check-include-files-failing-despite-setting-cmake-required-includes/2998/1 "2021-03-23T16:53:03Z")

</div>

I have the following in CMakeLists.txt:

```
check_include_files("foo.h" HAVE_FOO)

```

Despite passing `-DCMAKE_REQUIRED_INCLUDES=/directory/containing/fooincludefile` to cmake, I still get:

```
-- Looking for include file foo.h - not found

```

Is this not the correct usage of `check_include_files` and `CMAKE_REQUIRED_INCLUDES` (per the `check_include_files` [documentation](https://cmake.org/cmake/help/v3.19/module/CheckIncludeFiles.html))? CMakeError.log shows that the `-I/directory/containing/fooincludefile` I was hoping for is not being passed to the compiler.

---

<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: [March 23, 2021, 7:16pm UTC](https://discourse.cmake.org/t/cmake-check-include-files-failing-despite-setting-cmake-required-includes/2998/2 "2021-03-23T19:16:15Z")

</div>

`CMAKE_REQUIRED_INCLUDES` is usually a local variable. Its value is probably being saved and reset at various places, so your cache value probably doesn’t survive until your `check_include_files`. I would recommend logging it before the call.
