Hi,
I am in the process of porting my project from sln to cmake and I have a situation where I need to compile 2 specific .c files as cpp. I used set_source_files_properties on these 2 files like so:
set_source_files_properties(
${CMAKE_CURRENT_SOURCE_DIR}/abc/x.c
${CMAKE_CURRENT_SOURCE_DIR}/abc/y.c
PROPERTIES COMPILE_OPTIONS /Tp)
This generates the following compile line
.......truncated.....
/external:W3 /Gd /TC /analyze- /errorReport:queue /Tp C:\code\abc\x.c C:\code\abc\y.c
x.c
Generating Code...
Compiling...
y.c
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.38.33130\include\yvals_core.h(27): STL1003: Unexpected comp
iler, expected C++ compiler.
Generating Code...
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.38.33130\include\yvals_core.h(28,1): error C1189: #error: Error in C++ Standard Library usage
(compiling source file '../../Ccode/abc/y.c')
As you can see the compilation fails, apparently because the /Tp applies to only the first x.c… I manually pasted the command line by introducing an explicit /Tp before y.c as well and it compiles fine then. The original vcxproj (generated by vs) was using CompileAs stanza under the clcompile task for these 2 files individually as opposed to the AdditionalOptions used by cmake generator… Any thoughts on how I could make this work with cmake ? thank you
Neelabh
additional info:
- cmake version 3.28.0-rc5
- having 2 seperate set_source_files_properties one each on x.c and y.c with /Tp also doesn’t help. the result is the same