mirror of
https://github.com/Kitware/CMake.git
synced 2026-11-06 05:16:58 +00:00
Custom rule: ensure user's callbacks are executed during config step
This commit is contained in:
1 parent
efd3f3450e
commit
ccc15ac21c
5 files changed
+68
-69
No files matched your search
@@ -178,9 +178,9 @@ Generating Files
|
||||
usually emitted by the custom command itself.
|
||||
|
||||
``CONFIGURATOR``
|
||||
Specify one or two CMake functions which will be called at the generation
|
||||
step, in the context of the file set directory, before the effective
|
||||
instantiation and custom commands definition.
|
||||
Specify one or two CMake functions which will be called at the
|
||||
configuration step, in the context of the file set directory, before the
|
||||
effective instantiation and custom commands definition.
|
||||
|
||||
.. note::
|
||||
|
||||
@@ -314,8 +314,9 @@ Derived Rule
|
||||
Specify the rule from which this new rule will inherit.
|
||||
|
||||
``CONFIGURATOR``
|
||||
Specify one or two CMake functions which will be called at the generation
|
||||
step before the effective instantiation and custom commands definition.
|
||||
Specify one or two CMake functions which will be called at the
|
||||
configuration step, in the context of the file set directory, before the
|
||||
effective instantiation and custom commands definition.
|
||||
|
||||
.. note::
|
||||
|
||||
|
||||
@@ -1544,6 +1544,8 @@ void cmGlobalGenerator::Configure()
|
||||
|
||||
this->ReserveGlobalTargetCodegen();
|
||||
|
||||
this->ConfigureRules();
|
||||
|
||||
// update the cache entry for the number of local generators, this is used
|
||||
// for progress
|
||||
this->GetCMakeInstance()->AddCacheEntry(
|
||||
@@ -1555,8 +1557,6 @@ void cmGlobalGenerator::CreateGenerationObjects(TargetTypes targetTypes)
|
||||
{
|
||||
this->CreateLocalGenerators();
|
||||
|
||||
this->CreateCustomCommandsFromRules();
|
||||
|
||||
// Commit side effects only if we are actually generating
|
||||
if (targetTypes == TargetTypes::AllTargets) {
|
||||
this->CheckTargetProperties();
|
||||
@@ -2335,58 +2335,6 @@ cmGlobalGenerator::CreateMSVC60LinkLineComputer(
|
||||
cm::make_unique<cmMSVC60LinkLineComputer>(outputConverter, stateDir));
|
||||
}
|
||||
|
||||
void cmGlobalGenerator::CreateCustomCommandsFromRules()
|
||||
{
|
||||
for (unsigned int i = 0; i < this->LocalGenerators.size(); ++i) {
|
||||
cmMakefile* mf = this->Makefiles[i].get();
|
||||
cmLocalGenerator* lg = this->LocalGenerators[i].get();
|
||||
for (auto& item : mf->GetTargets()) {
|
||||
cmTarget& target = item.second;
|
||||
for (auto const& fsName : target.GetAllFileSetNames(
|
||||
cm::FileSetMetadata::FileSetDomain::RULE)) {
|
||||
cmFileSet const* fileSet = target.GetFileSet(fsName);
|
||||
cmRule const* rule =
|
||||
fileSet->GetMakefile()->FindRuleToUse(fileSet->GetType());
|
||||
if (!rule) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// generated files by the custom command are stored in a file set
|
||||
cmFileSet* outFileSet = rule->GetOutputFileSet(&target, fileSet);
|
||||
if (!outFileSet) {
|
||||
continue;
|
||||
}
|
||||
|
||||
cmRule::PatternSet fileSetPatterns;
|
||||
if (!rule->Instantiate(&target, fileSet, outFileSet,
|
||||
fileSetPatterns)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (auto const& files : fileSet->GetFileEntries()) {
|
||||
for (auto const& file :
|
||||
cmList{ cm::remove_BT(files), cmList::EmptyElements::No }) {
|
||||
cmSourceFile* source = mf->GetOrCreateSource(file);
|
||||
source->ResolveFullPath();
|
||||
|
||||
cmRule::PatternSet sourcePatterns{ fileSetPatterns };
|
||||
if (!rule->Instantiate(&target, fileSet, outFileSet, source,
|
||||
sourcePatterns)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
auto genRule = cm::make_unique<cmGeneratorRule>(
|
||||
rule, &target, fileSet, outFileSet, source, sourcePatterns);
|
||||
auto cc = genRule->Generate(outFileSet);
|
||||
lg->AddGeneratorRule(std::move(genRule));
|
||||
mf->AddCustomCommandToOutput(std::move(cc));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void cmGlobalGenerator::FinalizeTargetConfiguration()
|
||||
{
|
||||
std::vector<std::string> const langs =
|
||||
@@ -3905,6 +3853,61 @@ void cmGlobalGenerator::ReserveGlobalTargetCodegen()
|
||||
}
|
||||
}
|
||||
|
||||
void cmGlobalGenerator::ConfigureRules()
|
||||
{
|
||||
for (auto const& mf : this->Makefiles) {
|
||||
for (auto& item : mf->GetTargets()) {
|
||||
cmTarget& target = item.second;
|
||||
for (auto const& fsName : target.GetAllFileSetNames(
|
||||
cm::FileSetMetadata::FileSetDomain::RULE)) {
|
||||
cmFileSet const* fileSet = target.GetFileSet(fsName);
|
||||
cmRule const* rule =
|
||||
fileSet->GetMakefile()->FindRuleToUse(fileSet->GetType());
|
||||
if (!rule) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// generated files by the custom command are stored in a file set
|
||||
cmFileSet* outFileSet = rule->GetOutputFileSet(&target, fileSet);
|
||||
if (!outFileSet) {
|
||||
continue;
|
||||
}
|
||||
|
||||
cmRule::PatternSet fileSetPatterns;
|
||||
if (!rule->Instantiate(&target, fileSet, outFileSet,
|
||||
fileSetPatterns)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (auto const& files : fileSet->GetFileEntries()) {
|
||||
for (auto const& file :
|
||||
cmList{ cm::remove_BT(files), cmList::EmptyElements::No }) {
|
||||
cmSourceFile* source = mf->GetOrCreateSource(file);
|
||||
source->ResolveFullPath();
|
||||
|
||||
cmRule::PatternSet sourcePatterns{ fileSetPatterns };
|
||||
if (!rule->Instantiate(&target, fileSet, outFileSet, source,
|
||||
sourcePatterns)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
mf->AddGeneratorAction(
|
||||
[rule, &target, fileSet, outFileSet, source, sourcePatterns](
|
||||
cmLocalGenerator& lg, cmListFileBacktrace const&) {
|
||||
auto genRule = cm::make_unique<cmGeneratorRule>(
|
||||
rule, &target, fileSet, outFileSet, source, sourcePatterns);
|
||||
auto cc = genRule->Generate(outFileSet);
|
||||
lg.AddGeneratorRule(std::move(genRule));
|
||||
detail::AddCustomCommandToOutput(
|
||||
lg, cmCommandOrigin::Generator, std::move(cc), false);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool cmGlobalGenerator::CheckCMP0171() const
|
||||
{
|
||||
return this->AllowGlobalTargetCodegen;
|
||||
|
||||
@@ -227,9 +227,6 @@ public:
|
||||
|
||||
virtual bool InspectConfigTypeVariables() { return true; }
|
||||
|
||||
// Produce custom commands for file sets attached to a custom rule
|
||||
void CreateCustomCommandsFromRules();
|
||||
|
||||
enum class CxxModuleSupportQuery
|
||||
{
|
||||
// Support is expected at the call site.
|
||||
@@ -940,6 +937,10 @@ protected:
|
||||
|
||||
void ReserveGlobalTargetCodegen();
|
||||
|
||||
// Execute user's callbacks and produce custom commands for file sets
|
||||
// attached to a custom rule
|
||||
void ConfigureRules();
|
||||
|
||||
std::string FindMakeProgramFile;
|
||||
std::string ConfiguredFilesPath;
|
||||
cmake* CMakeInstance;
|
||||
|
||||
@@ -20,9 +20,3 @@ Call Stack \(most recent call first\):
|
||||
CMake Error in CMakeLists\.txt:
|
||||
Erroneous execution of the CONFIGURATOR "configurator2", from the RULE
|
||||
"foo2", for the FILE_SET "fs2" of TARGET "foo"\.
|
||||
|
||||
|
||||
CMake Error at RuleProperties2\.cmake:[0-9]+ \(add_library\):
|
||||
No SOURCES given to target: foo
|
||||
Call Stack \(most recent call first\):
|
||||
CMakeLists\.txt:[0-9]+ \(include\)
|
||||
@@ -1,4 +1,4 @@
|
||||
CMake Error in CMakeLists\.txt:
|
||||
CMake Error:
|
||||
Error evaluating generator expression:
|
||||
|
||||
\$<RULE_PROPERTY:foo_[0-9]+,COMPILE_OPTIONS>
|
||||
|
||||
Reference in new issue
Block a user