mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-20 21:40:15 +08:00
VS: Simplify logic adding source file C/C++ language flag to MSVC
Do not add a target-wide language flag. We need a flag on an individual source file to explicitly specify the C or C++ language if and only if the source file extension does not imply it.
This commit is contained in:
@@ -2318,21 +2318,13 @@ void cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags(
|
|||||||
cmGeneratorExpression::Find(*cincludes) != std::string::npos;
|
cmGeneratorExpression::Find(*cincludes) != std::string::npos;
|
||||||
includes += *cincludes;
|
includes += *cincludes;
|
||||||
}
|
}
|
||||||
std::string lang =
|
|
||||||
this->GlobalGenerator->GetLanguageFromExtension(sf.GetExtension().c_str());
|
// Force language if the file extension does not match.
|
||||||
std::string sourceLang = this->LocalGenerator->GetSourceFileLanguage(sf);
|
std::string lang = this->LocalGenerator->GetSourceFileLanguage(sf);
|
||||||
const std::string& linkLanguage =
|
|
||||||
this->GeneratorTarget->GetLinkerLanguage("");
|
|
||||||
bool needForceLang = false;
|
|
||||||
// source file does not match its extension language
|
|
||||||
if (lang != sourceLang) {
|
|
||||||
needForceLang = true;
|
|
||||||
lang = sourceLang;
|
|
||||||
}
|
|
||||||
// if the source file does not match the linker language
|
|
||||||
// then force c or c++
|
|
||||||
const char* compileAs = 0;
|
const char* compileAs = 0;
|
||||||
if (needForceLang || (linkLanguage != lang)) {
|
if (lang !=
|
||||||
|
this->GlobalGenerator->GetLanguageFromExtension(
|
||||||
|
sf.GetExtension().c_str())) {
|
||||||
if (lang == "CXX") {
|
if (lang == "CXX") {
|
||||||
// force a C++ file type
|
// force a C++ file type
|
||||||
compileAs = "CompileAsCpp";
|
compileAs = "CompileAsCpp";
|
||||||
@@ -2341,6 +2333,7 @@ void cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags(
|
|||||||
compileAs = "CompileAsC";
|
compileAs = "CompileAsC";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool noWinRT = this->TargetCompileAsWinRT && lang == "C";
|
bool noWinRT = this->TargetCompileAsWinRT && lang == "C";
|
||||||
// for the first time we need a new line if there is something
|
// for the first time we need a new line if there is something
|
||||||
// produced here.
|
// produced here.
|
||||||
@@ -2737,13 +2730,6 @@ bool cmVisualStudio10TargetGenerator::ComputeClOptions(
|
|||||||
this->LocalGenerator->AddCompileOptions(flags, this->GeneratorTarget,
|
this->LocalGenerator->AddCompileOptions(flags, this->GeneratorTarget,
|
||||||
langForClCompile, configName);
|
langForClCompile, configName);
|
||||||
}
|
}
|
||||||
// set the correct language
|
|
||||||
if (linkLanguage == "C") {
|
|
||||||
clOptions.AddFlag("CompileAs", "CompileAsC");
|
|
||||||
}
|
|
||||||
if (linkLanguage == "CXX") {
|
|
||||||
clOptions.AddFlag("CompileAs", "CompileAsCpp");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Put the IPO enabled configurations into a set.
|
// Put the IPO enabled configurations into a set.
|
||||||
if (this->GeneratorTarget->IsIPOEnabled(linkLanguage, configName)) {
|
if (this->GeneratorTarget->IsIPOEnabled(linkLanguage, configName)) {
|
||||||
|
Reference in New Issue
Block a user