Move automoc processing from add_executable/library to cmGlobalGenerator

Now automoc is enabled by setting the AUTOMOC target property to true,
instead of using the AUTOMOC keyword in add_executable() or add_library()

Alex
This commit is contained in:
Alex Neundorf 2011-08-16 01:45:05 +02:00
parent cbaac2a587
commit 50cd6cef92
4 changed files with 36 additions and 41 deletions

View File

@ -10,7 +10,6 @@
See the License for more information.
============================================================================*/
#include "cmAddExecutableCommand.h"
#include "cmQtAutomoc.h"
// cmExecutableCommand
bool cmAddExecutableCommand
@ -30,7 +29,6 @@ bool cmAddExecutableCommand
bool use_macbundle = false;
bool excludeFromAll = false;
bool importTarget = false;
bool doAutomoc = false;
while ( s != args.end() )
{
if (*s == "WIN32")
@ -43,11 +41,6 @@ bool cmAddExecutableCommand
++s;
use_macbundle = true;
}
else if ( *s == "AUTOMOC" )
{
++s;
doAutomoc = true;
}
else if(*s == "EXCLUDE_FROM_ALL")
{
++s;
@ -66,17 +59,12 @@ bool cmAddExecutableCommand
// Special modifiers are not allowed with IMPORTED signature.
if(importTarget
&& (use_win32 || use_macbundle || excludeFromAll || doAutomoc))
&& (use_win32 || use_macbundle || excludeFromAll))
{
if(use_win32)
{
this->SetError("may not be given WIN32 for an IMPORTED target.");
}
else if(doAutomoc)
{
this->SetError(
"may not be given AUTOMOC for an IMPORTED target.");
}
else if(use_macbundle)
{
this->SetError(
@ -137,11 +125,5 @@ bool cmAddExecutableCommand
tgt->SetProperty("MACOSX_BUNDLE", "ON");
}
if ( doAutomoc )
{
cmQtAutomoc automoc;
automoc.SetupAutomocTarget(tgt);
}
return true;
}

View File

@ -12,7 +12,6 @@
#include "cmAddLibraryCommand.h"
#include "cmake.h"
#include "cmQtAutomoc.h"
// cmLibraryCommand
bool cmAddLibraryCommand
@ -32,7 +31,6 @@ bool cmAddLibraryCommand
}
bool excludeFromAll = false;
bool importTarget = false;
bool doAutomoc = false;
std::vector<std::string>::const_iterator s = args.begin();
@ -81,11 +79,6 @@ bool cmAddLibraryCommand
++s;
importTarget = true;
}
else if (*s == "AUTOMOC")
{
++s;
doAutomoc = true;
}
else
{
break;
@ -120,13 +113,6 @@ bool cmAddLibraryCommand
return false;
}
// Don't run automoc on an imported library
if (doAutomoc)
{
this->SetError("cannot be called with AUTOMOC for an IMPORTED library.");
return false;
}
// Make sure the target does not already exist.
if(this->Makefile->FindTargetToUse(libName.c_str()))
{
@ -178,14 +164,7 @@ bool cmAddLibraryCommand
++s;
}
cmTarget* tgt =this->Makefile->AddLibrary(libName.c_str(), type, srclists,
excludeFromAll);
if ( doAutomoc )
{
cmQtAutomoc automoc;
automoc.SetupAutomocTarget(tgt);
}
this->Makefile->AddLibrary(libName.c_str(), type, srclists, excludeFromAll);
return true;
}

View File

@ -18,6 +18,7 @@
#include "cmExternalMakefileProjectGenerator.h"
#include "cmake.h"
#include "cmMakefile.h"
#include "cmQtAutomoc.h"
#include "cmSourceFile.h"
#include "cmVersion.h"
#include "cmExportInstallFileGenerator.h"
@ -832,6 +833,10 @@ void cmGlobalGenerator::Generate()
return;
}
// Iterate through all targets and set up automoc for those which have
// the AUTOMOC property set
this->CreateAutomocTargets();
// For each existing cmLocalGenerator
unsigned int i;
@ -950,6 +955,33 @@ bool cmGlobalGenerator::CheckTargets()
return true;
}
//----------------------------------------------------------------------------
void cmGlobalGenerator::CreateAutomocTargets()
{
for(unsigned int i=0; i < this->LocalGenerators.size(); ++i)
{
cmTargets& targets =
this->LocalGenerators[i]->GetMakefile()->GetTargets();
for(cmTargets::iterator ti = targets.begin();
ti != targets.end(); ++ti)
{
cmTarget& target = ti->second;
if(target.GetType() == cmTarget::EXECUTABLE ||
target.GetType() == cmTarget::STATIC_LIBRARY ||
target.GetType() == cmTarget::SHARED_LIBRARY ||
target.GetType() == cmTarget::MODULE_LIBRARY)
{
if(target.GetPropertyAsBool("AUTOMOC") && !target.IsImported())
{
cmQtAutomoc automoc;
automoc.SetupAutomocTarget(&target);
}
}
}
}
}
void cmGlobalGenerator::CheckLocalGenerators()
{
std::map<cmStdString, cmStdString> notFoundMap;

View File

@ -282,6 +282,8 @@ protected:
virtual bool CheckALLOW_DUPLICATE_CUSTOM_TARGETS();
bool CheckTargets();
void CreateAutomocTargets();
// Fill the ProjectMap, this must be called after LocalGenerators
// has been populated.