CheckLanguage — CMake 4.0.3-dirty Documentation

# CheckLanguage

Check whether a language can be enabled by the `enable_language()` or `project()` commands:

check_language

      check_language(<lang>)

  Try enabling language `<lang>` in a test project and record results in the cache:

  `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 the variable is already set its value is always preserved. Only compatible values will be considered for `CMAKE_<LANG>_COMPILER`.

For example:

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