Merge topic 'refactor-autogen-setup'
944277d
cmAutogen: Gather tool arguments after creating generator targets.d2f4b1e
cmAutogen: Rename method to InitializeAutogenTarget45735f3
cmAutogen: Move autogen target creation to InitializeMocSourceFile.20a234d
cmAutogen: Extract some helper methods for autogen targets.
This commit is contained in:
commit
18985f6c29
|
@ -1061,9 +1061,12 @@ void cmGlobalGenerator::Generate()
|
||||||
|
|
||||||
this->FinalizeTargetCompileDefinitions();
|
this->FinalizeTargetCompileDefinitions();
|
||||||
|
|
||||||
|
#ifdef CMAKE_BUILD_WITH_CMAKE
|
||||||
// Iterate through all targets and set up automoc for those which have
|
// Iterate through all targets and set up automoc for those which have
|
||||||
// the AUTOMOC, AUTOUIC or AUTORCC property set
|
// the AUTOMOC, AUTOUIC or AUTORCC property set
|
||||||
this->CreateQtAutoGeneratorsTargets();
|
AutogensType autogens;
|
||||||
|
this->CreateQtAutoGeneratorsTargets(autogens);
|
||||||
|
#endif
|
||||||
|
|
||||||
// For each existing cmLocalGenerator
|
// For each existing cmLocalGenerator
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
@ -1097,6 +1100,14 @@ void cmGlobalGenerator::Generate()
|
||||||
// Create per-target generator information.
|
// Create per-target generator information.
|
||||||
this->CreateGeneratorTargets();
|
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
|
// Trace the dependencies, after that no custom commands should be added
|
||||||
// because their dependencies might not be handled correctly
|
// because their dependencies might not be handled correctly
|
||||||
for (i = 0; i < this->LocalGenerators.size(); ++i)
|
for (i = 0; i < this->LocalGenerators.size(); ++i)
|
||||||
|
@ -1222,11 +1233,9 @@ bool cmGlobalGenerator::CheckTargets()
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
void cmGlobalGenerator::CreateQtAutoGeneratorsTargets()
|
void cmGlobalGenerator::CreateQtAutoGeneratorsTargets(AutogensType &autogens)
|
||||||
{
|
{
|
||||||
#ifdef CMAKE_BUILD_WITH_CMAKE
|
#ifdef CMAKE_BUILD_WITH_CMAKE
|
||||||
typedef std::vector<std::pair<cmQtAutoGenerators, cmTarget*> > Autogens;
|
|
||||||
Autogens autogens;
|
|
||||||
for(unsigned int i=0; i < this->LocalGenerators.size(); ++i)
|
for(unsigned int i=0; i < this->LocalGenerators.size(); ++i)
|
||||||
{
|
{
|
||||||
cmTargets& targets =
|
cmTargets& targets =
|
||||||
|
@ -1247,7 +1256,7 @@ void cmGlobalGenerator::CreateQtAutoGeneratorsTargets()
|
||||||
&& !target.IsImported())
|
&& !target.IsImported())
|
||||||
{
|
{
|
||||||
cmQtAutoGenerators autogen;
|
cmQtAutoGenerators autogen;
|
||||||
if(autogen.InitializeMocSourceFile(&target))
|
if(autogen.InitializeAutogenTarget(&target))
|
||||||
{
|
{
|
||||||
autogens.push_back(std::make_pair(autogen, &target));
|
autogens.push_back(std::make_pair(autogen, &target));
|
||||||
}
|
}
|
||||||
|
@ -1255,11 +1264,8 @@ void cmGlobalGenerator::CreateQtAutoGeneratorsTargets()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (Autogens::iterator it = autogens.begin(); it != autogens.end();
|
#else
|
||||||
++it)
|
(void)autogens;
|
||||||
{
|
|
||||||
it->first.SetupAutoGenerateTarget(it->second);
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,7 @@ class cmTarget;
|
||||||
class cmInstallTargetGenerator;
|
class cmInstallTargetGenerator;
|
||||||
class cmInstallFilesGenerator;
|
class cmInstallFilesGenerator;
|
||||||
class cmExportBuildFileGenerator;
|
class cmExportBuildFileGenerator;
|
||||||
|
class cmQtAutoGenerators;
|
||||||
|
|
||||||
/** \class cmGlobalGenerator
|
/** \class cmGlobalGenerator
|
||||||
* \brief Responable for overseeing the generation process for the entire tree
|
* \brief Responable for overseeing the generation process for the entire tree
|
||||||
|
@ -323,7 +324,8 @@ protected:
|
||||||
virtual bool CheckALLOW_DUPLICATE_CUSTOM_TARGETS();
|
virtual bool CheckALLOW_DUPLICATE_CUSTOM_TARGETS();
|
||||||
|
|
||||||
bool CheckTargets();
|
bool CheckTargets();
|
||||||
void CreateQtAutoGeneratorsTargets();
|
typedef std::vector<std::pair<cmQtAutoGenerators, cmTarget*> > AutogensType;
|
||||||
|
void CreateQtAutoGeneratorsTargets(AutogensType& autogens);
|
||||||
|
|
||||||
|
|
||||||
// Fill the ProjectMap, this must be called after LocalGenerators
|
// Fill the ProjectMap, this must be called after LocalGenerators
|
||||||
|
|
|
@ -138,7 +138,25 @@ cmQtAutoGenerators::cmQtAutoGenerators()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cmQtAutoGenerators::InitializeMocSourceFile(cmTarget* target)
|
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::InitializeAutogenTarget(cmTarget* target)
|
||||||
{
|
{
|
||||||
cmMakefile* makefile = target->GetMakefile();
|
cmMakefile* makefile = target->GetMakefile();
|
||||||
// don't do anything if there is no Qt4 or Qt5Core (which contains moc):
|
// don't do anything if there is no Qt4 or Qt5Core (which contains moc):
|
||||||
|
@ -154,8 +172,7 @@ bool cmQtAutoGenerators::InitializeMocSourceFile(cmTarget* target)
|
||||||
|
|
||||||
if (target->GetPropertyAsBool("AUTOMOC"))
|
if (target->GetPropertyAsBool("AUTOMOC"))
|
||||||
{
|
{
|
||||||
std::string automocTargetName = target->GetName();
|
std::string automocTargetName = getAutogenTargetName(target);
|
||||||
automocTargetName += "_automoc";
|
|
||||||
std::string mocCppFile = makefile->GetCurrentOutputDirectory();
|
std::string mocCppFile = makefile->GetCurrentOutputDirectory();
|
||||||
mocCppFile += "/";
|
mocCppFile += "/";
|
||||||
mocCppFile += automocTargetName;
|
mocCppFile += automocTargetName;
|
||||||
|
@ -168,81 +185,10 @@ bool cmQtAutoGenerators::InitializeMocSourceFile(cmTarget* target)
|
||||||
|
|
||||||
target->AddSourceFile(mocCppSource);
|
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<std::string> 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<std::string>::const_iterator incDirIt = includeDirs.begin();
|
|
||||||
incDirIt != includeDirs.end();
|
|
||||||
++incDirIt)
|
|
||||||
{
|
|
||||||
incs += sep;
|
|
||||||
sep = ";";
|
|
||||||
incs += *incDirIt;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::set<std::string> defines;
|
|
||||||
localGen->AddCompileDefinitions(defines, target, config);
|
|
||||||
|
|
||||||
sep = "";
|
|
||||||
for(std::set<std::string>::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<void>(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:
|
// create a custom target for running generators at buildtime:
|
||||||
std::string autogenTargetName = targetName;
|
std::string autogenTargetName = getAutogenTargetName(target);
|
||||||
autogenTargetName += "_automoc";
|
|
||||||
|
|
||||||
makefile->AddDefinition("_moc_target_name",
|
std::string targetDir = getAutogenTargetDir(target);
|
||||||
cmLocalGenerator::EscapeForCMake(autogenTargetName.c_str()).c_str());
|
|
||||||
|
|
||||||
std::string targetDir = makefile->GetCurrentOutputDirectory();
|
|
||||||
targetDir += makefile->GetCMakeInstance()->GetCMakeFilesDirectory();
|
|
||||||
targetDir += "/";
|
|
||||||
targetDir += autogenTargetName;
|
|
||||||
targetDir += ".dir/";
|
|
||||||
|
|
||||||
cmCustomCommandLine currentLine;
|
cmCustomCommandLine currentLine;
|
||||||
currentLine.push_back(makefile->GetSafeDefinition("CMAKE_COMMAND"));
|
currentLine.push_back(makefile->GetSafeDefinition("CMAKE_COMMAND"));
|
||||||
|
@ -284,7 +230,7 @@ void cmQtAutoGenerators::SetupAutoGenerateTarget(cmTarget* target)
|
||||||
tools += " and " + toolNames[0];
|
tools += " and " + toolNames[0];
|
||||||
}
|
}
|
||||||
std::string autogenComment = "Automatic " + tools + " for target ";
|
std::string autogenComment = "Automatic " + tools + " for target ";
|
||||||
autogenComment += targetName;
|
autogenComment += target->GetName();
|
||||||
|
|
||||||
#if defined(_WIN32) && !defined(__CYGWIN__)
|
#if defined(_WIN32) && !defined(__CYGWIN__)
|
||||||
bool usePRE_BUILD = false;
|
bool usePRE_BUILD = false;
|
||||||
|
@ -341,6 +287,77 @@ void cmQtAutoGenerators::SetupAutoGenerateTarget(cmTarget* target)
|
||||||
target->AddUtility(autogenTargetName.c_str());
|
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<std::string> 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<std::string>::const_iterator incDirIt = includeDirs.begin();
|
||||||
|
incDirIt != includeDirs.end();
|
||||||
|
++incDirIt)
|
||||||
|
{
|
||||||
|
incs += sep;
|
||||||
|
sep = ";";
|
||||||
|
incs += *incDirIt;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::set<std::string> defines;
|
||||||
|
localGen->AddCompileDefinitions(defines, target, config);
|
||||||
|
|
||||||
|
sep = "";
|
||||||
|
for(std::set<std::string>::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<void>(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<std::string, std::string> configIncludes;
|
std::map<std::string, std::string> configIncludes;
|
||||||
std::map<std::string, std::string> configDefines;
|
std::map<std::string, std::string> configDefines;
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ public:
|
||||||
cmQtAutoGenerators();
|
cmQtAutoGenerators();
|
||||||
bool Run(const char* targetDirectory, const char *config);
|
bool Run(const char* targetDirectory, const char *config);
|
||||||
|
|
||||||
bool InitializeMocSourceFile(cmTarget* target);
|
bool InitializeAutogenTarget(cmTarget* target);
|
||||||
void SetupAutoGenerateTarget(cmTarget* target);
|
void SetupAutoGenerateTarget(cmTarget* target);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Reference in New Issue