enable_language

Enable languages (CXX/C/OBJC/OBJCXX/Fortran/etc)

enable_language(<lang>... [OPTIONAL])

Enables support for the named languages in CMake. This is the same as the project() command but does not create any of the extra variables that are created by the project() command.

The supported languages are:

C

CXX

C++

CSharp

在 3.8 版被加入.

C#

CUDA

在 3.8 版被加入.

OBJC

在 3.16 版被加入.

Objective-C

OBJCXX

在 3.16 版被加入.

Objective-C++

Fortran

HIP

在 3.21 版被加入.

ISPC

在 3.18 版被加入.

Swift

在 3.15 版被加入.

ASM

Assembly language supported by the C compiler.

If enabling ASM, list it last so that CMake can check whether the C or CXX compiler supports assembly.

ASM_NASM

Netwide Assembler

ASM_MARMASM

在 3.26 版被加入.

Microsoft Assembler (ARM, ARM64)

ASM_MASM

Microsoft Assembler (x86, x64)

ASM_POASM

在 4.4 版被加入.

Pelles C toolchain assembler.

ASM-ATT

AT&T-syntax assembler (e.g. GNU as)

以下限制適用於呼叫 enable_language() 的位置:

  • It must not be called before the first call to project(). See policy CMP0165.

  • It must be called such that the command executes before any targets that use the language directly for compiling sources or indirectly through link dependencies.

備註

Further restrictions apply if policy CMP0220 is not set to NEW. See the policy documentation for details.

The OPTIONAL keyword is a placeholder for future implementation and does not currently work. Instead you can use the CheckLanguage module to verify support before enabling.