我如何 "override" CMake 中文件的扩展类型

How do I "override" the by-extension type of a file in CMake

CMake 似乎会根据文件的扩展名对文件做出假设——具体来说,用什么来编译源文件。虽然这有时可以使用编译器标志手动覆盖(例如 -x C++ 用于 .c 文件),但这取决于特定的编译器并且似乎可以规避问题。

有没有办法告诉 CMake "treat a file with extension .ext1 as though it had extension .ext2"?我似乎无法在 CMake 文档中找到类似的内容。

您可以使用 LANGUAGE 设置文件 `set_source_files_properties'

LANGUAGE

What programming language is the file.

A property that can be set to indicate what programming language the source file is. If it is not set the language is determined based on the file extension. Typical values are CXX (i.e. C++), C, CSharp, CUDA, Fortran, and ASM. Setting this property for a file means this file will be compiled. Do not set this for headers or files that should not be compiled.