From 20a234d1b8d41852bdf401ee6484b1d0e877c7c4 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Mon, 4 Nov 2013 10:25:08 +0100 Subject: cmAutogen: Extract some helper methods for autogen targets. These snippets will soon be needed from multiple methods. --- Source/cmQtAutoGenerators.cxx | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx index 5f7a26f..dcd0300 100644 --- a/Source/cmQtAutoGenerators.cxx +++ b/Source/cmQtAutoGenerators.cxx @@ -138,6 +138,24 @@ cmQtAutoGenerators::cmQtAutoGenerators() } } +static std::string getAutogenTargetName(cmTarget *target) +{ + std::string autogenTargetName = target->GetName(); + autogenTargetName += "_automoc"; + return autogenTargetName; +} + +static std::string getAutogenTargetDir(cmTarget *target) +{ + cmMakefile* makefile = target->GetMakefile(); + std::string targetDir = makefile->GetCurrentOutputDirectory(); + targetDir += makefile->GetCMakeInstance()->GetCMakeFilesDirectory(); + targetDir += "/"; + targetDir += getAutogenTargetName(target); + targetDir += ".dir/"; + return targetDir; +} + bool cmQtAutoGenerators::InitializeMocSourceFile(cmTarget* target) { cmMakefile* makefile = target->GetMakefile(); @@ -154,8 +172,7 @@ bool cmQtAutoGenerators::InitializeMocSourceFile(cmTarget* target) if (target->GetPropertyAsBool("AUTOMOC")) { - std::string automocTargetName = target->GetName(); - automocTargetName += "_automoc"; + std::string automocTargetName = getAutogenTargetName(target); std::string mocCppFile = makefile->GetCurrentOutputDirectory(); mocCppFile += "/"; mocCppFile += automocTargetName; @@ -232,17 +249,12 @@ void cmQtAutoGenerators::SetupAutoGenerateTarget(cmTarget* target) makefile->AddDefinition("_target_qt_version", qtVersion); } // create a custom target for running generators at buildtime: - std::string autogenTargetName = targetName; - autogenTargetName += "_automoc"; + std::string autogenTargetName = getAutogenTargetName(target); makefile->AddDefinition("_moc_target_name", cmLocalGenerator::EscapeForCMake(autogenTargetName.c_str()).c_str()); - std::string targetDir = makefile->GetCurrentOutputDirectory(); - targetDir += makefile->GetCMakeInstance()->GetCMakeFilesDirectory(); - targetDir += "/"; - targetDir += autogenTargetName; - targetDir += ".dir/"; + std::string targetDir = getAutogenTargetDir(target); cmCustomCommandLine currentLine; currentLine.push_back(makefile->GetSafeDefinition("CMAKE_COMMAND")); -- cgit v0.12 From 45735f38275ad4d13e801ba41e7565bcfd5a0f0a Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Mon, 4 Nov 2013 10:29:21 +0100 Subject: cmAutogen: Move autogen target creation to InitializeMocSourceFile. The SetupAutoGenerateTarget method will soon be invoked at a later time in a followup commit. We need to ensure that we create the utility autogen target early. --- Source/cmQtAutoGenerators.cxx | 139 ++++++++++++++++++++++-------------------- 1 file changed, 72 insertions(+), 67 deletions(-) diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx index dcd0300..e07f7b4 100644 --- a/Source/cmQtAutoGenerators.cxx +++ b/Source/cmQtAutoGenerators.cxx @@ -185,75 +185,9 @@ bool cmQtAutoGenerators::InitializeMocSourceFile(cmTarget* target) target->AddSourceFile(mocCppSource); } - return true; -} - -static void GetCompileDefinitionsAndDirectories(cmTarget *target, - const char * config, - std::string &incs, - std::string &defs) -{ - cmMakefile* makefile = target->GetMakefile(); - cmLocalGenerator* localGen = makefile->GetLocalGenerator(); - std::vector includeDirs; - cmGeneratorTarget gtgt(target); - // Get the include dirs for this target, without stripping the implicit - // include dirs off, see http://public.kitware.com/Bug/view.php?id=13667 - localGen->GetIncludeDirectories(includeDirs, >gt, "CXX", config, false); - const char* sep = ""; - incs = ""; - for(std::vector::const_iterator incDirIt = includeDirs.begin(); - incDirIt != includeDirs.end(); - ++incDirIt) - { - incs += sep; - sep = ";"; - incs += *incDirIt; - } - - std::set defines; - localGen->AddCompileDefinitions(defines, target, config); - - sep = ""; - for(std::set::const_iterator defIt = defines.begin(); - defIt != defines.end(); - ++defIt) - { - defs += sep; - sep = ";"; - defs += *defIt; - } -} - -void cmQtAutoGenerators::SetupAutoGenerateTarget(cmTarget* target) -{ - cmMakefile* makefile = target->GetMakefile(); - const char* targetName = target->GetName(); - - // forget the variables added here afterwards again: - cmMakefile::ScopePushPop varScope(makefile); - static_cast(varScope); - - const char *qtVersion = makefile->GetDefinition("Qt5Core_VERSION_MAJOR"); - if (!qtVersion) - { - qtVersion = makefile->GetDefinition("QT_VERSION_MAJOR"); - } - if (const char *targetQtVersion = - target->GetLinkInterfaceDependentStringProperty("QT_MAJOR_VERSION", 0)) - { - qtVersion = targetQtVersion; - } - if (qtVersion) - { - makefile->AddDefinition("_target_qt_version", qtVersion); - } // create a custom target for running generators at buildtime: std::string autogenTargetName = getAutogenTargetName(target); - makefile->AddDefinition("_moc_target_name", - cmLocalGenerator::EscapeForCMake(autogenTargetName.c_str()).c_str()); - std::string targetDir = getAutogenTargetDir(target); cmCustomCommandLine currentLine; @@ -296,7 +230,7 @@ void cmQtAutoGenerators::SetupAutoGenerateTarget(cmTarget* target) tools += " and " + toolNames[0]; } std::string autogenComment = "Automatic " + tools + " for target "; - autogenComment += targetName; + autogenComment += target->GetName(); #if defined(_WIN32) && !defined(__CYGWIN__) bool usePRE_BUILD = false; @@ -353,6 +287,77 @@ void cmQtAutoGenerators::SetupAutoGenerateTarget(cmTarget* target) target->AddUtility(autogenTargetName.c_str()); } + return true; +} + +static void GetCompileDefinitionsAndDirectories(cmTarget *target, + const char * config, + std::string &incs, + std::string &defs) +{ + cmMakefile* makefile = target->GetMakefile(); + cmLocalGenerator* localGen = makefile->GetLocalGenerator(); + std::vector includeDirs; + cmGeneratorTarget gtgt(target); + // Get the include dirs for this target, without stripping the implicit + // include dirs off, see http://public.kitware.com/Bug/view.php?id=13667 + localGen->GetIncludeDirectories(includeDirs, >gt, "CXX", config, false); + const char* sep = ""; + incs = ""; + for(std::vector::const_iterator incDirIt = includeDirs.begin(); + incDirIt != includeDirs.end(); + ++incDirIt) + { + incs += sep; + sep = ";"; + incs += *incDirIt; + } + + std::set defines; + localGen->AddCompileDefinitions(defines, target, config); + + sep = ""; + for(std::set::const_iterator defIt = defines.begin(); + defIt != defines.end(); + ++defIt) + { + defs += sep; + sep = ";"; + defs += *defIt; + } +} + +void cmQtAutoGenerators::SetupAutoGenerateTarget(cmTarget* target) +{ + cmMakefile* makefile = target->GetMakefile(); + + // forget the variables added here afterwards again: + cmMakefile::ScopePushPop varScope(makefile); + static_cast(varScope); + + // create a custom target for running generators at buildtime: + std::string autogenTargetName = getAutogenTargetName(target); + + makefile->AddDefinition("_moc_target_name", + cmLocalGenerator::EscapeForCMake(autogenTargetName.c_str()).c_str()); + + std::string targetDir = getAutogenTargetDir(target); + + const char *qtVersion = makefile->GetDefinition("Qt5Core_VERSION_MAJOR"); + if (!qtVersion) + { + qtVersion = makefile->GetDefinition("QT_VERSION_MAJOR"); + } + if (const char *targetQtVersion = + target->GetLinkInterfaceDependentStringProperty("QT_MAJOR_VERSION", 0)) + { + qtVersion = targetQtVersion; + } + if (qtVersion) + { + makefile->AddDefinition("_target_qt_version", qtVersion); + } + std::map configIncludes; std::map configDefines; -- cgit v0.12 From d2f4b1e3cf934eab02282ee312408601d6756a31 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Mon, 4 Nov 2013 10:32:27 +0100 Subject: cmAutogen: Rename method to InitializeAutogenTarget This reflects better what it is doing. --- Source/cmGlobalGenerator.cxx | 2 +- Source/cmQtAutoGenerators.cxx | 2 +- Source/cmQtAutoGenerators.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index ea17afa..b6f491a 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -1291,7 +1291,7 @@ void cmGlobalGenerator::CreateQtAutoGeneratorsTargets() && !target.IsImported()) { cmQtAutoGenerators autogen; - if(autogen.InitializeMocSourceFile(&target)) + if(autogen.InitializeAutogenTarget(&target)) { autogens.push_back(std::make_pair(autogen, &target)); } diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx index e07f7b4..36cb368 100644 --- a/Source/cmQtAutoGenerators.cxx +++ b/Source/cmQtAutoGenerators.cxx @@ -156,7 +156,7 @@ static std::string getAutogenTargetDir(cmTarget *target) return targetDir; } -bool cmQtAutoGenerators::InitializeMocSourceFile(cmTarget* target) +bool cmQtAutoGenerators::InitializeAutogenTarget(cmTarget* target) { cmMakefile* makefile = target->GetMakefile(); // don't do anything if there is no Qt4 or Qt5Core (which contains moc): diff --git a/Source/cmQtAutoGenerators.h b/Source/cmQtAutoGenerators.h index 696abc8..116f174 100644 --- a/Source/cmQtAutoGenerators.h +++ b/Source/cmQtAutoGenerators.h @@ -23,7 +23,7 @@ public: cmQtAutoGenerators(); bool Run(const char* targetDirectory, const char *config); - bool InitializeMocSourceFile(cmTarget* target); + bool InitializeAutogenTarget(cmTarget* target); void SetupAutoGenerateTarget(cmTarget* target); private: -- cgit v0.12 From 944277d09ebdf59f2ea32931516af568e897bcd5 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Mon, 4 Nov 2013 10:34:54 +0100 Subject: cmAutogen: Gather tool arguments after creating generator targets. This change causes the GetLinkInterfaceDependentStringProperty method, called in SetupAutoGenerateTarget, after the creation of generator targets. In CMake 4.0, the GetLinkInterfaceDependentStringProperty will move to the cmGeneratorTarget class, and this patch is a necessary prerequisite to that. --- Source/cmGlobalGenerator.cxx | 24 +++++++++++++++--------- Source/cmGlobalGenerator.h | 4 +++- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index b6f491a..e1842f7 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -1105,9 +1105,12 @@ void cmGlobalGenerator::Generate() this->FinalizeTargetCompileDefinitions(); +#ifdef CMAKE_BUILD_WITH_CMAKE // Iterate through all targets and set up automoc for those which have // the AUTOMOC, AUTOUIC or AUTORCC property set - this->CreateQtAutoGeneratorsTargets(); + AutogensType autogens; + this->CreateQtAutoGeneratorsTargets(autogens); +#endif // For each existing cmLocalGenerator unsigned int i; @@ -1141,6 +1144,14 @@ void cmGlobalGenerator::Generate() // Create per-target generator information. this->CreateGeneratorTargets(); +#ifdef CMAKE_BUILD_WITH_CMAKE + for (AutogensType::iterator it = autogens.begin(); it != autogens.end(); + ++it) + { + it->first.SetupAutoGenerateTarget(it->second); + } +#endif + // Trace the dependencies, after that no custom commands should be added // because their dependencies might not be handled correctly for (i = 0; i < this->LocalGenerators.size(); ++i) @@ -1266,11 +1277,9 @@ bool cmGlobalGenerator::CheckTargets() } //---------------------------------------------------------------------------- -void cmGlobalGenerator::CreateQtAutoGeneratorsTargets() +void cmGlobalGenerator::CreateQtAutoGeneratorsTargets(AutogensType &autogens) { #ifdef CMAKE_BUILD_WITH_CMAKE - typedef std::vector > Autogens; - Autogens autogens; for(unsigned int i=0; i < this->LocalGenerators.size(); ++i) { cmTargets& targets = @@ -1299,11 +1308,8 @@ void cmGlobalGenerator::CreateQtAutoGeneratorsTargets() } } } - for (Autogens::iterator it = autogens.begin(); it != autogens.end(); - ++it) - { - it->first.SetupAutoGenerateTarget(it->second); - } +#else + (void)autogens; #endif } diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h index 92c3096..b9f4bd0 100644 --- a/Source/cmGlobalGenerator.h +++ b/Source/cmGlobalGenerator.h @@ -32,6 +32,7 @@ class cmTarget; class cmInstallTargetGenerator; class cmInstallFilesGenerator; class cmExportBuildFileGenerator; +class cmQtAutoGenerators; /** \class cmGlobalGenerator * \brief Responable for overseeing the generation process for the entire tree @@ -323,7 +324,8 @@ protected: virtual bool CheckALLOW_DUPLICATE_CUSTOM_TARGETS(); bool CheckTargets(); - void CreateQtAutoGeneratorsTargets(); + typedef std::vector > AutogensType; + void CreateQtAutoGeneratorsTargets(AutogensType& autogens); // Fill the ProjectMap, this must be called after LocalGenerators -- cgit v0.12