From 90e1206f253c0acbef37668403133585a31b2a92 Mon Sep 17 00:00:00 2001 From: NAKAMURA Takumi Date: Sun, 14 Nov 2021 10:19:28 +0900 Subject: cmMakefile: Introduce GeneratorAction as the class. --- Source/cmMakefile.cxx | 10 ++++++++-- Source/cmMakefile.h | 27 ++++++++++++++++++++++++--- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index e376323..e84e474 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -891,12 +891,18 @@ struct file_not_persistent }; } -void cmMakefile::AddGeneratorAction(GeneratorAction action) +void cmMakefile::AddGeneratorAction(GeneratorAction&& action) { assert(!this->GeneratorActionsInvoked); this->GeneratorActions.emplace_back(std::move(action), this->Backtrace); } +void cmMakefile::GeneratorAction::operator()(cmLocalGenerator& lg, + const cmListFileBacktrace& lfbt) +{ + Action(lg, lfbt); +} + void cmMakefile::DoGenerate(cmLocalGenerator& lg) { // do all the variable expansions here @@ -904,7 +910,7 @@ void cmMakefile::DoGenerate(cmLocalGenerator& lg) // give all the commands a chance to do something // after the file has been parsed before generation - for (const BT& action : this->GeneratorActions) { + for (auto& action : this->GeneratorActions) { action.Value(lg, action.Backtrace); } this->GeneratorActionsInvoked = true; diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index c29fb00..75412d7 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -140,13 +140,34 @@ public: bool EnforceUniqueName(std::string const& name, std::string& msg, bool isCustom = false) const; - using GeneratorAction = - std::function; + class GeneratorAction + { + using ActionT = + std::function; + + public: + GeneratorAction(ActionT&& action) + : Action(std::move(action)) + { + } + + void operator()(cmLocalGenerator& lg, const cmListFileBacktrace& lfbt); + + private: + ActionT Action; + }; /** * Register an action that is executed during Generate */ - void AddGeneratorAction(GeneratorAction action); + void AddGeneratorAction(GeneratorAction&& action); + + /// Helper to insert the constructor GeneratorAction(args...) + template + void AddGeneratorAction(Args&&... args) + { + AddGeneratorAction(GeneratorAction(std::move(args)...)); + } /** * Perform generate actions, Library dependency analysis etc before output of -- cgit v0.12