CheckIncludeFiles — CMake 4.4.3 Documentation

# CheckIncludeFiles

This module provides a command to check one or more C/C++ header files.

Load this module in a CMake project with:

    include(CheckIncludeFiles)

## Commands

This module provides the following command:

check_include_files

  Checks once whether one or more header files exist and can be included together in C or C++ code:

      check_include_files(<includes> <variable> [LANGUAGE <language>])

  The arguments are:

  `<includes>`

    A semicolon-separated list of header files to be checked.

  `<variable>`

    The name of the variable to store the result of the check. This variable will be created as an internal cache variable.

  `LANGUAGE <language>`

    Added in version 3.11.

    If set, the specified `<language>` compiler will be used to perform the check. Acceptable values are `C` and `CXX`. If this option is not given, the C compiler will be used if enabled. If the C compiler is not enabled, the C++ compiler will be used if enabled.

  Variables Affecting the Check

  The following variables may be set before calling this command to modify the way the check is run:

  `CMAKE_REQUIRED_FLAGS`

    A space-separated string of additional flags to pass to the compiler. A semicolon-separated list will not work. The contents of `CMAKE_<LANG>_FLAGS` and its associated configuration-specific `CMAKE_<LANG>_FLAGS_<CONFIG>` variables are automatically prepended to the compiler command before the contents of this variable.

  `CMAKE_REQUIRED_DEFINITIONS`

    A semicolon-separated list of compiler definitions, each of the form `-DFOO` or `-DFOO=bar`. A definition for the name specified by the result variable argument of the check command is also added automatically.

  `CMAKE_REQUIRED_INCLUDES`

    A semicolon-separated list of header search paths to pass to the compiler. These will be the only header search paths used; the contents of the `INCLUDE_DIRECTORIES` directory property will be ignored.

  `CMAKE_REQUIRED_LINK_OPTIONS`

    Added in version 3.14.

    A semicolon-separated list of options to add to the link command (see `try_compile()` for further details).

  `CMAKE_REQUIRED_LIBRARIES`

    A semicolon-separated list of libraries to add to the link command. These can be the names of system libraries, or they can be Imported Targets (see `try_compile()` for further details).

  `CMAKE_REQUIRED_LINK_DIRECTORIES`

    Added in version 3.31.

    A semicolon-separated list of library search paths to pass to the linker (see `try_compile()` for further details).

  `CMAKE_REQUIRED_QUIET`

    Added in version 3.1.

    If this variable evaluates to a boolean true value, all status messages associated with the check will be suppressed.

  Added in version 3.12: The `CMAKE_REQUIRED_LIBRARIES` variable, if policy `CMP0075` is set to `NEW`.

## Examples

Checking one or more C headers and storing the check result in cache variables:

    include(CheckIncludeFiles)

    check_include_files(sys/socket.h HAVE_SYS_SOCKET_H)

    if(HAVE_SYS_SOCKET_H)
      # The <net/if.h> header on Darwin and BSD-like systems is not self-contained
      # and also requires <sys/socket.h>
      check_include_files("sys/socket.h;net/if.h" HAVE_NET_IF_H)
    else()
      check_include_files(net/if.h HAVE_NET_IF_H)
    endif()

The `LANGUAGE` option can be used to specify which compiler to use. For example, checking multiple `C++` headers, when both `C` and `CXX` languages are enabled in the project:

    include(CheckIncludeFiles)

    check_include_files("header_1.hpp;header_2.hpp" HAVE_HEADERS LANGUAGE CXX)

## See Also

- The `CheckIncludeFile` module to check for a single C header.

- The `CheckIncludeFileCXX` module to check for a single C++ header.