cmMakefile: Introduce GeneratorAction as the class.

This commit is contained in:
NAKAMURA Takumi
2021-11-14 10:19:28 +09:00
committed by Brad King
parent 9b31a97748
commit 90e1206f25
2 changed files with 32 additions and 5 deletions

View File

@@ -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<GeneratorAction>& action : this->GeneratorActions) {
for (auto& action : this->GeneratorActions) {
action.Value(lg, action.Backtrace);
}
this->GeneratorActionsInvoked = true;

View File

@@ -140,13 +140,34 @@ public:
bool EnforceUniqueName(std::string const& name, std::string& msg,
bool isCustom = false) const;
using GeneratorAction =
std::function<void(cmLocalGenerator&, const cmListFileBacktrace&)>;
class GeneratorAction
{
using ActionT =
std::function<void(cmLocalGenerator&, const cmListFileBacktrace&)>;
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 <class... Args>
void AddGeneratorAction(Args&&... args)
{
AddGeneratorAction(GeneratorAction(std::move(args)...));
}
/**
* Perform generate actions, Library dependency analysis etc before output of