diff options
Diffstat (limited to 'Source/cmMakefile.cxx')
-rw-r--r-- | Source/cmMakefile.cxx | 377 |
1 files changed, 154 insertions, 223 deletions
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index e0f69cb..f101cdc 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -9,14 +9,13 @@ #include <cstring> #include <ctype.h> #include <iterator> -#include <memory> // IWYU pragma: keep +#include <memory> #include <sstream> #include <stdio.h> #include <stdlib.h> #include <utility> #include "cmAlgorithms.h" -#include "cmCommand.h" #include "cmCommandArgumentParserHelper.h" #include "cmCustomCommand.h" #include "cmCustomCommandLines.h" @@ -24,6 +23,7 @@ #include "cmExpandedCommandArgument.h" // IWYU pragma: keep #include "cmFileLockPool.h" #include "cmFunctionBlocker.h" +#include "cmGeneratedFileStream.h" #include "cmGeneratorExpression.h" #include "cmGeneratorExpressionEvaluationFile.h" #include "cmGlobalGenerator.h" @@ -48,7 +48,7 @@ #include "cmConfigure.h" // IWYU pragma: keep -#ifdef CMAKE_BUILD_WITH_CMAKE +#ifndef CMAKE_BOOTSTRAP # include "cmVariableWatch.h" #endif @@ -98,7 +98,7 @@ cmMakefile::cmMakefile(cmGlobalGenerator* globalGenerator, // cmListFileCache in the top level if necessary. this->CheckCMP0000 = false; -#if defined(CMAKE_BUILD_WITH_CMAKE) +#if !defined(CMAKE_BOOTSTRAP) this->AddSourceGroup("", "^.*$"); this->AddSourceGroup("Source Files", CM_SOURCE_REGEX); this->AddSourceGroup("Header Files", CM_HEADER_REGEX); @@ -118,8 +118,6 @@ cmMakefile::~cmMakefile() cmDeleteAll(this->SourceFiles); cmDeleteAll(this->Tests); cmDeleteAll(this->ImportedTargetsOwned); - cmDeleteAll(this->FinalPassCommands); - cmDeleteAll(this->FunctionBlockers); cmDeleteAll(this->EvaluationFiles); } @@ -324,7 +322,13 @@ void cmMakefile::PrintCommandTrace(const cmListFileFunction& lff) const msg << " "; } msg << ")"; - cmSystemTools::Message(msg.str()); + + auto& f = this->GetCMakeInstance()->GetTraceFile(); + if (f) { + f << msg.str() << '\n'; + } else { + cmSystemTools::Message(msg.str()); + } } // Helper class to make sure the call stack is valid. @@ -356,6 +360,11 @@ private: cmMakefile* Makefile; }; +void cmMakefile::OnExecuteCommand(std::function<void()> callback) +{ + this->ExecuteCommandCallback = std::move(callback); +} + bool cmMakefile::ExecuteCommand(const cmListFileFunction& lff, cmExecutionStatus& status) { @@ -367,6 +376,10 @@ bool cmMakefile::ExecuteCommand(const cmListFileFunction& lff, return result; } + if (this->ExecuteCommandCallback) { + this->ExecuteCommandCallback(); + } + // Place this call on the call stack. cmMakefileCall stack_manager(this, lff, status); static_cast<void>(stack_manager); @@ -390,12 +403,8 @@ bool cmMakefile::ExecuteCommand(const cmListFileFunction& lff, } // Lookup the command prototype. - if (cmCommand* proto = + if (cmState::Command command = this->GetState()->GetCommandByExactName(lff.Name.Lower)) { - // Clone the prototype. - std::unique_ptr<cmCommand> pcmd(proto->Clone()); - pcmd->SetMakefile(this); - // Decide whether to invoke the command. if (!cmSystemTools::GetFatalErrorOccured()) { // if trace is enabled, print out invoke information @@ -403,29 +412,25 @@ bool cmMakefile::ExecuteCommand(const cmListFileFunction& lff, this->PrintCommandTrace(lff); } // Try invoking the command. - bool invokeSucceeded = pcmd->InvokeInitialPass(lff.Arguments, status); + bool invokeSucceeded = command(lff.Arguments, status); bool hadNestedError = status.GetNestedError(); if (!invokeSucceeded || hadNestedError) { if (!hadNestedError) { // The command invocation requested that we report an error. std::string const error = - std::string(lff.Name.Original) + " " + pcmd->GetError(); + std::string(lff.Name.Original) + " " + status.GetError(); this->IssueMessage(MessageType::FATAL_ERROR, error); } result = false; if (this->GetCMakeInstance()->GetWorkingMode() != cmake::NORMAL_MODE) { cmSystemTools::SetFatalErrorOccured(); } - } else if (pcmd->HasFinalPass()) { - // use the command - this->FinalPassCommands.push_back(pcmd.release()); } } } else { if (!cmSystemTools::GetFatalErrorOccured()) { - std::string error = "Unknown CMake command \""; - error += lff.Name.Original; - error += "\"."; + std::string error = + cmStrCat("Unknown CMake command \"", lff.Name.Original, "\"."); this->IssueMessage(MessageType::FATAL_ERROR, error); result = false; cmSystemTools::SetFatalErrorOccured(); @@ -567,8 +572,9 @@ void cmMakefile::IncludeScope::EnforceCMP0011() bool cmMakefile::ReadDependentFile(const std::string& filename, bool noPolicyScope) { - this->AddDefinition("CMAKE_PARENT_LIST_FILE", - this->GetDefinition("CMAKE_CURRENT_LIST_FILE")); + if (const char* def = this->GetDefinition("CMAKE_CURRENT_LIST_FILE")) { + this->AddDefinition("CMAKE_PARENT_LIST_FILE", def); + } std::string filenametoread = cmSystemTools::CollapseFullPath( filename, this->GetCurrentSourceDirectory()); @@ -651,9 +657,9 @@ void cmMakefile::ReadListFile(cmListFile const& listFile, this->GetSafeDefinition("CMAKE_PARENT_LIST_FILE"); std::string currentFile = this->GetSafeDefinition("CMAKE_CURRENT_LIST_FILE"); - this->AddDefinition("CMAKE_CURRENT_LIST_FILE", filenametoread.c_str()); + this->AddDefinition("CMAKE_CURRENT_LIST_FILE", filenametoread); this->AddDefinition("CMAKE_CURRENT_LIST_DIR", - cmSystemTools::GetFilenamePath(filenametoread).c_str()); + cmSystemTools::GetFilenamePath(filenametoread)); this->MarkVariableAsUsed("CMAKE_PARENT_LIST_FILE"); this->MarkVariableAsUsed("CMAKE_CURRENT_LIST_FILE"); @@ -662,7 +668,7 @@ void cmMakefile::ReadListFile(cmListFile const& listFile, // Run the parsed commands. const size_t numberFunctions = listFile.Functions.size(); for (size_t i = 0; i < numberFunctions; ++i) { - cmExecutionStatus status; + cmExecutionStatus status(*this); this->ExecuteCommand(listFile.Functions[i], status); if (cmSystemTools::GetFatalErrorOccured()) { break; @@ -674,10 +680,10 @@ void cmMakefile::ReadListFile(cmListFile const& listFile, } this->CheckForUnusedVariables(); - this->AddDefinition("CMAKE_PARENT_LIST_FILE", currentParentFile.c_str()); - this->AddDefinition("CMAKE_CURRENT_LIST_FILE", currentFile.c_str()); + this->AddDefinition("CMAKE_PARENT_LIST_FILE", currentParentFile); + this->AddDefinition("CMAKE_CURRENT_LIST_FILE", currentFile); this->AddDefinition("CMAKE_CURRENT_LIST_DIR", - cmSystemTools::GetFilenamePath(currentFile).c_str()); + cmSystemTools::GetFilenamePath(currentFile)); this->MarkVariableAsUsed("CMAKE_PARENT_LIST_FILE"); this->MarkVariableAsUsed("CMAKE_CURRENT_LIST_FILE"); this->MarkVariableAsUsed("CMAKE_CURRENT_LIST_DIR"); @@ -769,6 +775,11 @@ struct file_not_persistent }; } +void cmMakefile::AddFinalAction(FinalAction action) +{ + this->FinalActions.push_back(std::move(action)); +} + void cmMakefile::FinalPass() { // do all the variable expansions here @@ -776,8 +787,8 @@ void cmMakefile::FinalPass() // give all the commands a chance to do something // after the file has been parsed before generation - for (cmCommand* fpCommand : this->FinalPassCommands) { - fpCommand->FinalPass(); + for (FinalAction& action : this->FinalActions) { + action(*this); } // go through all configured files and see which ones still exist. @@ -1176,10 +1187,8 @@ cmTarget* cmMakefile::AddUtilityCommand( // Store the custom command in the target. if (!commandLines.empty() || !depends.empty()) { - std::string force = this->GetCurrentBinaryDirectory(); - force += "/CMakeFiles"; - force += "/"; - force += utilityName; + std::string force = + cmStrCat(this->GetCurrentBinaryDirectory(), "/CMakeFiles/", utilityName); std::vector<std::string> forced; forced.push_back(force); std::string no_main_dependency; @@ -1343,8 +1352,7 @@ bool cmMakefile::ParseDefineFlag(std::string const& def, bool remove) if (remove) { if (const char* cdefs = this->GetProperty("COMPILE_DEFINITIONS")) { // Expand the list. - std::vector<std::string> defs; - cmSystemTools::ExpandListArgument(cdefs, defs); + std::vector<std::string> defs = cmExpandedList(cdefs); // Recompose the list without the definition. std::vector<std::string>::const_iterator defEnd = @@ -1385,8 +1393,8 @@ void cmMakefile::InitializeFromParent(cmMakefile* parent) std::vector<std::string> configs; this->GetConfigurations(configs); for (std::string const& config : configs) { - std::string defPropName = "COMPILE_DEFINITIONS_"; - defPropName += cmSystemTools::UpperCase(config); + std::string defPropName = + cmStrCat("COMPILE_DEFINITIONS_", cmSystemTools::UpperCase(config)); const char* prop = parent->GetProperty(defPropName); this->SetProperty(defPropName, prop); } @@ -1420,7 +1428,7 @@ void cmMakefile::PushFunctionScope(std::string const& fileName, this->PushLoopBlockBarrier(); -#if defined(CMAKE_BUILD_WITH_CMAKE) +#if !defined(CMAKE_BOOTSTRAP) this->GetGlobalGenerator()->GetFileLockPool().PushFunctionScope(); #endif @@ -1437,7 +1445,7 @@ void cmMakefile::PopFunctionScope(bool reportError) this->PopFunctionBlockerBarrier(reportError); -#if defined(CMAKE_BUILD_WITH_CMAKE) +#if !defined(CMAKE_BOOTSTRAP) this->GetGlobalGenerator()->GetFileLockPool().PopFunctionScope(); #endif @@ -1479,8 +1487,8 @@ public: , ReportError(true) { std::string currentStart = - this->Makefile->StateSnapshot.GetDirectory().GetCurrentSource(); - currentStart += "/CMakeLists.txt"; + cmStrCat(this->Makefile->StateSnapshot.GetDirectory().GetCurrentSource(), + "/CMakeLists.txt"); this->Makefile->StateSnapshot.SetListFile(currentStart); this->Makefile->StateSnapshot = this->Makefile->StateSnapshot.GetState()->CreatePolicyScopeSnapshot( @@ -1492,7 +1500,7 @@ public: this->Snapshot = this->GG->GetCMakeInstance()->GetCurrentSnapshot(); this->GG->GetCMakeInstance()->SetCurrentSnapshot(this->Snapshot); this->GG->SetCurrentMakefile(mf); -#if defined(CMAKE_BUILD_WITH_CMAKE) +#if !defined(CMAKE_BOOTSTRAP) this->GG->GetFileLockPool().PushFileScope(); #endif } @@ -1501,7 +1509,7 @@ public: { this->Makefile->PopFunctionBlockerBarrier(this->ReportError); this->Makefile->PopSnapshot(this->ReportError); -#if defined(CMAKE_BUILD_WITH_CMAKE) +#if !defined(CMAKE_BOOTSTRAP) this->GG->GetFileLockPool().PopFileScope(); #endif this->GG->SetCurrentMakefile(this->CurrentMakefile); @@ -1523,9 +1531,8 @@ private: void cmMakefile::Configure() { - std::string currentStart = - this->StateSnapshot.GetDirectory().GetCurrentSource(); - currentStart += "/CMakeLists.txt"; + std::string currentStart = cmStrCat( + this->StateSnapshot.GetDirectory().GetCurrentSource(), "/CMakeLists.txt"); // Add the bottom of all backtraces within this directory. // We will never pop this scope because it should be available @@ -1535,12 +1542,12 @@ void cmMakefile::Configure() BuildsystemFileScope scope(this); // make sure the CMakeFiles dir is there - std::string filesDir = this->StateSnapshot.GetDirectory().GetCurrentBinary(); - filesDir += "/CMakeFiles"; + std::string filesDir = cmStrCat( + this->StateSnapshot.GetDirectory().GetCurrentBinary(), "/CMakeFiles"); cmSystemTools::MakeDirectory(filesDir); assert(cmSystemTools::FileExists(currentStart, true)); - this->AddDefinition("CMAKE_PARENT_LIST_FILE", currentStart.c_str()); + this->AddDefinition("CMAKE_PARENT_LIST_FILE", currentStart); cmListFile listFile; if (!listFile.ParseFile(currentStart.c_str(), this->GetMessenger(), @@ -1578,7 +1585,7 @@ void cmMakefile::Configure() allowedCommands.insert("message"); isProblem = false; for (cmListFileFunction const& func : listFile.Functions) { - if (allowedCommands.find(func.Name.Lower) == allowedCommands.end()) { + if (!cmContains(allowedCommands, func.Name.Lower)) { isProblem = true; break; } @@ -1647,8 +1654,7 @@ void cmMakefile::ConfigureSubDirectory(cmMakefile* mf) mf->InitializeFromParent(this); std::string currentStart = mf->GetCurrentSourceDirectory(); if (this->GetCMakeInstance()->GetDebugOutput()) { - std::string msg = " Entering "; - msg += currentStart; + std::string msg = cmStrCat(" Entering ", currentStart); cmSystemTools::Message(msg); } @@ -1690,8 +1696,8 @@ void cmMakefile::ConfigureSubDirectory(cmMakefile* mf) mf->Configure(); if (this->GetCMakeInstance()->GetDebugOutput()) { - std::string msg = " Returning to "; - msg += this->GetCurrentSourceDirectory(); + std::string msg = + cmStrCat(" Returning to ", this->GetCurrentSourceDirectory()); cmSystemTools::Message(msg); } } @@ -1788,26 +1794,27 @@ void cmMakefile::AddSystemIncludeDirectories(const std::set<std::string>& incs) } } -void cmMakefile::AddDefinition(const std::string& name, const char* value) +void cmMakefile::AddDefinition(const std::string& name, cm::string_view value) { - if (!value) { - return; - } - if (this->VariableInitialized(name)) { this->LogUnused("changing definition", name); } this->StateSnapshot.SetDefinition(name, value); -#ifdef CMAKE_BUILD_WITH_CMAKE +#ifndef CMAKE_BOOTSTRAP cmVariableWatch* vv = this->GetVariableWatch(); if (vv) { vv->VariableAccessed(name, cmVariableWatch::VARIABLE_MODIFIED_ACCESS, - value, this); + value.data(), this); } #endif } +void cmMakefile::AddDefinitionBool(const std::string& name, bool value) +{ + this->AddDefinition(name, value ? "ON" : "OFF"); +} + void cmMakefile::AddCacheDefinition(const std::string& name, const char* value, const char* doc, cmStateEnums::CacheEntryType type, @@ -1831,10 +1838,10 @@ void cmMakefile::AddCacheDefinition(const std::string& name, const char* value, std::vector<std::string> files; nvalue = value ? value : ""; - cmSystemTools::ExpandListArgument(nvalue, files); + cmExpandList(nvalue, files); nvalue.clear(); for (cc = 0; cc < files.size(); cc++) { - if (!cmSystemTools::IsOff(files[cc])) { + if (!cmIsOff(files[cc])) { files[cc] = cmSystemTools::CollapseFullPath(files[cc]); } if (cc > 0) { @@ -1853,23 +1860,6 @@ void cmMakefile::AddCacheDefinition(const std::string& name, const char* value, this->StateSnapshot.RemoveDefinition(name); } -void cmMakefile::AddDefinition(const std::string& name, bool value) -{ - if (this->VariableInitialized(name)) { - this->LogUnused("changing definition", name); - } - - this->StateSnapshot.SetDefinition(name, value ? "ON" : "OFF"); - -#ifdef CMAKE_BUILD_WITH_CMAKE - cmVariableWatch* vv = this->GetVariableWatch(); - if (vv) { - vv->VariableAccessed(name, cmVariableWatch::VARIABLE_MODIFIED_ACCESS, - value ? "ON" : "OFF", this); - } -#endif -} - void cmMakefile::CheckForUnusedVariables() const { if (!this->WarnUnused) { @@ -1914,8 +1904,7 @@ void cmMakefile::LogUnused(const char* reason, const std::string& name) const if (!this->ExecutionStatusStack.empty()) { path = this->GetExecutionContext().FilePath; } else { - path = this->GetCurrentSourceDirectory(); - path += "/CMakeLists.txt"; + path = cmStrCat(this->GetCurrentSourceDirectory(), "/CMakeLists.txt"); } if (this->CheckSystemVars || this->IsProjectFile(path.c_str())) { @@ -1932,7 +1921,7 @@ void cmMakefile::RemoveDefinition(const std::string& name) this->LogUnused("unsetting", name); } this->StateSnapshot.RemoveDefinition(name); -#ifdef CMAKE_BUILD_WITH_CMAKE +#ifndef CMAKE_BOOTSTRAP cmVariableWatch* vv = this->GetVariableWatch(); if (vv) { vv->VariableAccessed(name, cmVariableWatch::VARIABLE_REMOVED_ACCESS, @@ -1963,8 +1952,7 @@ void cmMakefile::AddGlobalLinkInformation(cmTarget& target) } if (const char* linkLibsProp = this->GetProperty("LINK_LIBRARIES")) { - std::vector<std::string> linkLibs; - cmSystemTools::ExpandListArgument(linkLibsProp, linkLibs); + std::vector<std::string> linkLibs = cmExpandedList(linkLibsProp); for (std::vector<std::string>::iterator j = linkLibs.begin(); j != linkLibs.end(); ++j) { @@ -2090,7 +2078,7 @@ cmSourceFile* cmMakefile::GetSourceFileWithOutput( return nullptr; } -#if defined(CMAKE_BUILD_WITH_CMAKE) +#if !defined(CMAKE_BOOTSTRAP) cmSourceGroup* cmMakefile::GetSourceGroup( const std::vector<std::string>& name) const { @@ -2186,8 +2174,7 @@ cmSourceGroup* cmMakefile::GetOrCreateSourceGroup(const std::string& name) if (delimiter == nullptr) { delimiter = "\\"; } - return this->GetOrCreateSourceGroup( - cmSystemTools::tokenize(name, delimiter)); + return this->GetOrCreateSourceGroup(cmTokenize(name, delimiter)); } /** @@ -2292,8 +2279,7 @@ void cmMakefile::ExpandVariablesCMP0019() } if (const char* linkLibsProp = this->GetProperty("LINK_LIBRARIES")) { - std::vector<std::string> linkLibs; - cmSystemTools::ExpandListArgument(linkLibsProp, linkLibs); + std::vector<std::string> linkLibs = cmExpandedList(linkLibsProp); for (std::vector<std::string>::iterator l = linkLibs.begin(); l != linkLibs.end(); ++l) { @@ -2336,7 +2322,7 @@ void cmMakefile::ExpandVariablesCMP0019() bool cmMakefile::IsOn(const std::string& name) const { const char* value = this->GetDefinition(name); - return cmSystemTools::IsOn(value); + return cmIsOn(value); } bool cmMakefile::IsSet(const std::string& name) const @@ -2350,7 +2336,7 @@ bool cmMakefile::IsSet(const std::string& name) const return false; } - if (cmSystemTools::IsNOTFOUND(value)) { + if (cmIsNOTFOUND(value)) { return false; } @@ -2472,7 +2458,7 @@ bool cmMakefile::IsDefinitionSet(const std::string& name) const if (!def) { def = this->GetState()->GetInitializedCacheValue(name); } -#ifdef CMAKE_BUILD_WITH_CMAKE +#ifndef CMAKE_BOOTSTRAP if (cmVariableWatch* vv = this->GetVariableWatch()) { if (!def) { vv->VariableAccessed( @@ -2489,7 +2475,7 @@ const std::string* cmMakefile::GetDef(const std::string& name) const if (!def) { def = this->GetState()->GetInitializedCacheValue(name); } -#ifdef CMAKE_BUILD_WITH_CMAKE +#ifndef CMAKE_BOOTSTRAP cmVariableWatch* vv = this->GetVariableWatch(); if (vv && !this->SuppressSideEffects) { bool const watch_function_executed = @@ -2608,8 +2594,8 @@ const std::string& cmMakefile::ExpandVariablesInString( } // ...otherwise, see if there's a difference that needs to be warned about. else if (compareResults && (newResult != source || newError != mtype)) { - std::string msg = cmPolicies::GetPolicyWarning(cmPolicies::CMP0053); - msg += "\n"; + std::string msg = + cmStrCat(cmPolicies::GetPolicyWarning(cmPolicies::CMP0053), '\n'); std::string msg_input = original; cmSystemTools::ReplaceString(msg_input, "\n", "\n "); @@ -2679,7 +2665,7 @@ MessageType cmMakefile::ExpandVariablesInStringOld( if (const char* val = this->GetDefinition(var)) { // Store the value in the output escaping as requested. if (escapeQuotes) { - source.append(cmSystemTools::EscapeQuotes(val)); + source.append(cmEscapeQuotes(val)); } else { source.append(val); } @@ -2824,9 +2810,7 @@ MessageType cmMakefile::ExpandVariablesInStringNew( switch (var.domain) { case NORMAL: if (filename && lookup == lineVar) { - std::ostringstream ostr; - ostr << line; - varresult = ostr.str(); + varresult = std::to_string(line); } else { value = this->GetDefinition(lookup); } @@ -2843,7 +2827,7 @@ MessageType cmMakefile::ExpandVariablesInStringNew( // Get the string we're meant to append to. if (value) { if (escapeQuotes) { - varresult = cmSystemTools::EscapeQuotes(value); + varresult = cmEscapeQuotes(value); } else { varresult = value; } @@ -2969,7 +2953,7 @@ MessageType cmMakefile::ExpandVariablesInStringNew( } if (escapeQuotes) { - varresult = cmSystemTools::EscapeQuotes(varresult); + varresult = cmEscapeQuotes(varresult); } // Skip over the variable. result.append(last, in - last); @@ -3062,7 +3046,7 @@ std::string cmMakefile::GetConfigurations(std::vector<std::string>& configs, if (this->GetGlobalGenerator()->IsMultiConfig()) { if (const char* configTypes = this->GetDefinition("CMAKE_CONFIGURATION_TYPES")) { - cmSystemTools::ExpandListArgument(configTypes, configs); + cmExpandList(configTypes, configs); } return ""; } @@ -3077,19 +3061,11 @@ bool cmMakefile::IsFunctionBlocked(const cmListFileFunction& lff, cmExecutionStatus& status) { // if there are no blockers get out of here - if (this->FunctionBlockers.begin() == this->FunctionBlockers.end()) { + if (this->FunctionBlockers.empty()) { return false; } - // loop over all function blockers to see if any block this command - // evaluate in reverse, this is critical for balanced IF statements etc - for (cmFunctionBlocker* pos : cmReverseRange(this->FunctionBlockers)) { - if (pos->IsFunctionBlocked(lff, *this, status)) { - return true; - } - } - - return false; + return this->FunctionBlockers.top()->IsFunctionBlocked(lff, status); } void cmMakefile::PushFunctionBlockerBarrier() @@ -3103,8 +3079,9 @@ void cmMakefile::PopFunctionBlockerBarrier(bool reportError) FunctionBlockersType::size_type barrier = this->FunctionBlockerBarriers.back(); while (this->FunctionBlockers.size() > barrier) { - std::unique_ptr<cmFunctionBlocker> fb(this->FunctionBlockers.back()); - this->FunctionBlockers.pop_back(); + std::unique_ptr<cmFunctionBlocker> fb( + std::move(this->FunctionBlockers.top())); + this->FunctionBlockers.pop(); if (reportError) { // Report the context in which the unclosed block was opened. cmListFileContext const& lfc = fb->GetStartingContext(); @@ -3186,7 +3163,7 @@ bool cmMakefile::ExpandArguments(std::vector<cmListFileArgument> const& inArgs, if (i.Delim == cmListFileArgument::Quoted) { outArgs.push_back(value); } else { - cmSystemTools::ExpandListArgument(value, outArgs); + cmExpandList(value, outArgs); } } return !cmSystemTools::GetFatalErrorOccured(); @@ -3218,8 +3195,7 @@ bool cmMakefile::ExpandArguments( if (i.Delim == cmListFileArgument::Quoted) { outArgs.emplace_back(value, true); } else { - std::vector<std::string> stringArgs; - cmSystemTools::ExpandListArgument(value, stringArgs); + std::vector<std::string> stringArgs = cmExpandedList(value); for (std::string const& stringArg : stringArgs) { outArgs.emplace_back(stringArg, false); } @@ -3228,54 +3204,25 @@ bool cmMakefile::ExpandArguments( return !cmSystemTools::GetFatalErrorOccured(); } -void cmMakefile::AddFunctionBlocker(cmFunctionBlocker* fb) +void cmMakefile::AddFunctionBlocker(std::unique_ptr<cmFunctionBlocker> fb) { if (!this->ExecutionStatusStack.empty()) { // Record the context in which the blocker is created. fb->SetStartingContext(this->GetExecutionContext()); } - this->FunctionBlockers.push_back(fb); + this->FunctionBlockers.push(std::move(fb)); } -std::unique_ptr<cmFunctionBlocker> cmMakefile::RemoveFunctionBlocker( - cmFunctionBlocker* fb, const cmListFileFunction& lff) +std::unique_ptr<cmFunctionBlocker> cmMakefile::RemoveFunctionBlocker() { - // Find the function blocker stack barrier for the current scope. - // We only remove a blocker whose index is not less than the barrier. - FunctionBlockersType::size_type barrier = 0; - if (!this->FunctionBlockerBarriers.empty()) { - barrier = this->FunctionBlockerBarriers.back(); - } + assert(!this->FunctionBlockers.empty()); + assert(this->FunctionBlockerBarriers.empty() || + this->FunctionBlockers.size() > this->FunctionBlockerBarriers.back()); - // Search for the function blocker whose scope this command ends. - for (FunctionBlockersType::size_type i = this->FunctionBlockers.size(); - i > barrier; --i) { - std::vector<cmFunctionBlocker*>::iterator pos = - this->FunctionBlockers.begin() + (i - 1); - if (*pos == fb) { - // Warn if the arguments do not match, but always remove. - if (!(*pos)->ShouldRemove(lff, *this)) { - cmListFileContext const& lfc = fb->GetStartingContext(); - cmListFileContext closingContext = - cmListFileContext::FromCommandContext(lff, lfc.FilePath); - std::ostringstream e; - /* clang-format off */ - e << "A logical block opening on the line\n" - << " " << lfc << "\n" - << "closes on the line\n" - << " " << closingContext << "\n" - << "with mis-matching arguments."; - /* clang-format on */ - this->IssueMessage(MessageType::AUTHOR_WARNING, e.str()); - } - cmFunctionBlocker* b = *pos; - this->FunctionBlockers.erase(pos); - return std::unique_ptr<cmFunctionBlocker>(b); - } - } - - return std::unique_ptr<cmFunctionBlocker>(); + auto b = std::move(this->FunctionBlockers.top()); + this->FunctionBlockers.pop(); + return b; } std::string const& cmMakefile::GetHomeDirectory() const @@ -3290,20 +3237,18 @@ std::string const& cmMakefile::GetHomeOutputDirectory() const void cmMakefile::SetScriptModeFile(std::string const& scriptfile) { - this->AddDefinition("CMAKE_SCRIPT_MODE_FILE", scriptfile.c_str()); + this->AddDefinition("CMAKE_SCRIPT_MODE_FILE", scriptfile); } void cmMakefile::SetArgcArgv(const std::vector<std::string>& args) { - std::ostringstream strStream; - strStream << args.size(); - this->AddDefinition("CMAKE_ARGC", strStream.str().c_str()); + this->AddDefinition("CMAKE_ARGC", std::to_string(args.size())); // this->MarkVariableAsUsed("CMAKE_ARGC"); for (unsigned int t = 0; t < args.size(); ++t) { std::ostringstream tmpStream; tmpStream << "CMAKE_ARGV" << t; - this->AddDefinition(tmpStream.str(), args[t].c_str()); + this->AddDefinition(tmpStream.str(), args[t]); // this->MarkVariableAsUsed(tmpStream.str().c_str()); } } @@ -3375,7 +3320,7 @@ void cmMakefile::AddTargetObject(std::string const& tgtName, cmSourceFile* sf = this->GetOrCreateSource(objFile, true); sf->SetObjectLibrary(tgtName); sf->SetProperty("EXTERNAL_OBJECT", "1"); -#if defined(CMAKE_BUILD_WITH_CMAKE) +#if !defined(CMAKE_BOOTSTRAP) this->SourceGroups[this->ObjectLibrariesSourceGroupIndex].AddGroupFile( sf->GetFullPath()); #endif @@ -3384,8 +3329,9 @@ void cmMakefile::AddTargetObject(std::string const& tgtName, void cmMakefile::EnableLanguage(std::vector<std::string> const& lang, bool optional) { - this->AddDefinition("CMAKE_CFG_INTDIR", - this->GetGlobalGenerator()->GetCMakeCFGIntDir()); + if (const char* def = this->GetGlobalGenerator()->GetCMakeCFGIntDir()) { + this->AddDefinition("CMAKE_CFG_INTDIR", def); + } // If RC is explicitly listed we need to do it after other languages. // On some platforms we enable RC implicitly while enabling others. // Do not let that look like recursive enable_language(RC). @@ -3556,7 +3502,7 @@ cmGlobalGenerator* cmMakefile::GetGlobalGenerator() const return this->GlobalGenerator; } -#ifdef CMAKE_BUILD_WITH_CMAKE +#ifndef CMAKE_BOOTSTRAP cmVariableWatch* cmMakefile::GetVariableWatch() const { if (this->GetCMakeInstance() && @@ -3604,8 +3550,7 @@ std::string cmMakefile::GetModulesFile(const std::string& filename, // Always search in CMAKE_MODULE_PATH: const char* cmakeModulePath = this->GetDefinition("CMAKE_MODULE_PATH"); if (cmakeModulePath) { - std::vector<std::string> modulePath; - cmSystemTools::ExpandListArgument(cmakeModulePath, modulePath); + std::vector<std::string> modulePath = cmExpandedList(cmakeModulePath); // Look through the possible module directories. for (std::string itempl : modulePath) { @@ -3620,9 +3565,8 @@ std::string cmMakefile::GetModulesFile(const std::string& filename, } // Always search in the standard modules location. - moduleInCMakeRoot = cmSystemTools::GetCMakeRoot(); - moduleInCMakeRoot += "/Modules/"; - moduleInCMakeRoot += filename; + moduleInCMakeRoot = + cmStrCat(cmSystemTools::GetCMakeRoot(), "/Modules/", filename); cmSystemTools::ConvertToUnixSlashes(moduleInCMakeRoot); if (!cmSystemTools::FileExists(moduleInCMakeRoot)) { moduleInCMakeRoot.clear(); @@ -3697,7 +3641,7 @@ void cmMakefile::ConfigureString(const std::string& input, std::string& output, // Replace #cmakedefine instances. if (this->cmDefineRegex.find(line)) { const char* def = this->GetDefinition(this->cmDefineRegex.match(2)); - if (!cmSystemTools::IsOff(def)) { + if (!cmIsOff(def)) { const std::string indentation = this->cmDefineRegex.match(1); cmSystemTools::ReplaceString(line, "#" + indentation + "cmakedefine", "#" + indentation + "define"); @@ -3713,7 +3657,7 @@ void cmMakefile::ConfigureString(const std::string& input, std::string& output, cmSystemTools::ReplaceString(line, "#" + indentation + "cmakedefine01", "#" + indentation + "define"); output += line; - if (!cmSystemTools::IsOff(def)) { + if (!cmIsOff(def)) { output += " 1"; } else { output += " 0"; @@ -3788,8 +3732,7 @@ int cmMakefile::ConfigureFile(const std::string& infile, } else { newLineCharacters = "\n"; } - std::string tempOutputFile = soutfile; - tempOutputFile += ".tmp"; + std::string tempOutputFile = cmStrCat(soutfile, ".tmp"); cmsys::ofstream fout(tempOutputFile.c_str(), omode); if (!fout) { cmSystemTools::Error("Could not open file for write in copy operation " + @@ -3877,7 +3820,7 @@ const char* cmMakefile::GetProperty(const std::string& prop, bool chain) const bool cmMakefile::GetPropertyAsBool(const std::string& prop) const { - return cmSystemTools::IsOn(this->GetProperty(prop)); + return cmIsOn(this->GetProperty(prop)); } std::vector<std::string> cmMakefile::GetPropertyKeys() const @@ -3930,15 +3873,13 @@ void cmMakefile::AddCMakeDependFilesFromUser() { std::vector<std::string> deps; if (const char* deps_str = this->GetProperty("CMAKE_CONFIGURE_DEPENDS")) { - cmSystemTools::ExpandListArgument(deps_str, deps); + cmExpandList(deps_str, deps); } for (std::string const& dep : deps) { if (cmSystemTools::FileIsFullPath(dep)) { this->AddCMakeDependFile(dep); } else { - std::string f = this->GetCurrentSourceDirectory(); - f += "/"; - f += dep; + std::string f = cmStrCat(this->GetCurrentSourceDirectory(), '/', dep); this->AddCMakeDependFile(f); } } @@ -3978,14 +3919,14 @@ void cmMakefile::PushScope() this->GetState()->CreateVariableScopeSnapshot(this->StateSnapshot); this->PushLoopBlockBarrier(); -#if defined(CMAKE_BUILD_WITH_CMAKE) +#if !defined(CMAKE_BOOTSTRAP) this->GetGlobalGenerator()->GetFileLockPool().PushFunctionScope(); #endif } void cmMakefile::PopScope() { -#if defined(CMAKE_BUILD_WITH_CMAKE) +#if !defined(CMAKE_BOOTSTRAP) this->GetGlobalGenerator()->GetFileLockPool().PopFunctionScope(); #endif @@ -4009,7 +3950,7 @@ void cmMakefile::RaiseScope(const std::string& var, const char* varDef) return; } -#ifdef CMAKE_BUILD_WITH_CMAKE +#ifndef CMAKE_BOOTSTRAP cmVariableWatch* vv = this->GetVariableWatch(); if (vv) { vv->VariableAccessed(var, cmVariableWatch::VARIABLE_MODIFIED_ACCESS, @@ -4059,7 +4000,7 @@ cmTarget* cmMakefile::FindTargetToUse(const std::string& name, bool cmMakefile::IsAlias(const std::string& name) const { - if (this->AliasTargets.find(name) != this->AliasTargets.end()) { + if (cmContains(this->AliasTargets, name)) { return true; } return this->GetGlobalGenerator()->IsAlias(name); @@ -4237,7 +4178,7 @@ void cmMakefile::StoreMatches(cmsys::RegularExpression& re) std::string const& m = re.match(i); if (!m.empty()) { std::string const& var = matchVariables[i]; - this->AddDefinition(var, m.c_str()); + this->AddDefinition(var, m); this->MarkVariableAsUsed(var); highest = static_cast<char>('0' + i); } @@ -4267,7 +4208,7 @@ bool cmMakefile::PolicyOptionalWarningEnabled(std::string const& var) { // Check for an explicit CMAKE_POLICY_WARNING_CMP<NNNN> setting. if (const char* val = this->GetDefinition(var)) { - return cmSystemTools::IsOn(val); + return cmIsOn(val); } // Enable optional policy warnings with --debug-output, --trace, // or --trace-expand. @@ -4300,7 +4241,7 @@ bool cmMakefile::SetPolicy(cmPolicies::PolicyID id, // Deprecate old policies, especially those that require a lot // of code to maintain the old behavior. - if (status == cmPolicies::OLD && id <= cmPolicies::CMP0066 && + if (status == cmPolicies::OLD && id <= cmPolicies::CMP0067 && !(this->GetCMakeInstance()->GetIsInTryCompile() && ( // Policies set by cmCoreTryCompile::TryCompileCode. @@ -4424,10 +4365,8 @@ bool cmMakefile::AddRequiredTargetFeature(cmTarget* target, return false; } - std::vector<std::string> availableFeatures; - cmSystemTools::ExpandListArgument(features, availableFeatures); - if (std::find(availableFeatures.begin(), availableFeatures.end(), feature) == - availableFeatures.end()) { + std::vector<std::string> availableFeatures = cmExpandedList(features); + if (!cmContains(availableFeatures, feature)) { std::ostringstream e; e << "The compiler feature \"" << feature << "\" is not known to " << lang << " compiler\n\"" @@ -4549,10 +4488,10 @@ bool cmMakefile::HaveCStandardAvailable(cmTarget const* target, const char* defaultCStandard = this->GetDefinition("CMAKE_C_STANDARD_DEFAULT"); if (!defaultCStandard) { - std::ostringstream e; - e << "CMAKE_C_STANDARD_DEFAULT is not set. COMPILE_FEATURES support " - "not fully configured for this compiler."; - this->IssueMessage(MessageType::INTERNAL_ERROR, e.str()); + this->IssueMessage( + MessageType::INTERNAL_ERROR, + "CMAKE_C_STANDARD_DEFAULT is not set. COMPILE_FEATURES support " + "not fully configured for this compiler."); // Return true so the caller does not try to lookup the default standard. return true; } @@ -4633,10 +4572,10 @@ bool cmMakefile::HaveCxxStandardAvailable(cmTarget const* target, const char* defaultCxxStandard = this->GetDefinition("CMAKE_CXX_STANDARD_DEFAULT"); if (!defaultCxxStandard) { - std::ostringstream e; - e << "CMAKE_CXX_STANDARD_DEFAULT is not set. COMPILE_FEATURES support " - "not fully configured for this compiler."; - this->IssueMessage(MessageType::INTERNAL_ERROR, e.str()); + this->IssueMessage( + MessageType::INTERNAL_ERROR, + "CMAKE_CXX_STANDARD_DEFAULT is not set. COMPILE_FEATURES support " + "not fully configured for this compiler."); // Return true so the caller does not try to lookup the default standard. return true; } @@ -4694,33 +4633,28 @@ void cmMakefile::CheckNeededCxxLanguage(const std::string& feature, { if (const char* propCxx98 = this->GetDefinition("CMAKE_CXX98_COMPILE_FEATURES")) { - std::vector<std::string> props; - cmSystemTools::ExpandListArgument(propCxx98, props); - needCxx98 = std::find(props.begin(), props.end(), feature) != props.end(); + std::vector<std::string> props = cmExpandedList(propCxx98); + needCxx98 = cmContains(props, feature); } if (const char* propCxx11 = this->GetDefinition("CMAKE_CXX11_COMPILE_FEATURES")) { - std::vector<std::string> props; - cmSystemTools::ExpandListArgument(propCxx11, props); - needCxx11 = std::find(props.begin(), props.end(), feature) != props.end(); + std::vector<std::string> props = cmExpandedList(propCxx11); + needCxx11 = cmContains(props, feature); } if (const char* propCxx14 = this->GetDefinition("CMAKE_CXX14_COMPILE_FEATURES")) { - std::vector<std::string> props; - cmSystemTools::ExpandListArgument(propCxx14, props); - needCxx14 = std::find(props.begin(), props.end(), feature) != props.end(); + std::vector<std::string> props = cmExpandedList(propCxx14); + needCxx14 = cmContains(props, feature); } if (const char* propCxx17 = this->GetDefinition("CMAKE_CXX17_COMPILE_FEATURES")) { - std::vector<std::string> props; - cmSystemTools::ExpandListArgument(propCxx17, props); - needCxx17 = std::find(props.begin(), props.end(), feature) != props.end(); + std::vector<std::string> props = cmExpandedList(propCxx17); + needCxx17 = cmContains(props, feature); } if (const char* propCxx20 = this->GetDefinition("CMAKE_CXX20_COMPILE_FEATURES")) { - std::vector<std::string> props; - cmSystemTools::ExpandListArgument(propCxx20, props); - needCxx20 = std::find(props.begin(), props.end(), feature) != props.end(); + std::vector<std::string> props = cmExpandedList(propCxx20); + needCxx20 = cmContains(props, feature); } } @@ -4818,21 +4752,18 @@ void cmMakefile::CheckNeededCLanguage(const std::string& feature, { if (const char* propC90 = this->GetDefinition("CMAKE_C90_COMPILE_FEATURES")) { - std::vector<std::string> props; - cmSystemTools::ExpandListArgument(propC90, props); - needC90 = std::find(props.begin(), props.end(), feature) != props.end(); + std::vector<std::string> props = cmExpandedList(propC90); + needC90 = cmContains(props, feature); } if (const char* propC99 = this->GetDefinition("CMAKE_C99_COMPILE_FEATURES")) { - std::vector<std::string> props; - cmSystemTools::ExpandListArgument(propC99, props); - needC99 = std::find(props.begin(), props.end(), feature) != props.end(); + std::vector<std::string> props = cmExpandedList(propC99); + needC99 = cmContains(props, feature); } if (const char* propC11 = this->GetDefinition("CMAKE_C11_COMPILE_FEATURES")) { - std::vector<std::string> props; - cmSystemTools::ExpandListArgument(propC11, props); - needC11 = std::find(props.begin(), props.end(), feature) != props.end(); + std::vector<std::string> props = cmExpandedList(propC11); + needC11 = cmContains(props, feature); } } |