Genex: Enable COMPILE_LANGUAGE for COMPILE_DEFINITIONS with VS and Xcode

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_DEFINITIONS` to match the selected language.

This is not exactly the same as for other generators, but is the best VS
and Xcode can do.  It is also sufficient for many use cases since the
set of definitions for C and C++ is frequently similar but may be
distinct from those for other languages like CUDA.

Issue: #17435
This commit is contained in:
Brad King
2018-01-11 11:23:06 -05:00
parent 0795d25b78
commit c2f79c9867
24 changed files with 107 additions and 115 deletions

View File

@@ -705,7 +705,9 @@ void cmLocalVisualStudio7Generator::WriteConfiguration(
targetOptions.Parse(defineFlags.c_str());
targetOptions.ParseFinish();
std::vector<std::string> targetDefines;
target->GetCompileDefinitions(targetDefines, configName, "CXX");
if (!langForClCompile.empty()) {
target->GetCompileDefinitions(targetDefines, configName, langForClCompile);
}
targetOptions.AddDefines(targetDefines);
targetOptions.SetVerboseMakefile(
this->Makefile->IsOn("CMAKE_VERBOSE_MAKEFILE"));
@@ -812,7 +814,8 @@ void cmLocalVisualStudio7Generator::WriteConfiguration(
}
fout << "\"\n";
targetOptions.OutputFlagMap(fout, "\t\t\t\t");
targetOptions.OutputPreprocessorDefinitions(fout, "\t\t\t\t", "\n", "CXX");
targetOptions.OutputPreprocessorDefinitions(fout, "\t\t\t\t", "\n",
langForClCompile);
fout << "\t\t\t\tObjectFile=\"$(IntDir)\\\"\n";
if (target->GetType() <= cmStateEnums::OBJECT_LIBRARY) {
// Specify the compiler program database file if configured.