[英]Force CMake to use C++ compiler for C files with Visual Studio
I have generated .h and .c files which must be compiled as C++ files with Visual Studio. 我已生成.h和.c文件,必须使用Visual Studio编译为C ++文件。 I heard I could do something like
set_source_files_properties( ${SOURCES} PROPERTIES LANGUAGE "CXX" )
. 我听说我可以做类似
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? 那么,强制CMake生成将C文件编译为C ++文件的VS项目的最佳方法是什么?
PS: renaming the generated files is not an option. PS:重命名生成的文件不是一个选项。
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. 这适用于Linux和Windows,似乎没有任何问题。 What have you heard that makes you hesitate?
你听到了什么让你犹豫不决?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.