CheckLanguage — CMake 4.1.4 Documentation

# CheckLanguage

This module provides a command to check whether a language can be enabled using the `enable_language()` or `project()` commands.

Load this module in a CMake project with:

    include(CheckLanguage)

This module is useful when a project does not always require a specific language but may need to enable it for certain parts.

## Commands

This module provides the following command:

check_language

  Checks whether a language can be enabled in a CMake project:

      check_language(<lang>)

  This command attempts to enable the language `<lang>` in a test project and records the results in the following cache variables:

  `CMAKE_<LANG>_COMPILER`

    If the language can be enabled, this variable is set to the compiler that was found. If the language cannot be enabled, this variable is set to `NOTFOUND`.

    If this variable is already set, either explicitly or cached by a previous call, the check is skipped.

  `CMAKE_<LANG>_HOST_COMPILER`

    This variable is set when `<lang>` is `CUDA` or `HIP`.

    If the check detects an explicit host compiler that is required for compilation, this variable will be set to that compiler. If the check detects that no explicit host compiler is needed, this variable will be cleared.

    If this variable is already set, its value is preserved only if `CMAKE_<LANG>_COMPILER` is also set. Otherwise, the check runs and overwrites `CMAKE_<LANG>_HOST_COMPILER` with a new result. Note that `CMAKE_<LANG>_HOST_COMPILER` documents it should not be set without also setting `CMAKE_<LANG>_COMPILER` to a NVCC compiler.

  `CMAKE_<LANG>_PLATFORM`

    This variable is set to the detected GPU platform when `<lang>` is `HIP`.

    If this variable is already set, its value is always preserved. Only compatible values will be considered for `CMAKE_<LANG>_COMPILER`.

## Examples

The following example checks for the availability of the `Fortran` language and enables it if possible:

    include(CheckLanguage)
    check_language(Fortran)
    if(CMAKE_Fortran_COMPILER)
      enable_language(Fortran)
    else()
      message(STATUS "No Fortran support")
    endif()