# Undocumented Behavior of \`CHECK\_INCLUDE\_FILE\_CXX\` Depending on Policy or Version

**URL:** https://discourse.cmake.org/t/undocumented-behavior-of-check-include-file-cxx-depending-on-policy-or-version/7239
**Category:** Development
**Created:** [January 13, 2023, 10:26am UTC](https://discourse.cmake.org/t/undocumented-behavior-of-check-include-file-cxx-depending-on-policy-or-version/7239 "2023-01-13T10:26:11Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Xaldew](https://discourse.cmake.org/user_avatar/discourse.cmake.org/xaldew/32/3068_2.png) [@Xaldew](https://discourse.cmake.org/u/Xaldew)
#### Post date: [January 13, 2023, 10:26am UTC](https://discourse.cmake.org/t/undocumented-behavior-of-check-include-file-cxx-depending-on-policy-or-version/7239/1 "2023-01-13T10:26:11Z")

</div>

This turned out to be a bit of head-scratcher. The `CHECK_INCLUDE_FILE_CXX` macro changes behavior depending on if the minimum CMake version is below version 3.8 or if policy `CMP0067` is set to `NEW`.

In short, it seems like `CHECK_INCLUDE_FILE_CXX` uses `try_compile` internally and thus only uses the `CMAKE_CXX_STANDARD` when `CMP0067` is set to `NEW` as stated [here](https://cmake.org/cmake/help/latest/policy/CMP0067.html). In my opinion, this should be added to the [documentation](https://cmake.org/cmake/help/latest/module/CheckIncludeFileCXX.html) for the macro. Actually, this should probably be stated in all the `CheckIncludeFile{,s,CXX}` documentation pages.

A small example project is included below showing this behavior, and in case someone wants to test this, this is on an M1 Mac, with extra OpenCL headers installed in $ENV{HOME}/.local/include.

```auto
#cmake_minimum_required(VERSION 3.8)

cmake_minimum_required(VERSION 3.1)
# cmake_policy(SET CMP0067 NEW)

project(TEST C CXX)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Double-check that the OpenCL C++ bindings are present.
find_package(OpenCL 1.2)
if (OpenCL_FOUND)
  cmake_policy(SET CMP0075 NEW)
  include(CheckIncludeFileCXX)
  set(OpenCL_INCLUDE_DIRS "${OpenCL_INCLUDE_DIRS};$ENV{HOME}/.local/include")
  set(CMAKE_REQUIRED_INCLUDES ${OpenCL_INCLUDE_DIRS})
  set(CMAKE_REQUIRED_LIBRARIES ${OpenCL_LIBRARIES})
  CHECK_INCLUDE_FILE_CXX(CL/opencl.hpp OpenCLHPP_FOUND)
  if (NOT OpenCLHPP_FOUND)
    set(OpenCL_FOUND NO)
  endif()
endif()

```

---

<div class="post-metadata">

### Author: ![brad.king](https://discourse.cmake.org/user_avatar/discourse.cmake.org/brad.king/32/11_2.png) [@brad.king](https://discourse.cmake.org/u/brad.king)
#### Post date: [January 13, 2023, 4:04pm UTC](https://discourse.cmake.org/t/undocumented-behavior-of-check-include-file-cxx-depending-on-policy-or-version/7239/2 "2023-01-13T16:04:58Z")

</div>

Most of the `Check*` modules use `try_compile`, so perhaps we need a note in all check module’s documentation, possibly linking to a section somewhere with more details.
