Refactor SetupAutomocTarget() so it can be run after creating the target
This makes it easier to move it from InitialPass() to some other location, e.g. FinalPass() or something else. Alex
This commit is contained in:
parent
24d9b7d745
commit
c27607baf8
@ -126,14 +126,6 @@ bool cmAddExecutableCommand
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> srclists(s, args.end());
|
std::vector<std::string> srclists(s, args.end());
|
||||||
cmQtAutomoc* automoc = 0;
|
|
||||||
if ( doAutomoc )
|
|
||||||
{
|
|
||||||
automoc = new cmQtAutomoc;
|
|
||||||
automoc->SetupAutomocTarget(this->Makefile, exename.c_str(), srclists);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
cmTarget* tgt = this->Makefile->AddExecutable(exename.c_str(), srclists,
|
cmTarget* tgt = this->Makefile->AddExecutable(exename.c_str(), srclists,
|
||||||
excludeFromAll);
|
excludeFromAll);
|
||||||
if ( use_win32 )
|
if ( use_win32 )
|
||||||
@ -145,11 +137,10 @@ bool cmAddExecutableCommand
|
|||||||
tgt->SetProperty("MACOSX_BUNDLE", "ON");
|
tgt->SetProperty("MACOSX_BUNDLE", "ON");
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( automoc )
|
if ( doAutomoc )
|
||||||
{
|
{
|
||||||
automoc->AddTargetDependency(this->Makefile, tgt);
|
cmQtAutomoc automoc;
|
||||||
delete automoc;
|
automoc.SetupAutomocTarget(tgt);
|
||||||
automoc = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -178,21 +178,13 @@ bool cmAddLibraryCommand
|
|||||||
++s;
|
++s;
|
||||||
}
|
}
|
||||||
|
|
||||||
cmQtAutomoc* automoc = 0;
|
|
||||||
if ( doAutomoc )
|
|
||||||
{
|
|
||||||
automoc = new cmQtAutomoc;
|
|
||||||
automoc->SetupAutomocTarget(this->Makefile, libName.c_str(), srclists);
|
|
||||||
}
|
|
||||||
|
|
||||||
cmTarget* tgt =this->Makefile->AddLibrary(libName.c_str(), type, srclists,
|
cmTarget* tgt =this->Makefile->AddLibrary(libName.c_str(), type, srclists,
|
||||||
excludeFromAll);
|
excludeFromAll);
|
||||||
|
|
||||||
if ( automoc )
|
if ( doAutomoc )
|
||||||
{
|
{
|
||||||
automoc->AddTargetDependency(this->Makefile, tgt);
|
cmQtAutomoc automoc;
|
||||||
delete automoc;
|
automoc.SetupAutomocTarget(tgt);
|
||||||
automoc = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -32,10 +32,10 @@ cmQtAutomoc::cmQtAutomoc()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void cmQtAutomoc::SetupAutomocTarget(cmMakefile* makefile,
|
void cmQtAutomoc::SetupAutomocTarget(cmTarget* target)
|
||||||
const char* targetName,
|
|
||||||
std::vector<std::string>& srcs)
|
|
||||||
{
|
{
|
||||||
|
cmMakefile* makefile = target->GetMakefile();
|
||||||
|
const char* targetName = target->GetName();
|
||||||
// don't do anything if there is no Qt4:
|
// don't do anything if there is no Qt4:
|
||||||
std::string qtMajorVersion = makefile->GetSafeDefinition("QT_VERSION_MAJOR");
|
std::string qtMajorVersion = makefile->GetSafeDefinition("QT_VERSION_MAJOR");
|
||||||
if (qtMajorVersion != "4")
|
if (qtMajorVersion != "4")
|
||||||
@ -43,6 +43,7 @@ void cmQtAutomoc::SetupAutomocTarget(cmMakefile* makefile,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// create a custom target for running automoc at buildtime:
|
||||||
std::string automocTargetName = targetName;
|
std::string automocTargetName = targetName;
|
||||||
automocTargetName += "_automoc";
|
automocTargetName += "_automoc";
|
||||||
|
|
||||||
@ -66,34 +67,32 @@ void cmQtAutomoc::SetupAutomocTarget(cmMakefile* makefile,
|
|||||||
|
|
||||||
std::vector<std::string> depends;
|
std::vector<std::string> depends;
|
||||||
|
|
||||||
cmTarget* target = makefile->AddUtilityCommand(automocTargetName.c_str(),
|
cmTarget* mocTarget = makefile->AddUtilityCommand(automocTargetName.c_str(),
|
||||||
true,
|
true,
|
||||||
workingDirectory.c_str(), depends,
|
workingDirectory.c_str(), depends,
|
||||||
commandLines, false, "Automoc target");
|
commandLines, false, "Automoc target");
|
||||||
|
target->AddUtility(automocTargetName.c_str());
|
||||||
|
|
||||||
|
// configure a file to get all information to automoc at buildtime:
|
||||||
std::string _moc_files;
|
std::string _moc_files;
|
||||||
std::string _moc_headers;
|
std::string _moc_headers;
|
||||||
const char* sepFiles = "";
|
const char* sepFiles = "";
|
||||||
const char* sepHeaders = "";
|
const char* sepHeaders = "";
|
||||||
for(std::vector<std::string>::const_iterator fileIt = srcs.begin();
|
|
||||||
fileIt != srcs.end();
|
const std::vector<cmSourceFile*>& srcFiles = target->GetSourceFiles();
|
||||||
|
|
||||||
|
for(std::vector<cmSourceFile*>::const_iterator fileIt = srcFiles.begin();
|
||||||
|
fileIt != srcFiles.end();
|
||||||
++fileIt)
|
++fileIt)
|
||||||
{
|
{
|
||||||
std::string absFile = cmSystemTools::CollapseFullPath(
|
cmSourceFile* sf = *fileIt;
|
||||||
fileIt->c_str(), makefile->GetCurrentDirectory());
|
std::string absFile = sf->GetFullPath();
|
||||||
|
bool skip = cmSystemTools::IsOn(sf->GetPropertyForUser("SKIP_AUTOMOC"));
|
||||||
bool skip = false;
|
bool generated = cmSystemTools::IsOn(sf->GetPropertyForUser("GENERATED"));
|
||||||
bool generated = false;
|
|
||||||
cmSourceFile* sf = makefile->GetSource(absFile.c_str());
|
|
||||||
if (sf)
|
|
||||||
{
|
|
||||||
skip = cmSystemTools::IsOn(sf->GetPropertyForUser("SKIP_AUTOMOC"));
|
|
||||||
generated = cmSystemTools::IsOn(sf->GetPropertyForUser("GENERATED"));
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((skip==false) && (generated == false))
|
if ((skip==false) && (generated == false))
|
||||||
{
|
{
|
||||||
std::string ext = cmSystemTools::GetFilenameExtension(fileIt->c_str());
|
std::string ext = sf->GetExtension();
|
||||||
cmSystemTools::FileFormat fileType = cmSystemTools::GetFileFormat(
|
cmSystemTools::FileFormat fileType = cmSystemTools::GetFileFormat(
|
||||||
ext.c_str());
|
ext.c_str());
|
||||||
if (fileType == cmSystemTools::CXX_FILE_FORMAT)
|
if (fileType == cmSystemTools::CXX_FILE_FORMAT)
|
||||||
@ -137,29 +136,15 @@ void cmQtAutomoc::SetupAutomocTarget(cmMakefile* makefile,
|
|||||||
mocCppFile += "/";
|
mocCppFile += "/";
|
||||||
mocCppFile += automocTargetName;
|
mocCppFile += automocTargetName;
|
||||||
mocCppFile += ".cpp";
|
mocCppFile += ".cpp";
|
||||||
makefile->GetOrCreateSource(mocCppFile.c_str(), true);
|
cmSourceFile* mocCppSource = makefile->GetOrCreateSource(mocCppFile.c_str(),
|
||||||
srcs.push_back(mocCppFile);
|
true);
|
||||||
|
target->AddSourceFile(mocCppSource);
|
||||||
|
|
||||||
makefile->AppendProperty("ADDITIONAL_MAKE_CLEAN_FILES",
|
makefile->AppendProperty("ADDITIONAL_MAKE_CLEAN_FILES",
|
||||||
mocCppFile.c_str(), false);
|
mocCppFile.c_str(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void cmQtAutomoc::AddTargetDependency(cmMakefile* makefile, cmTarget* target)
|
|
||||||
{
|
|
||||||
// don't do anything if there is no Qt4:
|
|
||||||
std::string qtMajorVersion = makefile->GetSafeDefinition("QT_VERSION_MAJOR");
|
|
||||||
if (qtMajorVersion != "4")
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string automocTargetName = target->GetName();
|
|
||||||
automocTargetName += "_automoc";
|
|
||||||
target->AddUtility(automocTargetName.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool cmQtAutomoc::Run(const char* targetDirectory)
|
bool cmQtAutomoc::Run(const char* targetDirectory)
|
||||||
{
|
{
|
||||||
cmake cm;
|
cmake cm;
|
||||||
|
@ -10,11 +10,7 @@ public:
|
|||||||
cmQtAutomoc();
|
cmQtAutomoc();
|
||||||
bool Run(const char* targetDirectory);
|
bool Run(const char* targetDirectory);
|
||||||
|
|
||||||
void SetupAutomocTarget(cmMakefile* makefile,
|
void SetupAutomocTarget(cmTarget* target);
|
||||||
const char* targetName,
|
|
||||||
std::vector<std::string>& srcs);
|
|
||||||
|
|
||||||
void AddTargetDependency(cmMakefile* makefile, cmTarget* target);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
cmGlobalGenerator* CreateGlobalGenerator(cmake* cm,
|
cmGlobalGenerator* CreateGlobalGenerator(cmake* cm,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user