diff options
author | Brad King <brad.king@kitware.com> | 2019-09-27 18:38:02 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2019-09-27 18:38:30 (GMT) |
commit | d608b2c6200afd9d732c30c862bda923139a8d08 (patch) | |
tree | a00f6941f3068d172b571dca91f425e9210de830 /Source | |
parent | 8c568722d79f9de0c03550981cbcb9453733a8bb (diff) | |
parent | 8b84c046faa9d6e52b99855a955bd7b6f48e9a8b (diff) | |
download | CMake-d608b2c6200afd9d732c30c862bda923139a8d08.zip CMake-d608b2c6200afd9d732c30c862bda923139a8d08.tar.gz CMake-d608b2c6200afd9d732c30c862bda923139a8d08.tar.bz2 |
Merge topic 'fileapiSourcePropertyBacktraces'
8b84c046fa fileapi: add some source property backtraces
c71ac889ba cmSourceFile: Add backtraces for a few source properties
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !3861
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmFileAPICodemodel.cxx | 66 | ||||
-rw-r--r-- | Source/cmSourceFile.cxx | 78 | ||||
-rw-r--r-- | Source/cmSourceFile.h | 22 |
3 files changed, 142 insertions, 24 deletions
diff --git a/Source/cmFileAPICodemodel.cxx b/Source/cmFileAPICodemodel.cxx index 96ea071..fbdb975 100644 --- a/Source/cmFileAPICodemodel.cxx +++ b/Source/cmFileAPICodemodel.cxx @@ -858,47 +858,69 @@ CompileData Target::BuildCompileData(cmSourceFile* sf) fd.Flags.emplace_back(std::move(flags), JBTIndex()); } const std::string COMPILE_OPTIONS("COMPILE_OPTIONS"); - if (const char* coptions = sf->GetProperty(COMPILE_OPTIONS)) { - std::string flags; - lg->AppendCompileOptions( - flags, genexInterpreter.Evaluate(coptions, COMPILE_OPTIONS)); - fd.Flags.emplace_back(std::move(flags), JBTIndex()); + for (BT<std::string> tmpOpt : sf->GetCompileOptions()) { + tmpOpt.Value = genexInterpreter.Evaluate(tmpOpt.Value, COMPILE_OPTIONS); + // After generator evaluation we need to use the AppendCompileOptions + // method so we handle situations where backtrace entries have lists + // and properly escape flags. + std::string tmp; + lg->AppendCompileOptions(tmp, tmpOpt.Value); + BT<std::string> opt(tmp, tmpOpt.Backtrace); + fd.Flags.emplace_back(this->ToJBT(opt)); } // Add include directories from source file properties. { - std::vector<std::string> includes; const std::string INCLUDE_DIRECTORIES("INCLUDE_DIRECTORIES"); - if (const char* cincludes = sf->GetProperty(INCLUDE_DIRECTORIES)) { - const std::string& evaluatedIncludes = - genexInterpreter.Evaluate(cincludes, INCLUDE_DIRECTORIES); - lg->AppendIncludeDirectories(includes, evaluatedIncludes, *sf); - - for (std::string const& include : includes) { - bool const isSystemInclude = this->GT->IsSystemIncludeDirectory( - include, this->Config, fd.Language); - fd.Includes.emplace_back(include, isSystemInclude); + for (BT<std::string> tmpInclude : sf->GetIncludeDirectories()) { + tmpInclude.Value = + genexInterpreter.Evaluate(tmpInclude.Value, INCLUDE_DIRECTORIES); + + // After generator evaluation we need to use the AppendIncludeDirectories + // method so we handle situations where backtrace entries have lists. + std::vector<std::string> tmp; + lg->AppendIncludeDirectories(tmp, tmpInclude.Value, *sf); + for (std::string& i : tmp) { + bool const isSystemInclude = + this->GT->IsSystemIncludeDirectory(i, this->Config, fd.Language); + BT<std::string> include(i, tmpInclude.Backtrace); + fd.Includes.emplace_back(this->ToJBT(include), isSystemInclude); } } } const std::string COMPILE_DEFINITIONS("COMPILE_DEFINITIONS"); - std::set<std::string> fileDefines; - if (const char* defs = sf->GetProperty(COMPILE_DEFINITIONS)) { - lg->AppendDefines(fileDefines, - genexInterpreter.Evaluate(defs, COMPILE_DEFINITIONS)); + std::set<BT<std::string>> fileDefines; + for (BT<std::string> tmpDef : sf->GetCompileDefinitions()) { + tmpDef.Value = + genexInterpreter.Evaluate(tmpDef.Value, COMPILE_DEFINITIONS); + + // After generator evaluation we need to use the AppendDefines method + // so we handle situations where backtrace entries have lists. + std::set<std::string> tmp; + lg->AppendDefines(tmp, tmpDef.Value); + for (const std::string& i : tmp) { + BT<std::string> def(i, tmpDef.Backtrace); + fileDefines.insert(def); + } } + std::set<std::string> configFileDefines; const std::string defPropName = "COMPILE_DEFINITIONS_" + cmSystemTools::UpperCase(this->Config); if (const char* config_defs = sf->GetProperty(defPropName)) { lg->AppendDefines( - fileDefines, + configFileDefines, genexInterpreter.Evaluate(config_defs, COMPILE_DEFINITIONS)); } - fd.Defines.reserve(fileDefines.size()); - for (std::string const& d : fileDefines) { + fd.Defines.reserve(fileDefines.size() + configFileDefines.size()); + + for (BT<std::string> const& def : fileDefines) { + fd.Defines.emplace_back(this->ToJBT(def)); + } + + for (std::string const& d : configFileDefines) { fd.Defines.emplace_back(d, JBTIndex()); } diff --git a/Source/cmSourceFile.cxx b/Source/cmSourceFile.cxx index bd68d04..2a345eb 100644 --- a/Source/cmSourceFile.cxx +++ b/Source/cmSourceFile.cxx @@ -6,6 +6,7 @@ #include <utility> #include "cmGlobalGenerator.h" +#include "cmListFileCache.h" #include "cmMakefile.h" #include "cmMessageType.h" #include "cmProperty.h" @@ -28,6 +29,11 @@ std::string const& cmSourceFile::GetExtension() const const std::string cmSourceFile::propLANGUAGE = "LANGUAGE"; const std::string cmSourceFile::propLOCATION = "LOCATION"; const std::string cmSourceFile::propGENERATED = "GENERATED"; +const std::string cmSourceFile::propCOMPILE_DEFINITIONS = + "COMPILE_DEFINITIONS"; +const std::string cmSourceFile::propCOMPILE_OPTIONS = "COMPILE_OPTIONS"; +const std::string cmSourceFile::propINCLUDE_DIRECTORIES = + "INCLUDE_DIRECTORIES"; void cmSourceFile::SetObjectLibrary(std::string const& objlib) { @@ -226,7 +232,27 @@ bool cmSourceFile::Matches(cmSourceFileLocation const& loc) void cmSourceFile::SetProperty(const std::string& prop, const char* value) { - this->Properties.SetProperty(prop, value); + if (prop == propINCLUDE_DIRECTORIES) { + this->IncludeDirectories.clear(); + if (value) { + cmListFileBacktrace lfbt = this->Location.GetMakefile()->GetBacktrace(); + this->IncludeDirectories.emplace_back(value, lfbt); + } + } else if (prop == propCOMPILE_OPTIONS) { + this->CompileOptions.clear(); + if (value) { + cmListFileBacktrace lfbt = this->Location.GetMakefile()->GetBacktrace(); + this->CompileOptions.emplace_back(value, lfbt); + } + } else if (prop == propCOMPILE_DEFINITIONS) { + this->CompileDefinitions.clear(); + if (value) { + cmListFileBacktrace lfbt = this->Location.GetMakefile()->GetBacktrace(); + this->CompileDefinitions.emplace_back(value, lfbt); + } + } else { + this->Properties.SetProperty(prop, value); + } // Update IsGenerated flag if (prop == propGENERATED) { @@ -237,7 +263,24 @@ void cmSourceFile::SetProperty(const std::string& prop, const char* value) void cmSourceFile::AppendProperty(const std::string& prop, const char* value, bool asString) { - this->Properties.AppendProperty(prop, value, asString); + if (prop == propINCLUDE_DIRECTORIES) { + if (value && *value) { + cmListFileBacktrace lfbt = this->Location.GetMakefile()->GetBacktrace(); + this->IncludeDirectories.emplace_back(value, lfbt); + } + } else if (prop == propCOMPILE_OPTIONS) { + if (value && *value) { + cmListFileBacktrace lfbt = this->Location.GetMakefile()->GetBacktrace(); + this->CompileOptions.emplace_back(value, lfbt); + } + } else if (prop == propCOMPILE_DEFINITIONS) { + if (value && *value) { + cmListFileBacktrace lfbt = this->Location.GetMakefile()->GetBacktrace(); + this->CompileDefinitions.emplace_back(value, lfbt); + } + } else { + this->Properties.AppendProperty(prop, value, asString); + } // Update IsGenerated flag if (prop == propGENERATED) { @@ -287,6 +330,37 @@ const char* cmSourceFile::GetProperty(const std::string& prop) const return this->FullPath.c_str(); } + // Check for the properties with backtraces. + if (prop == propINCLUDE_DIRECTORIES) { + if (this->IncludeDirectories.empty()) { + return nullptr; + } + + static std::string output; + output = cmJoin(this->IncludeDirectories, ";"); + return output.c_str(); + } + + if (prop == propCOMPILE_OPTIONS) { + if (this->CompileOptions.empty()) { + return nullptr; + } + + static std::string output; + output = cmJoin(this->CompileOptions, ";"); + return output.c_str(); + } + + if (prop == propCOMPILE_DEFINITIONS) { + if (this->CompileDefinitions.empty()) { + return nullptr; + } + + static std::string output; + output = cmJoin(this->CompileDefinitions, ";"); + return output.c_str(); + } + const char* retVal = this->Properties.GetPropertyValue(prop); if (!retVal) { cmMakefile const* mf = this->Location.GetMakefile(); diff --git a/Source/cmSourceFile.h b/Source/cmSourceFile.h index 3b18fdb..6ef4167 100644 --- a/Source/cmSourceFile.h +++ b/Source/cmSourceFile.h @@ -6,6 +6,7 @@ #include "cmConfigure.h" // IWYU pragma: keep #include "cmCustomCommand.h" +#include "cmListFileCache.h" #include "cmPropertyMap.h" #include "cmSourceFileLocation.h" #include "cmSourceFileLocationKind.h" @@ -57,6 +58,21 @@ public: /// @return Equivalent to GetPropertyAsBool("GENERATED") bool GetIsGenerated() const { return this->IsGenerated; } + const std::vector<BT<std::string>>& GetCompileOptions() const + { + return this->CompileOptions; + } + + const std::vector<BT<std::string>>& GetCompileDefinitions() const + { + return this->CompileDefinitions; + } + + const std::vector<BT<std::string>>& GetIncludeDirectories() const + { + return this->IncludeDirectories; + } + /** * Resolves the full path to the file. Attempts to locate the file on disk * and finalizes its location. @@ -116,6 +132,9 @@ private: std::string FullPath; std::string ObjectLibrary; std::vector<std::string> Depends; + std::vector<BT<std::string>> CompileOptions; + std::vector<BT<std::string>> CompileDefinitions; + std::vector<BT<std::string>> IncludeDirectories; bool FindFullPathFailed = false; bool IsGenerated = false; @@ -126,6 +145,9 @@ private: static const std::string propLANGUAGE; static const std::string propLOCATION; static const std::string propGENERATED; + static const std::string propCOMPILE_DEFINITIONS; + static const std::string propCOMPILE_OPTIONS; + static const std::string propINCLUDE_DIRECTORIES; }; // TODO: Factor out into platform information modules. |