Genex: Enable COMPILE_LANGUAGE for COMPILE_OPTIONS and file(GENERATE) with Visual Studio
Since !996 (merged) the evaluation of COMPILE_LANGUAGE
receives the proper
language. The set of compile flags used for a target's C and C++
sources is based on the linker language. By default this is always the
C++ flags if any C++ sources appear in the target, and otherwise the C
flags. Therefore we can define the COMPILE_LANGUAGE
generator
expression in COMPILE_OPTIONS
to match the selected language.
This is not exactly the same as for other generators, but is the best VS
can do. It is also sufficient for many use cases since the set of
allowed flags for C and C++ is almost the same in Visual Studio.
Furthermore, since the VS generator moves many of the flags to
declarative .vcxproj
elements, it will automatically avoid passing
C++ flags for C sources.
Also enable COMPILE_LANGUAGE
for file(GENERATE)
. It requires no
special new support and simply needs to have the rejection dropped.
Issue: #17435 (closed)