diff --git a/Source/cmAddCustomCommandCommand.cxx b/Source/cmAddCustomCommandCommand.cxx index 46067d1dc6..85a807b049 100644 --- a/Source/cmAddCustomCommandCommand.cxx +++ b/Source/cmAddCustomCommandCommand.cxx @@ -9,6 +9,7 @@ #include #include +#include #include #include "cmCustomCommand.h" @@ -44,8 +45,7 @@ bool cmAddCustomCommandCommand(std::vector const& args, std::string depfile; std::string job_pool; std::string job_server_aware; - std::string comment_buffer; - char const* comment = nullptr; + cm::optional comment; std::vector depends; std::vector outputs; std::vector output; @@ -369,7 +369,7 @@ bool cmAddCustomCommandCommand(std::vector const& args, byproducts.push_back(filename); break; case doing_comment: - if (!comment_buffer.empty()) { + if (comment && !comment->empty()) { std::string const msg = "COMMENT requires exactly one argument, but multiple values " "or COMMENT keywords have been given."; @@ -381,8 +381,7 @@ bool cmAddCustomCommandCommand(std::vector const& args, mf.IssuePolicyWarning(cmPolicies::CMP0175, msg); } } - comment_buffer = copy; - comment = comment_buffer.c_str(); + comment = copy; break; default: status.SetError("Wrong syntax. Unknown type of argument."); @@ -477,7 +476,7 @@ bool cmAddCustomCommandCommand(std::vector const& args, cc->SetByproducts(byproducts); cc->SetCommandLines(commandLines); cc->SetComment(comment); - cc->SetWorkingDirectory(working.c_str()); + cc->SetWorkingDirectory(working); cc->SetEscapeOldStyle(!verbatim); cc->SetUsesTerminal(uses_terminal); cc->SetDepfile(depfile); diff --git a/Source/cmAddCustomTargetCommand.cxx b/Source/cmAddCustomTargetCommand.cxx index 92bc25e077..b2da4e0739 100644 --- a/Source/cmAddCustomTargetCommand.cxx +++ b/Source/cmAddCustomTargetCommand.cxx @@ -5,6 +5,7 @@ #include #include +#include #include "cmCustomCommand.h" #include "cmCustomCommandLines.h" @@ -50,8 +51,7 @@ bool cmAddCustomTargetCommand(std::vector const& args, bool verbatim = false; bool uses_terminal = false; bool command_expand_lists = false; - std::string comment_buffer; - char const* comment = nullptr; + cm::optional comment; std::vector sources; std::string job_pool; std::string job_server_aware; @@ -143,8 +143,7 @@ bool cmAddCustomTargetCommand(std::vector const& args, depends.push_back(std::move(dep)); } break; case doing_comment: - comment_buffer = copy; - comment = comment_buffer.c_str(); + comment = copy; break; case doing_source: sources.push_back(copy); @@ -209,7 +208,7 @@ bool cmAddCustomTargetCommand(std::vector const& args, // Add the utility target to the makefile. auto cc = cm::make_unique(); - cc->SetWorkingDirectory(working_directory.c_str()); + cc->SetWorkingDirectory(working_directory); cc->SetByproducts(byproducts); cc->SetDepends(depends); cc->SetCommandLines(commandLines); diff --git a/Source/cmArgumentParser.cxx b/Source/cmArgumentParser.cxx index 30bdadc074..97c2d2a02f 100644 --- a/Source/cmArgumentParser.cxx +++ b/Source/cmArgumentParser.cxx @@ -127,7 +127,8 @@ void Instance::Bind(NonEmpty>& val) ExpectAtLeast{ 1 }); } -void Instance::Bind(std::vector>& multiVal) +void Instance::Bind( + MaybeEmpty>>& multiVal) { multiVal.emplace_back(); std::vector& val = multiVal.back(); @@ -139,6 +140,18 @@ void Instance::Bind(std::vector>& multiVal) ExpectAtLeast{ 0 }); } +void Instance::Bind(NonEmpty>>& multiVal) +{ + multiVal.emplace_back(); + std::vector& val = multiVal.back(); + this->Bind( + [&val](cm::string_view arg) -> Continue { + val.emplace_back(arg); + return Continue::Yes; + }, + ExpectAtLeast{ 1 }); +} + void Instance::Consume(cm::string_view arg) { ParserState& state = this->GetState(); diff --git a/Source/cmArgumentParser.h b/Source/cmArgumentParser.h index 6bc22503b5..7b378551ae 100644 --- a/Source/cmArgumentParser.h +++ b/Source/cmArgumentParser.h @@ -228,7 +228,8 @@ public: void Bind(Maybe& val); void Bind(MaybeEmpty>& val); void Bind(NonEmpty>& val); - void Bind(std::vector>& val); + void Bind(MaybeEmpty>>& val); + void Bind(NonEmpty>>& val); template void Bind(NonEmpty>>& val, diff --git a/Source/cmCustomCommand.cxx b/Source/cmCustomCommand.cxx index 5ec451efbd..b7b40a9bf7 100644 --- a/Source/cmCustomCommand.cxx +++ b/Source/cmCustomCommand.cxx @@ -77,16 +77,14 @@ void cmCustomCommand::SetCommandLines(cmCustomCommandLines commandLines) this->CommandLines = std::move(commandLines); } -char const* cmCustomCommand::GetComment() const +cm::optional const& cmCustomCommand::GetComment() const { - char const* no_comment = nullptr; - return this->HaveComment ? this->Comment.c_str() : no_comment; + return this->Comment; } -void cmCustomCommand::SetComment(char const* comment) +void cmCustomCommand::SetComment(cm::optional comment) { - this->Comment = comment ? comment : ""; - this->HaveComment = (comment != nullptr); + this->Comment = std::move(comment); } void cmCustomCommand::AppendCommands(cmCustomCommandLines const& commandLines) diff --git a/Source/cmCustomCommand.h b/Source/cmCustomCommand.h index 927747e971..0a4a767bee 100644 --- a/Source/cmCustomCommand.h +++ b/Source/cmCustomCommand.h @@ -8,6 +8,8 @@ #include #include +#include + #include "cmCustomCommandLines.h" #include "cmListFileCache.h" #include "cmPolicies.h" @@ -50,9 +52,9 @@ public: return this->WorkingDirectory; } - void SetWorkingDirectory(char const* workingDirectory) + void SetWorkingDirectory(std::string const& workingDirectory) { - this->WorkingDirectory = (workingDirectory ? workingDirectory : ""); + this->WorkingDirectory = workingDirectory; } /** Get the list of command lines. */ @@ -60,8 +62,8 @@ public: void SetCommandLines(cmCustomCommandLines commandLines); /** Get the comment string for the command. */ - char const* GetComment() const; - void SetComment(char const* comment); + cm::optional const& GetComment() const; + void SetComment(cm::optional comment); /** Get a value indicating if the command uses UTF-8 output pipes. */ bool GetStdPipesUTF8() const { return this->StdPipesUTF8; } @@ -148,13 +150,12 @@ private: cmListFileBacktrace Backtrace; cmImplicitDependsList ImplicitDepends; std::string Target; - std::string Comment; + cm::optional Comment; std::string WorkingDirectory; std::string Depfile; std::string JobPool; std::string Role; bool JobserverAware = false; - bool HaveComment = false; bool EscapeAllowMakeVars = false; bool EscapeOldStyle = true; bool UsesTerminal = false; diff --git a/Source/cmCustomCommandGenerator.cxx b/Source/cmCustomCommandGenerator.cxx index 6bb4b72388..9805ad6c88 100644 --- a/Source/cmCustomCommandGenerator.cxx +++ b/Source/cmCustomCommandGenerator.cxx @@ -152,7 +152,7 @@ std::string EvaluateDepfile(std::string const& path, return cge->Evaluate(lg, config); } -std::string EvaluateComment(char const* comment, +std::string EvaluateComment(std::string const& comment, cmGeneratorExpression const& ge, cmLocalGenerator* lg, std::string const& config) { @@ -484,12 +484,12 @@ std::string cmCustomCommandGenerator::GetInternalDepfile() const cm::optional cmCustomCommandGenerator::GetComment() const { - char const* comment = this->CC->GetComment(); - if (!comment) { + if (!this->CC->GetComment()) { return cm::nullopt; } - if (!*comment) { - return std::string(); + std::string const& comment = this->CC->GetComment().value(); + if (comment.empty()) { + return comment; } cmGeneratorExpression ge(*this->LG->GetCMakeInstance(), diff --git a/Source/cmExecuteProcessCommand.cxx b/Source/cmExecuteProcessCommand.cxx index 10563d0218..43d4febd33 100644 --- a/Source/cmExecuteProcessCommand.cxx +++ b/Source/cmExecuteProcessCommand.cxx @@ -79,7 +79,7 @@ bool cmExecuteProcessCommand(std::vector const& args, struct Arguments : public ArgumentParser::ParseResult { - std::vector> Commands; + ArgumentParser::MaybeEmpty>> Commands; std::string OutputVariable; std::string ErrorVariable; std::string ResultVariable; diff --git a/Source/cmExportCommand.cxx b/Source/cmExportCommand.cxx index 415b5521d5..02f463a331 100644 --- a/Source/cmExportCommand.cxx +++ b/Source/cmExportCommand.cxx @@ -487,8 +487,10 @@ static bool HandleSetupMode(std::vector const& args, { ArgumentParser::NonEmpty ExportSetName; ArgumentParser::NonEmpty CxxModulesDirectory; - std::vector> PackageDependencyArgs; - std::vector> TargetArgs; + ArgumentParser::MaybeEmpty>> + PackageDependencyArgs; + ArgumentParser::MaybeEmpty>> + TargetArgs; }; auto parser = cmArgumentParser{}; diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index 31ac2d715f..e83d10c093 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -3614,7 +3614,7 @@ void ModuleCompilationDatabaseCommandAction::operator()( cc->SetBacktrace(lfbt); cc->SetCommandLines(command_lines); - cc->SetWorkingDirectory(lg.GetBinaryDirectory().c_str()); + cc->SetWorkingDirectory(lg.GetBinaryDirectory()); cc->SetDependsExplicitOnly(true); cc->SetOutputs(this->Output); if (!inputs.empty()) { @@ -3646,7 +3646,7 @@ void ModuleCompilationDatabaseTargetAction::operator()( std::unique_ptr cc) { cc->SetBacktrace(lfbt); - cc->SetWorkingDirectory(lg.GetBinaryDirectory().c_str()); + cc->SetWorkingDirectory(lg.GetBinaryDirectory()); std::vector target_inputs; target_inputs.emplace_back(this->Output); cc->SetDepends(target_inputs); @@ -3698,7 +3698,7 @@ bool cmGlobalGenerator::AddBuildDatabaseTargets() static cm::static_string_view TargetPrefix = "cmake_build_database"_s; auto AddMergeTarget = - [&mf](std::string const& name, char const* comment, + [&mf](std::string const& name, std::string const& comment, std::string const& output, std::function()> inputs) { // Add the custom command. @@ -3732,13 +3732,13 @@ bool cmGlobalGenerator::AddBuildDatabaseTargets() lang, ".json"); mf->GetOrCreateGeneratedSource(output); AddMergeTarget( - cmStrCat(TargetPrefix, '-', lang), comment.c_str(), output, + cmStrCat(TargetPrefix, '-', lang), comment, output, [this, lang]() { return this->PerLanguageModuleDbs[lang]; }); all_lang_paths.emplace_back(std::move(output)); } // Add the overall target. - auto const* comment = "Combining module command databases"; + std::string comment{ "Combining module command databases" }; auto output = cmStrCat(mf->GetHomeOutputDirectory(), "/build_database.json"); mf->GetOrCreateGeneratedSource(output); @@ -3758,8 +3758,8 @@ bool cmGlobalGenerator::AddBuildDatabaseTargets() auto output = cmStrCat(mf->GetHomeOutputDirectory(), "/build_database_", lang, '_', config, ".json"); mf->GetOrCreateGeneratedSource(output); - AddMergeTarget(cmStrCat(TargetPrefix, '-', lang, '-', config), - comment.c_str(), output, [this, config, lang]() { + AddMergeTarget(cmStrCat(TargetPrefix, '-', lang, '-', config), comment, + output, [this, config, lang]() { return this->PerConfigModuleDbs[config][lang]; }); all_config_paths.emplace_back(std::move(output)); @@ -3770,8 +3770,8 @@ bool cmGlobalGenerator::AddBuildDatabaseTargets() auto output = cmStrCat(mf->GetHomeOutputDirectory(), "/build_database_", config, ".json"); mf->GetOrCreateGeneratedSource(output); - AddMergeTarget(cmStrCat(TargetPrefix, '-', config), comment.c_str(), - output, [all_config_paths]() { return all_config_paths; }); + AddMergeTarget(cmStrCat(TargetPrefix, '-', config), comment, output, + [all_config_paths]() { return all_config_paths; }); } // NMC considerations @@ -3783,13 +3783,13 @@ bool cmGlobalGenerator::AddBuildDatabaseTargets() lang, ".json"); mf->GetOrCreateGeneratedSource(output); AddMergeTarget( - cmStrCat(TargetPrefix, '-', lang), comment.c_str(), output, + cmStrCat(TargetPrefix, '-', lang), comment, output, [this, lang]() { return this->PerLanguageModuleDbs[lang]; }); all_config_paths.emplace_back(std::move(output)); } // Add the overall target. - auto const* comment = "Combining all module command databases"; + std::string comment{ "Combining all module command databases" }; auto output = cmStrCat(mf->GetHomeOutputDirectory(), "/build_database.json"); mf->GetOrCreateGeneratedSource(output); AddMergeTarget(std::string(TargetPrefix), comment, output, @@ -3844,7 +3844,7 @@ void cmGlobalGenerator::CreateGlobalTarget(GlobalTargetInfo const& gti, // Store the custom command in the target. cmCustomCommand cc; cc.SetCommandLines(gti.CommandLines); - cc.SetWorkingDirectory(gti.WorkingDir.c_str()); + cc.SetWorkingDirectory(gti.WorkingDir); cc.SetStdPipesUTF8(gti.StdPipesUTF8); cc.SetUsesTerminal(gti.UsesTerminal); cc.SetRole(gti.Role); diff --git a/Source/cmGlobalGhsMultiGenerator.cxx b/Source/cmGlobalGhsMultiGenerator.cxx index fe3f041337..d93d345445 100644 --- a/Source/cmGlobalGhsMultiGenerator.cxx +++ b/Source/cmGlobalGhsMultiGenerator.cxx @@ -9,6 +9,7 @@ #include #include +#include #include #include #include diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index 78d9cb1045..696a3e3ccb 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -829,7 +829,7 @@ void cmGlobalXCodeGenerator::AddExtraTargets( cc = cm::make_unique(); cc->SetCommandLines(legacyDependHelperCommandLines); cc->SetComment("Depend check for xcode"); - cc->SetWorkingDirectory(legacyDependHelperDir.c_str()); + cc->SetWorkingDirectory(legacyDependHelperDir); gen->AddCustomCommandToTarget( target->GetName(), cmCustomCommandType::POST_BUILD, std::move(cc), cmObjectLibraryCommands::Accept); diff --git a/Source/cmInstallCommand.cxx b/Source/cmInstallCommand.cxx index 89167ab544..33721d57d6 100644 --- a/Source/cmInstallCommand.cxx +++ b/Source/cmInstallCommand.cxx @@ -1016,7 +1016,7 @@ bool HandleTargetsMode(std::vector const& args, ArgumentParser::MaybeEmpty> PublicHeader; ArgumentParser::MaybeEmpty> Resource; ArgumentParser::MaybeEmpty> CxxModulesBmi; - std::vector> FileSets; + ArgumentParser::MaybeEmpty>> FileSets; }; static auto const argHelper = diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index cfb5d27090..3c06484fa1 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -3069,7 +3069,7 @@ void cmLocalGenerator::CopyPchCompilePdb( auto cc = cm::make_unique(); cc->SetCommandLines(commandLines); - cc->SetComment(comment.c_str()); + cc->SetComment(comment); cc->SetStdPipesUTF8(true); cc->AppendDepends( { reuseTarget->GetPchFile(config, language), copy_script }); diff --git a/Source/cmLocalVisualStudio7Generator.cxx b/Source/cmLocalVisualStudio7Generator.cxx index acc3ba6b78..d9a7cf77c6 100644 --- a/Source/cmLocalVisualStudio7Generator.cxx +++ b/Source/cmLocalVisualStudio7Generator.cxx @@ -272,7 +272,7 @@ cmSourceFile* cmLocalVisualStudio7Generator::CreateVCProjBuildRule() cc->SetMainDependency(makefileIn); cc->SetDepends(listFiles); cc->SetCommandLines(commandLines); - cc->SetComment(comment.c_str()); + cc->SetComment(comment); cc->SetEscapeOldStyle(false); cc->SetStdPipesUTF8(true); cc->SetUsesTerminal(true); diff --git a/Source/cmNinjaNormalTargetGenerator.cxx b/Source/cmNinjaNormalTargetGenerator.cxx index 53f8902e30..8a569188a3 100644 --- a/Source/cmNinjaNormalTargetGenerator.cxx +++ b/Source/cmNinjaNormalTargetGenerator.cxx @@ -1520,7 +1520,7 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement( true, config); localGen.AppendCustomCommandLines(ccg, *cmdLineLists[i]); if (cc.GetComment()) { - auto cge = ge.Parse(cc.GetComment()); + auto cge = ge.Parse(cc.GetComment().value()); cmdComments[i]->emplace_back( cge->Evaluate(this->GetLocalGenerator(), config)); } diff --git a/Source/cmNinjaUtilityTargetGenerator.cxx b/Source/cmNinjaUtilityTargetGenerator.cxx index 08d6019d12..e4f3b270a2 100644 --- a/Source/cmNinjaUtilityTargetGenerator.cxx +++ b/Source/cmNinjaUtilityTargetGenerator.cxx @@ -11,6 +11,8 @@ #include #include +#include + #include "cmCustomCommand.h" #include "cmCustomCommandGenerator.h" #include "cmGeneratedFileStream.h" @@ -96,7 +98,7 @@ void cmNinjaUtilityTargetGenerator::WriteUtilBuildStatements( if (!commandDesc.empty()) { commandDesc += "; "; } - auto cge = ge.Parse(ci.GetComment()); + auto cge = ge.Parse(ci.GetComment().value()); commandDesc += cge->Evaluate(this->GetLocalGenerator(), config); } util_outputs.Add(ccg.GetByproducts()); diff --git a/Source/cmPlaceholderExpander.cxx b/Source/cmPlaceholderExpander.cxx index aea427b681..54b0686d97 100644 --- a/Source/cmPlaceholderExpander.cxx +++ b/Source/cmPlaceholderExpander.cxx @@ -4,7 +4,8 @@ #include "cmsys/String.h" -std::string& cmPlaceholderExpander::ExpandVariables(std::string& s) +std::string& cmPlaceholderExpander::ExpandVariables(std::string& s, + HandleGenex handleGenex) { std::string::size_type start = s.find('<'); // no variables to expand @@ -14,6 +15,13 @@ std::string& cmPlaceholderExpander::ExpandVariables(std::string& s) std::string::size_type pos = 0; std::string expandedInput; while (start != std::string::npos && start < s.size() - 2) { + if (handleGenex == HandleGenex::Yes && start != 0 && s[start - 1] == '$') { + // this is a generator expression + // skip it and try to find the next < in the string + start = s.find('<', start + 1); + continue; + } + std::string::size_type end = s.find('>', start); // if we find a < with no > we are done if (end == std::string::npos) { diff --git a/Source/cmPlaceholderExpander.h b/Source/cmPlaceholderExpander.h index 3a4b1bc376..7c54ef60a1 100644 --- a/Source/cmPlaceholderExpander.h +++ b/Source/cmPlaceholderExpander.h @@ -10,9 +10,16 @@ class cmPlaceholderExpander { public: + enum class HandleGenex + { + No, + Yes + }; + virtual ~cmPlaceholderExpander() = default; - std::string& ExpandVariables(std::string& string); + std::string& ExpandVariables(std::string& string, + HandleGenex handleGenex = HandleGenex::No); protected: virtual std::string ExpandVariable(std::string const& variable) = 0; diff --git a/Source/cmQTWrapCPPCommand.cxx b/Source/cmQTWrapCPPCommand.cxx index d1dcb7619b..26dafebd0a 100644 --- a/Source/cmQTWrapCPPCommand.cxx +++ b/Source/cmQTWrapCPPCommand.cxx @@ -5,6 +5,7 @@ #include #include +#include #include #include "cmCustomCommand.h" diff --git a/Source/cmQtAutoGenGlobalInitializer.cxx b/Source/cmQtAutoGenGlobalInitializer.cxx index a992123ad3..b9172befe9 100644 --- a/Source/cmQtAutoGenGlobalInitializer.cxx +++ b/Source/cmQtAutoGenGlobalInitializer.cxx @@ -6,6 +6,7 @@ #include #include +#include #include "cmCustomCommand.h" #include "cmDiagnostics.h" @@ -171,9 +172,9 @@ void cmQtAutoGenGlobalInitializer::GetOrCreateGlobalTarget( // Create utility target auto cc = cm::make_unique(); - cc->SetWorkingDirectory(makefile->GetHomeOutputDirectory().c_str()); + cc->SetWorkingDirectory(makefile->GetHomeOutputDirectory()); cc->SetEscapeOldStyle(false); - cc->SetComment(comment.c_str()); + cc->SetComment(comment); cmTarget* target = localGen->AddUtilityCommand(name, true, std::move(cc)); localGen->AddGeneratorTarget( cm::make_unique(target, localGen)); diff --git a/Source/cmQtAutoGenInitializer.cxx b/Source/cmQtAutoGenInitializer.cxx index e24bd38735..afd68328a2 100644 --- a/Source/cmQtAutoGenInitializer.cxx +++ b/Source/cmQtAutoGenInitializer.cxx @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -1593,7 +1594,7 @@ bool cmQtAutoGenInitializer::InitAutogenTarget() cc->SetOutputs(timestampFileGenex); cc->SetDepends(uicDependencies); cc->SetComment(""); - cc->SetWorkingDirectory(this->Dir.Work.c_str()); + cc->SetWorkingDirectory(this->Dir.Work); cc->SetEscapeOldStyle(false); cc->SetStdPipesUTF8(stdPipesUTF8); this->LocalGen->AddCustomCommandToOutput(std::move(cc)); @@ -1607,9 +1608,9 @@ bool cmQtAutoGenInitializer::InitAutogenTarget() cmCustomCommand cc; cc.SetByproducts(autogenByproducts); cc.SetCommandLines(commandLines); - cc.SetComment(autogenComment.c_str()); + cc.SetComment(autogenComment); cc.SetBacktrace(this->Makefile->GetBacktrace()); - cc.SetWorkingDirectory(this->Dir.Work.c_str()); + cc.SetWorkingDirectory(this->Dir.Work); cc.SetStdPipesUTF8(stdPipesUTF8); cc.SetEscapeOldStyle(false); cc.SetEscapeAllowMakeVars(true); @@ -1671,7 +1672,7 @@ bool cmQtAutoGenInitializer::InitAutogenTarget() cmStrCat(this->GenTarget->GetName(), "_autogen_timestamp_deps"); auto cc = cm::make_unique(); - cc->SetWorkingDirectory(this->Dir.Work.c_str()); + cc->SetWorkingDirectory(this->Dir.Work); cc->SetDepends(dependencies); cc->SetEscapeOldStyle(false); timestampTarget = this->LocalGen->AddUtilityCommand( @@ -1742,8 +1743,8 @@ bool cmQtAutoGenInitializer::InitAutogenTarget() cc->SetByproducts(timestampByproducts); cc->SetDepends(dependencies); cc->SetCommandLines(commandLines); - cc->SetComment(autogenComment.c_str()); - cc->SetWorkingDirectory(this->Dir.Work.c_str()); + cc->SetComment(autogenComment); + cc->SetWorkingDirectory(this->Dir.Work); cc->SetEscapeOldStyle(false); cc->SetDepfile(depFile); cc->SetStdPipesUTF8(stdPipesUTF8); @@ -1763,12 +1764,12 @@ bool cmQtAutoGenInitializer::InitAutogenTarget() } else { // Create autogen target auto cc = cm::make_unique(); - cc->SetWorkingDirectory(this->Dir.Work.c_str()); + cc->SetWorkingDirectory(this->Dir.Work); cc->SetByproducts(autogenByproducts); cc->SetDepends(dependencies); cc->SetCommandLines(commandLines); cc->SetEscapeOldStyle(false); - cc->SetComment(autogenComment.c_str()); + cc->SetComment(autogenComment); cmTarget* autogenTarget = this->LocalGen->AddUtilityCommand( this->AutogenTarget.Name, true, std::move(cc)); // Create autogen generator target @@ -1878,9 +1879,9 @@ bool cmQtAutoGenInitializer::InitRccTargets() FileProjectRelativePath(this->Makefile, qrc.QrcFile)); auto cc = cm::make_unique(); - cc->SetWorkingDirectory(this->Dir.Work.c_str()); + cc->SetWorkingDirectory(this->Dir.Work); cc->SetCommandLines(commandLines); - cc->SetComment(ccComment.c_str()); + cc->SetComment(ccComment); cc->SetStdPipesUTF8(true); if (qrc.Generated || this->Rcc.GlobalTarget) { diff --git a/Source/cmSourceFile.cxx b/Source/cmSourceFile.cxx index 6ee095af83..04220e3a3b 100644 --- a/Source/cmSourceFile.cxx +++ b/Source/cmSourceFile.cxx @@ -49,8 +49,6 @@ std::string const& cmSourceFile::GetExtension() const return this->Extension; } -std::string const propTRUE = "1"; -std::string const propFALSE = "0"; std::string const cmSourceFile::propLANGUAGE = "LANGUAGE"; std::string const cmSourceFile::propLOCATION = "LOCATION"; std::string const cmSourceFile::propGENERATED = "GENERATED"; @@ -387,9 +385,9 @@ cmValue cmSourceFile::GetPropertyForUser(std::string const& prop) (cmp0118 != cmPolicies::OLD && cmp0118 != cmPolicies::WARN); if (this->GetIsGenerated((!cmp0118new) ? CheckScope::GlobalAndLocal : CheckScope::Global)) { - return cmValue(propTRUE); + return cmValue::True; } - return cmValue(propFALSE); + return cmValue::False; } // Perform the normal property lookup. diff --git a/Source/cmSourceFilePropertyHelper.cxx b/Source/cmSourceFilePropertyHelper.cxx index 0df2d8bf74..1c33f4f662 100644 --- a/Source/cmSourceFilePropertyHelper.cxx +++ b/Source/cmSourceFilePropertyHelper.cxx @@ -14,9 +14,9 @@ #include "cmSystemTools.h" #include "cmValue.h" -static bool GetSourceFilePropertyGENERATED(std::string const& name, - cmMakefile& mf, - cmValue& propertyValue) +namespace { +bool GetSourceFilePropertyGENERATED(std::string const& name, cmMakefile& mf, + cmValue& propertyValue) { // Globally set as generated? // Note: If the given "name" only contains a filename or a relative path @@ -26,13 +26,11 @@ static bool GetSourceFilePropertyGENERATED(std::string const& name, // generated in the build-directory. Therefore, we first check for // a generated file in the build-directory before we check for a // generated file in the source-directory. - static std::string const sOne = "1"; - static std::string const sZero = "0"; { auto file = cmSystemTools::CollapseFullPath(name, mf.GetCurrentBinaryDirectory()); if (mf.GetGlobalGenerator()->IsGeneratedFile(file)) { - propertyValue = cmValue(sOne); + propertyValue = cmValue::True; return true; } } @@ -40,13 +38,14 @@ static bool GetSourceFilePropertyGENERATED(std::string const& name, auto file = cmSystemTools::CollapseFullPath(name, mf.GetCurrentSourceDirectory()); if (mf.GetGlobalGenerator()->IsGeneratedFile(file)) { - propertyValue = cmValue(sOne); + propertyValue = cmValue::True; return true; } } - propertyValue = cmValue(sZero); + propertyValue = cmValue::False; return true; } +} cmGetSourceFilePropertyResult cmGetSourceFileProperty( std::string const& sourceName, std::string const& propertyName, diff --git a/Source/cmTargetSourcesCommand.cxx b/Source/cmTargetSourcesCommand.cxx index 146262438e..5d178268c7 100644 --- a/Source/cmTargetSourcesCommand.cxx +++ b/Source/cmTargetSourcesCommand.cxx @@ -42,7 +42,7 @@ auto const FileSetArgsParser = cmArgumentParser() struct FileSetsArgs { - std::vector> FileSets; + ArgumentParser::MaybeEmpty>> FileSets; }; auto const FileSetsArgsParser = diff --git a/Source/cmValue.cxx b/Source/cmValue.cxx index 83d18b32c5..bc40371973 100644 --- a/Source/cmValue.cxx +++ b/Source/cmValue.cxx @@ -8,6 +8,14 @@ #include "cmStringAlgorithms.h" +namespace { +std::string True{ "1" }; +std::string False{ "0" }; +} + +cmValue cmValue::True{ ::True }; +cmValue cmValue::False{ ::False }; + std::string cmValue::Empty; bool cmValue::IsOn(cm::string_view value) noexcept diff --git a/Source/cmValue.h b/Source/cmValue.h index 9151a29222..58edd54b31 100644 --- a/Source/cmValue.h +++ b/Source/cmValue.h @@ -13,6 +13,9 @@ class cmValue { public: + static cmValue True; + static cmValue False; + cmValue() noexcept = default; cmValue(std::nullptr_t) noexcept {} explicit cmValue(std::string const* value) noexcept diff --git a/Tests/CMakeLib/testArgumentParser.cxx b/Tests/CMakeLib/testArgumentParser.cxx index 176211de55..7d714746cd 100644 --- a/Tests/CMakeLib/testArgumentParser.cxx +++ b/Tests/CMakeLib/testArgumentParser.cxx @@ -45,10 +45,14 @@ struct Result : ArgumentParser::ParseResult cm::optional>> List5; cm::optional>> List6; - std::vector> Multi1; - std::vector> Multi2; - cm::optional>> Multi3; - cm::optional>> Multi4; + ArgumentParser::MaybeEmpty>> Multi1; + ArgumentParser::MaybeEmpty>> Multi2; + cm::optional< + ArgumentParser::MaybeEmpty>>> + Multi3; + cm::optional< + ArgumentParser::MaybeEmpty>>> + Multi4; cm::optional Pos0; cm::optional Pos1;