summaryrefslogtreecommitdiffstats
path: root/Source/cmGeneratorTarget.cxx
diff options
context:
space:
mode:
authorJustin Goshi <jgoshi@microsoft.com>2020-06-11 20:06:02 (GMT)
committerJustin Goshi <jgoshi@microsoft.com>2020-06-16 23:32:34 (GMT)
commit742ff97f809410055b22405a6b5728e72c458683 (patch)
tree3587f801e2f0801ea42b45ba3a7bdc0624cf6d5c /Source/cmGeneratorTarget.cxx
parent0892c798f795c6072ce882552384187db86797f0 (diff)
downloadCMake-742ff97f809410055b22405a6b5728e72c458683.zip
CMake-742ff97f809410055b22405a6b5728e72c458683.tar.gz
CMake-742ff97f809410055b22405a6b5728e72c458683.tar.bz2
Refactor language standard computation
Instead of mutating the configure-time cmTarget's properties at generate time, compute and store it in a cmGeneratorTarget field.
Diffstat (limited to 'Source/cmGeneratorTarget.cxx')
-rw-r--r--Source/cmGeneratorTarget.cxx97
1 files changed, 96 insertions, 1 deletions
diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx
index f2011ee..1f66a9f 100644
--- a/Source/cmGeneratorTarget.cxx
+++ b/Source/cmGeneratorTarget.cxx
@@ -947,6 +947,45 @@ bool cmGeneratorTarget::HasExplicitObjectName(cmSourceFile const* file) const
return it != this->ExplicitObjectName.end();
}
+cmProp cmGeneratorTarget::GetLanguageStandard(std::string const& lang,
+ std::string const& config) const
+{
+ std::string key = cmStrCat(cmSystemTools::UpperCase(config), '-', lang);
+ auto langStandardIter = this->LanguageStandardMap.find(key);
+ if (langStandardIter != this->LanguageStandardMap.end()) {
+ return &langStandardIter->second;
+ }
+
+ return this->Target->GetProperty(cmStrCat(lang, "_STANDARD"));
+}
+
+cmProp cmGeneratorTarget::GetLanguageStandardProperty(std::string const& lang,
+ const char* suffix) const
+{
+ cmProp propertyValue = this->Target->GetProperty(cmStrCat(lang, suffix));
+ if (propertyValue == nullptr) {
+ // Check if we should use the value set by another language.
+ if (lang == "OBJC") {
+ propertyValue = this->GetLanguageStandardProperty("C", suffix);
+ } else if (lang == "OBJCXX" || lang == "CUDA") {
+ propertyValue = this->GetLanguageStandardProperty("CXX", suffix);
+ }
+ }
+ return propertyValue;
+}
+
+cmProp cmGeneratorTarget::GetLanguageExtensions(std::string const& lang) const
+{
+ return this->GetLanguageStandardProperty(lang, "_EXTENSIONS");
+}
+
+bool cmGeneratorTarget::GetLanguageStandardRequired(
+ std::string const& lang) const
+{
+ cmProp p = this->GetLanguageStandardProperty(lang, "_STANDARD_REQUIRED");
+ return p && cmIsOn(*p);
+}
+
void cmGeneratorTarget::GetModuleDefinitionSources(
std::vector<cmSourceFile const*>& data, const std::string& config) const
{
@@ -4408,12 +4447,68 @@ void cmGeneratorTarget::ComputeTargetManifest(const std::string& config) const
bool cmGeneratorTarget::ComputeCompileFeatures(std::string const& config) const
{
+ // Compute the language standard based on the compile features.
std::vector<BT<std::string>> features = this->GetCompileFeatures(config);
for (BT<std::string> const& f : features) {
- if (!this->Makefile->AddRequiredTargetFeature(this->Target, f.Value)) {
+ std::string lang;
+ if (!this->Makefile->CompileFeatureKnown(this->Target->GetName(), f.Value,
+ lang, nullptr)) {
return false;
}
+
+ std::string key = cmStrCat(cmSystemTools::UpperCase(config), '-', lang);
+ cmProp currentLanguageStandard = this->GetLanguageStandard(lang, config);
+
+ std::string newRequiredStandard;
+ if (!this->Makefile->GetNewRequiredStandard(
+ this->Target->GetName(), f.Value, currentLanguageStandard,
+ newRequiredStandard)) {
+ return false;
+ }
+
+ if (!newRequiredStandard.empty()) {
+ this->LanguageStandardMap[key] = newRequiredStandard;
+ }
}
+
+ return true;
+}
+
+bool cmGeneratorTarget::ComputeCompileFeatures(
+ std::string const& config, std::set<LanguagePair> const& languagePairs) const
+{
+ for (const auto& language : languagePairs) {
+ cmProp generatorTargetLanguageStandard =
+ this->GetLanguageStandard(language.first, config);
+ if (!generatorTargetLanguageStandard) {
+ // If the standard isn't explicitly set we copy it over from the
+ // specified paired language.
+ std::string key =
+ cmStrCat(cmSystemTools::UpperCase(config), '-', language.first);
+ cmProp standardToCopy =
+ this->GetLanguageStandard(language.second, config);
+ if (standardToCopy != nullptr) {
+ this->LanguageStandardMap[key] = *standardToCopy;
+ generatorTargetLanguageStandard = &this->LanguageStandardMap[key];
+ } else {
+ cmProp defaultStandard = this->Makefile->GetDef(
+ cmStrCat("CMAKE_", language.second, "_STANDARD_DEFAULT"));
+ if (defaultStandard != nullptr) {
+ this->LanguageStandardMap[key] = *defaultStandard;
+ generatorTargetLanguageStandard = &this->LanguageStandardMap[key];
+ }
+ }
+
+ // Custom updates for the CUDA standard.
+ if (generatorTargetLanguageStandard != nullptr &&
+ language.first == "CUDA") {
+ if (*generatorTargetLanguageStandard == "98") {
+ this->LanguageStandardMap[key] = "03";
+ }
+ }
+ }
+ }
+
return true;
}