简体   繁体   中英

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. 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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM