强制CMake使用C ++编译器的C文件与Visual Studio [英] Force CMake to use C++ compiler for C files with Visual Studio
问题描述
我生成了.h和.c文件,它们必须使用Visual Studio编译为C ++文件。
我听说可以做 set_source_files_properties($ {SOURCES} PROPERTIES LANGUAGECXX)
。同时,我已经阅读,我不应该这样做,因为它应该只在异国情况下使用。
因此,什么是强制CMake生成VS项目,将C文件编译为C ++文件?
PS:重命名生成的文件不是一个选项。
<我一直在使用各个属性(很可能你也可以设置目录属性 - 但是这不是细粒度的)没有任何问题。不是为了设置语言(但为什么应该有不同?):
SET_SOURCE_FILES_PROPERTIES(file1.c PROPERTIES LANGUAGE CXX)
这在Linux和Windows下工作,似乎没有任何问题。你听说过什么让你犹豫吗?
I have generated .h and .c files which must be compiled as C++ files with Visual Studio.
I heard I could do something like set_source_files_properties( ${SOURCES} PROPERTIES LANGUAGE "CXX" )
. In parallel, I have read that I should not do that as it should used only in exotic situations.
So, what is the best way to force CMake to generate VS projects which compiles C files as C++ files?
PS: renaming the generated files is not an option.
I have been using the individual properties (most likely you can also set directory properties - but this is not as fine grained) without any problems. Not for setting the language though (but why should it be any different?):
SET_SOURCE_FILES_PROPERTIES( file1.c PROPERTIES LANGUAGE CXX )
This works under Linux and Windows and doesn't seem to pose any problems. What have you heard that makes you hesitate?
这篇关于强制CMake使用C ++编译器的C文件与Visual Studio的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!