From a1b9465bf85621f80f02b9903aa7b38a74676df1 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Mon, 4 Nov 2013 10:51:37 +0100 Subject: Automoc: Add directory-level COMPILE_DEFINITIONS to command line (#14535) In commit 18412153 (Refactor cmTarget::GetCompileDefinitions..., 2013-06-06) cmQtAutomoc was refactored to get all compile definitions from the target instead of separately asking the target and querying the directory-level COMPILE_DEFINITIONS property value. While the generation process does integrate directory-level COMPILE_DEFINITIONS into the target definitions, this did not happen until after Automoc targets are constructed. Therefore the commit regressed use of directory-level definitions in Automoc targets. Factor the definition finalization logic out from the cmGlobalGenerator::CreateGeneratorTargets method into a new cmGlobalGenerator::FinalizeTargetCompileDefinitions method and call it before constructing Automoc targets. This will place the directory-level definitions into the target in time to use them for the Automoc targets. Extend the QtAutomoc test to cover this case. --- Source/cmGlobalGenerator.cxx | 24 ++++++++++++++++++++---- Source/cmGlobalGenerator.h | 1 + Tests/QtAutomoc/foo.h | 5 ++++- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index 7f2b592..f940c9e 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -956,6 +956,8 @@ void cmGlobalGenerator::Generate() return; } + this->FinalizeTargetCompileDefinitions(); + // Iterate through all targets and set up automoc for those which have // the AUTOMOC property set this->CreateAutomocTargets(); @@ -1140,13 +1142,11 @@ void cmGlobalGenerator::CreateAutomocTargets() } //---------------------------------------------------------------------------- -void cmGlobalGenerator::CreateGeneratorTargets() +void cmGlobalGenerator::FinalizeTargetCompileDefinitions() { // Construct per-target generator information. for(unsigned int i=0; i < this->LocalGenerators.size(); ++i) { - cmGeneratorTargetsType generatorTargets; - cmMakefile *mf = this->LocalGenerators[i]->GetMakefile(); const std::vector noconfig_compile_definitions = @@ -1161,7 +1161,6 @@ void cmGlobalGenerator::CreateGeneratorTargets() { cmTarget* t = &ti->second; - { for (std::vector::const_iterator it = noconfig_compile_definitions.begin(); it != noconfig_compile_definitions.end(); ++it) @@ -1178,7 +1177,24 @@ void cmGlobalGenerator::CreateGeneratorTargets() mf->GetProperty(defPropName.c_str())); } } + } +} + +//---------------------------------------------------------------------------- +void cmGlobalGenerator::CreateGeneratorTargets() +{ + // Construct per-target generator information. + for(unsigned int i=0; i < this->LocalGenerators.size(); ++i) + { + cmGeneratorTargetsType generatorTargets; + + cmMakefile *mf = this->LocalGenerators[i]->GetMakefile(); + cmTargets& targets = mf->GetTargets(); + for(cmTargets::iterator ti = targets.begin(); + ti != targets.end(); ++ti) + { + cmTarget* t = &ti->second; cmGeneratorTarget* gt = new cmGeneratorTarget(t); this->GeneratorTargets[t] = gt; this->ComputeTargetObjects(gt); diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h index 18aba24..80916ae 100644 --- a/Source/cmGlobalGenerator.h +++ b/Source/cmGlobalGenerator.h @@ -382,6 +382,7 @@ private: void WriteSummary(); void WriteSummary(cmTarget* target); + void FinalizeTargetCompileDefinitions(); cmExternalMakefileProjectGenerator* ExtraGenerator; diff --git a/Tests/QtAutomoc/foo.h b/Tests/QtAutomoc/foo.h index 32d4c8d..f23ec07 100644 --- a/Tests/QtAutomoc/foo.h +++ b/Tests/QtAutomoc/foo.h @@ -16,7 +16,10 @@ #include -class Foo : public QObject +class Foo +#ifdef FOO + : public QObject +#endif { Q_OBJECT public: -- cgit v0.12