Unity Builds do not set language properly on individual files in Visual Studio
I have this in a cmake file:
set(CMAKE_UNITY_BUILD ON)
SET(CPP_LIBSRCS aelexpr.c
genfunvoc.cxx
misc.cxx complex.cxx
leafinterface.cxx
functions1.cxx
aelhpvar_utils.cxx ...
SET_SOURCE_FILES_PROPERTIES(${CPP_LIBSRCS} PROPERTIES LANGUAGE CXX)
add_library(mylib ${CPP_LIBSRCS})
In the Visual Studio 2019 project, aelexpr.c is NOT marked as c++ (Right-click, Properties, C/C++, Advanced, Compile As). This has the following consequences:
- Syntax highlighting and IntelliSense fail on this file because it is thought to be C.
- Compiling the individual file aelexpr.c fails as it attempts to compile in C.
This is a huge problem for us as we've switched to unity builds for a very large solution (1,200 projects, 4,600 files with .c extension compiling as C++).
Edited by Rob Lefebvre