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>_COMPILERIf 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_COMPILERThis variable is set when
<lang>isCUDAorHIP.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>_COMPILERis also set. Otherwise, the check runs and overwritesCMAKE_<LANG>_HOST_COMPILERwith a new result. Note thatCMAKE_<LANG>_HOST_COMPILERdocuments it should not be set without also settingCMAKE_<LANG>_COMPILERto a NVCC compiler.CMAKE_<LANG>_PLATFORMThis variable is set to the detected GPU platform when
<lang>isHIP.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()