diff options
author | Brad King <brad.king@kitware.com> | 2020-06-29 12:25:34 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2020-06-29 12:25:42 (GMT) |
commit | f2b84d24cfccf49b6332cf3f2ca164fd71ae023e (patch) | |
tree | 67d3b6500279ec0a57498d534bc2be747ec84a41 /Source | |
parent | 3453d797a57591ec6e6f0ed8e9a03f6298d7cd18 (diff) | |
parent | 7d6861f367673b57bf45e14863f1104e8e28eafa (diff) | |
download | CMake-f2b84d24cfccf49b6332cf3f2ca164fd71ae023e.zip CMake-f2b84d24cfccf49b6332cf3f2ca164fd71ae023e.tar.gz CMake-f2b84d24cfccf49b6332cf3f2ca164fd71ae023e.tar.bz2 |
Merge topic 'fileApiAddLanguageStandardBacktrace'
7d6861f367 fileapi: Extend codemodel targets with language standard
ba835874a4 Add backtrace support for language standard
e43486a639 cmGeneratorTarget: Clarify name of language property lookup helper
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !4798
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmFileAPI.cxx | 2 | ||||
-rw-r--r-- | Source/cmFileAPICodemodel.cxx | 36 | ||||
-rw-r--r-- | Source/cmGeneratorTarget.cxx | 51 | ||||
-rw-r--r-- | Source/cmGeneratorTarget.h | 9 | ||||
-rw-r--r-- | Source/cmMakefile.cxx | 6 | ||||
-rw-r--r-- | Source/cmTarget.cxx | 69 | ||||
-rw-r--r-- | Source/cmTarget.h | 7 |
7 files changed, 156 insertions, 24 deletions
diff --git a/Source/cmFileAPI.cxx b/Source/cmFileAPI.cxx index 594969b..c2ab2f1 100644 --- a/Source/cmFileAPI.cxx +++ b/Source/cmFileAPI.cxx @@ -665,7 +665,7 @@ std::string cmFileAPI::NoSupportedVersion( // The "codemodel" object kind. -static unsigned int const CodeModelV2Minor = 1; +static unsigned int const CodeModelV2Minor = 2; void cmFileAPI::BuildClientRequestCodeModel( ClientRequest& r, std::vector<RequestVersion> const& versions) diff --git a/Source/cmFileAPICodemodel.cxx b/Source/cmFileAPICodemodel.cxx index fe331ec..21d9abb 100644 --- a/Source/cmFileAPICodemodel.cxx +++ b/Source/cmFileAPICodemodel.cxx @@ -277,6 +277,7 @@ struct CompileData std::string Language; std::string Sysroot; + JBT<std::string> LanguageStandard; std::vector<JBT<std::string>> Flags; std::vector<JBT<std::string>> Defines; std::vector<JBT<std::string>> PrecompileHeaders; @@ -287,6 +288,7 @@ struct CompileData return (l.Language == r.Language && l.Sysroot == r.Sysroot && l.Flags == r.Flags && l.Defines == r.Defines && l.PrecompileHeaders == r.PrecompileHeaders && + l.LanguageStandard == r.LanguageStandard && l.Includes == r.Includes); } }; @@ -320,6 +322,10 @@ struct hash<CompileData> result = result ^ hash<std::string>()(i.Value) ^ hash<Json::ArrayIndex>()(i.Backtrace.Index); } + if (!in.LanguageStandard.Value.empty()) { + result = result ^ hash<std::string>()(in.LanguageStandard.Value) ^ + hash<Json::ArrayIndex>()(in.LanguageStandard.Backtrace.Index); + } return result; } }; @@ -377,6 +383,7 @@ class Target Json::Value DumpCompileData(CompileData const& cd); Json::Value DumpInclude(CompileData::IncludeEntry const& inc); Json::Value DumpPrecompileHeader(JBT<std::string> const& header); + Json::Value DumpLanguageStandard(JBT<std::string> const& standard); Json::Value DumpDefine(JBT<std::string> const& def); Json::Value DumpSources(); Json::Value DumpSource(cmGeneratorTarget::SourceAndKind const& sk, @@ -838,6 +845,11 @@ void Target::ProcessLanguage(std::string const& lang) for (BT<std::string> const& pch : precompileHeaders) { cd.PrecompileHeaders.emplace_back(this->ToJBT(pch)); } + BT<std::string> const* languageStandard = + this->GT->GetLanguageStandardProperty(lang, this->Config); + if (languageStandard) { + cd.LanguageStandard = this->ToJBT(*languageStandard); + } } Json::ArrayIndex Target::AddSourceGroup(cmSourceGroup* sg, Json::ArrayIndex si) @@ -996,6 +1008,9 @@ CompileData Target::MergeCompileData(CompileData const& fd) // All compile groups share the precompile headers of the target. cd.PrecompileHeaders = td.PrecompileHeaders; + // All compile groups share the language standard of the target. + cd.LanguageStandard = td.LanguageStandard; + // Use target-wide flags followed by source-specific flags. cd.Flags.reserve(td.Flags.size() + fd.Flags.size()); cd.Flags.insert(cd.Flags.end(), td.Flags.begin(), td.Flags.end()); @@ -1153,6 +1168,10 @@ Json::Value Target::DumpCompileData(CompileData const& cd) } result["precompileHeaders"] = std::move(precompileHeaders); } + if (!cd.LanguageStandard.Value.empty()) { + result["languageStandard"] = + this->DumpLanguageStandard(cd.LanguageStandard); + } return result; } @@ -1176,6 +1195,23 @@ Json::Value Target::DumpPrecompileHeader(JBT<std::string> const& header) return precompileHeader; } +Json::Value Target::DumpLanguageStandard(JBT<std::string> const& standard) +{ + Json::Value languageStandard = Json::objectValue; + languageStandard["standard"] = standard.Value; + if (standard.Backtrace) { + // Only one backtrace is currently stored for a given language standard, + // but we represent this as an array because it's possible for multiple + // compile features to set the same language standard value. Representing + // this as an array will allow things to just work once we support storing + // multiple backtraces for a language standard value. + Json::Value backtraces = Json::arrayValue; + backtraces.append(standard.Backtrace.Index); + languageStandard["backtraces"] = backtraces; + } + return languageStandard; +} + Json::Value Target::DumpDefine(JBT<std::string> const& def) { Json::Value define = Json::objectValue; diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 1f66a9f..992682f 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -947,8 +947,8 @@ bool cmGeneratorTarget::HasExplicitObjectName(cmSourceFile const* file) const return it != this->ExplicitObjectName.end(); } -cmProp cmGeneratorTarget::GetLanguageStandard(std::string const& lang, - std::string const& config) const +BT<std::string> const* cmGeneratorTarget::GetLanguageStandardProperty( + std::string const& lang, std::string const& config) const { std::string key = cmStrCat(cmSystemTools::UpperCase(config), '-', lang); auto langStandardIter = this->LanguageStandardMap.find(key); @@ -956,19 +956,34 @@ cmProp cmGeneratorTarget::GetLanguageStandard(std::string const& lang, return &langStandardIter->second; } - return this->Target->GetProperty(cmStrCat(lang, "_STANDARD")); + return this->Target->GetLanguageStandardProperty( + cmStrCat(lang, "_STANDARD")); +} + +cmProp cmGeneratorTarget::GetLanguageStandard(std::string const& lang, + std::string const& config) const +{ + BT<std::string> const* languageStandard = + this->GetLanguageStandardProperty(lang, config); + + if (languageStandard) { + return &(languageStandard->Value); + } + + return nullptr; } -cmProp cmGeneratorTarget::GetLanguageStandardProperty(std::string const& lang, - const char* suffix) const +cmProp cmGeneratorTarget::GetPropertyWithPairedLanguageSupport( + 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); + propertyValue = this->GetPropertyWithPairedLanguageSupport("C", suffix); } else if (lang == "OBJCXX" || lang == "CUDA") { - propertyValue = this->GetLanguageStandardProperty("CXX", suffix); + propertyValue = + this->GetPropertyWithPairedLanguageSupport("CXX", suffix); } } return propertyValue; @@ -976,13 +991,14 @@ cmProp cmGeneratorTarget::GetLanguageStandardProperty(std::string const& lang, cmProp cmGeneratorTarget::GetLanguageExtensions(std::string const& lang) const { - return this->GetLanguageStandardProperty(lang, "_EXTENSIONS"); + return this->GetPropertyWithPairedLanguageSupport(lang, "_EXTENSIONS"); } bool cmGeneratorTarget::GetLanguageStandardRequired( std::string const& lang) const { - cmProp p = this->GetLanguageStandardProperty(lang, "_STANDARD_REQUIRED"); + cmProp p = + this->GetPropertyWithPairedLanguageSupport(lang, "_STANDARD_REQUIRED"); return p && cmIsOn(*p); } @@ -4467,7 +4483,8 @@ bool cmGeneratorTarget::ComputeCompileFeatures(std::string const& config) const } if (!newRequiredStandard.empty()) { - this->LanguageStandardMap[key] = newRequiredStandard; + this->LanguageStandardMap[key] = + BT<std::string>(newRequiredStandard, f.Backtrace); } } @@ -4478,15 +4495,15 @@ 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); + BT<std::string> const* generatorTargetLanguageStandard = + this->GetLanguageStandardProperty(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); + BT<std::string> const* standardToCopy = + this->GetLanguageStandardProperty(language.second, config); if (standardToCopy != nullptr) { this->LanguageStandardMap[key] = *standardToCopy; generatorTargetLanguageStandard = &this->LanguageStandardMap[key]; @@ -4494,7 +4511,7 @@ bool cmGeneratorTarget::ComputeCompileFeatures( cmProp defaultStandard = this->Makefile->GetDef( cmStrCat("CMAKE_", language.second, "_STANDARD_DEFAULT")); if (defaultStandard != nullptr) { - this->LanguageStandardMap[key] = *defaultStandard; + this->LanguageStandardMap[key] = BT<std::string>(*defaultStandard); generatorTargetLanguageStandard = &this->LanguageStandardMap[key]; } } @@ -4502,8 +4519,8 @@ bool cmGeneratorTarget::ComputeCompileFeatures( // Custom updates for the CUDA standard. if (generatorTargetLanguageStandard != nullptr && language.first == "CUDA") { - if (*generatorTargetLanguageStandard == "98") { - this->LanguageStandardMap[key] = "03"; + if (generatorTargetLanguageStandard->Value == "98") { + this->LanguageStandardMap[key].Value = "03"; } } } diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h index a71e64c..20f3a07 100644 --- a/Source/cmGeneratorTarget.h +++ b/Source/cmGeneratorTarget.h @@ -148,6 +148,9 @@ public: bool HasExplicitObjectName(cmSourceFile const* file) const; void AddExplicitObjectName(cmSourceFile const* sf); + BT<std::string> const* GetLanguageStandardProperty( + std::string const& lang, std::string const& config) const; + cmProp GetLanguageStandard(std::string const& lang, std::string const& config) const; @@ -1050,10 +1053,10 @@ private: bool GetRPATH(const std::string& config, const std::string& prop, std::string& rpath) const; - mutable std::map<std::string, std::string> LanguageStandardMap; + mutable std::map<std::string, BT<std::string>> LanguageStandardMap; - cmProp GetLanguageStandardProperty(std::string const& lang, - const char* suffix) const; + cmProp GetPropertyWithPairedLanguageSupport(std::string const& lang, + const char* suffix) const; public: const std::vector<const cmGeneratorTarget*>& GetLinkImplementationClosure( diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 891e290..d34259f 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -5072,7 +5072,7 @@ bool cmMakefile::AddRequiredTargetCxxFeature(cmTarget* target, target->GetProperty(cmStrCat(lang, "_STANDARD")), newRequiredStandard, error)) { if (!newRequiredStandard.empty()) { - target->SetProperty(cmStrCat(lang, "_STANDARD"), newRequiredStandard); + target->SetLanguageStandardProperty(lang, newRequiredStandard, feature); } return true; } @@ -5253,7 +5253,7 @@ bool cmMakefile::AddRequiredTargetCudaFeature(cmTarget* target, target->GetProperty(cmStrCat(lang, "_STANDARD")), newRequiredStandard, error)) { if (!newRequiredStandard.empty()) { - target->SetProperty(cmStrCat(lang, "_STANDARD"), newRequiredStandard); + target->SetLanguageStandardProperty(lang, newRequiredStandard, feature); } return true; } @@ -5358,7 +5358,7 @@ bool cmMakefile::AddRequiredTargetCFeature(cmTarget* target, target->GetProperty(cmStrCat(lang, "_STANDARD")), newRequiredStandard, error)) { if (!newRequiredStandard.empty()) { - target->SetProperty(cmStrCat(lang, "_STANDARD"), newRequiredStandard); + target->SetLanguageStandardProperty(lang, newRequiredStandard, feature); } return true; } diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 4091b06..9f9b6f9 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -7,6 +7,7 @@ #include <cstring> #include <initializer_list> #include <iterator> +#include <map> #include <set> #include <sstream> #include <unordered_set> @@ -185,6 +186,7 @@ public: std::vector<cmInstallTargetGenerator*> InstallGenerators; std::set<std::string> SystemIncludeDirectories; cmTarget::LinkLibraryVectorType OriginalLinkLibraries; + std::map<std::string, BT<std::string>> LanguageStandardProperties; std::vector<std::string> IncludeDirectoriesEntries; std::vector<cmListFileBacktrace> IncludeDirectoriesBacktraces; std::vector<std::string> CompileOptionsEntries; @@ -598,6 +600,35 @@ cmGlobalGenerator* cmTarget::GetGlobalGenerator() const return impl->Makefile->GetGlobalGenerator(); } +BT<std::string> const* cmTarget::GetLanguageStandardProperty( + const std::string& propertyName) const +{ + auto entry = impl->LanguageStandardProperties.find(propertyName); + if (entry != impl->LanguageStandardProperties.end()) { + return &entry->second; + } + + return nullptr; +} + +void cmTarget::SetLanguageStandardProperty(std::string const& lang, + std::string const& value, + const std::string& feature) +{ + cmListFileBacktrace featureBacktrace; + for (size_t i = 0; i < impl->CompileFeaturesEntries.size(); i++) { + if (impl->CompileFeaturesEntries[i] == feature) { + if (i < impl->CompileFeaturesBacktraces.size()) { + featureBacktrace = impl->CompileFeaturesBacktraces[i]; + } + break; + } + } + + impl->LanguageStandardProperties[cmStrCat(lang, "_STANDARD")] = + BT<std::string>(value, featureBacktrace); +} + void cmTarget::AddUtility(std::string const& name, bool cross, cmMakefile* mf) { impl->Utilities.insert(BT<std::pair<std::string, bool>>( @@ -1133,6 +1164,11 @@ void cmTarget::SetProperty(const std::string& prop, const char* value) return; } #define MAKE_STATIC_PROP(PROP) static const std::string prop##PROP = #PROP + MAKE_STATIC_PROP(C_STANDARD); + MAKE_STATIC_PROP(CXX_STANDARD); + MAKE_STATIC_PROP(CUDA_STANDARD); + MAKE_STATIC_PROP(OBJC_STANDARD); + MAKE_STATIC_PROP(OBJCXX_STANDARD); MAKE_STATIC_PROP(COMPILE_DEFINITIONS); MAKE_STATIC_PROP(COMPILE_FEATURES); MAKE_STATIC_PROP(COMPILE_OPTIONS); @@ -1316,6 +1352,15 @@ void cmTarget::SetProperty(const std::string& prop, const char* value) cmProp tmp = reusedTarget->GetProperty("COMPILE_PDB_NAME"); this->SetProperty("COMPILE_PDB_NAME", tmp ? tmp->c_str() : nullptr); this->AddUtility(reusedFrom, false, impl->Makefile); + } else if (prop == propC_STANDARD || prop == propCXX_STANDARD || + prop == propCUDA_STANDARD || prop == propOBJC_STANDARD || + prop == propOBJCXX_STANDARD) { + if (value) { + impl->LanguageStandardProperties[prop] = + BT<std::string>(value, impl->Makefile->GetBacktrace()); + } else { + impl->LanguageStandardProperties.erase(prop); + } } else { impl->Properties.SetProperty(prop, value); } @@ -1419,6 +1464,11 @@ void cmTarget::AppendProperty(const std::string& prop, } else if (cmHasLiteralPrefix(prop, "IMPORTED_LIBNAME")) { impl->Makefile->IssueMessage(MessageType::FATAL_ERROR, prop + " property may not be APPENDed."); + } else if (prop == "C_STANDARD" || prop == "CXX_STANDARD" || + prop == "CUDA_STANDARD" || prop == "OBJC_STANDARD" || + prop == "OBJCXX_STANDARD") { + impl->Makefile->IssueMessage(MessageType::FATAL_ERROR, + prop + " property may not be appended."); } else { impl->Properties.AppendProperty(prop, value, asString); } @@ -1632,6 +1682,11 @@ cmProp cmTarget::GetComputedProperty(const std::string& prop, cmProp cmTarget::GetProperty(const std::string& prop) const { #define MAKE_STATIC_PROP(PROP) static const std::string prop##PROP = #PROP + MAKE_STATIC_PROP(C_STANDARD); + MAKE_STATIC_PROP(CXX_STANDARD); + MAKE_STATIC_PROP(CUDA_STANDARD); + MAKE_STATIC_PROP(OBJC_STANDARD); + MAKE_STATIC_PROP(OBJCXX_STANDARD); MAKE_STATIC_PROP(LINK_LIBRARIES); MAKE_STATIC_PROP(TYPE); MAKE_STATIC_PROP(INCLUDE_DIRECTORIES); @@ -1652,6 +1707,11 @@ cmProp cmTarget::GetProperty(const std::string& prop) const MAKE_STATIC_PROP(TRUE); #undef MAKE_STATIC_PROP static std::unordered_set<std::string> const specialProps{ + propC_STANDARD, + propCXX_STANDARD, + propCUDA_STANDARD, + propOBJC_STANDARD, + propOBJCXX_STANDARD, propLINK_LIBRARIES, propTYPE, propINCLUDE_DIRECTORIES, @@ -1670,6 +1730,15 @@ cmProp cmTarget::GetProperty(const std::string& prop) const propSOURCES }; if (specialProps.count(prop)) { + if (prop == propC_STANDARD || prop == propCXX_STANDARD || + prop == propCUDA_STANDARD || prop == propOBJC_STANDARD || + prop == propOBJCXX_STANDARD) { + auto propertyIter = impl->LanguageStandardProperties.find(prop); + if (propertyIter == impl->LanguageStandardProperties.end()) { + return nullptr; + } + return &(propertyIter->second.Value); + } if (prop == propLINK_LIBRARIES) { if (impl->LinkImplementationPropertyEntries.empty()) { return nullptr; diff --git a/Source/cmTarget.h b/Source/cmTarget.h index e7498bd..b3d6fe0 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -236,6 +236,13 @@ public: void AddSystemIncludeDirectories(std::set<std::string> const& incs); std::set<std::string> const& GetSystemIncludeDirectories() const; + BT<std::string> const* GetLanguageStandardProperty( + const std::string& propertyName) const; + + void SetLanguageStandardProperty(std::string const& lang, + std::string const& value, + const std::string& feature); + cmStringRange GetIncludeDirectoriesEntries() const; cmBacktraceRange GetIncludeDirectoriesBacktraces() const; |