Add AUTOMOC to the add_library() command

Alex
This commit is contained in:
Alex Neundorf 2011-08-10 19:51:07 +02:00
parent 126c6ead77
commit 83b730cd1a
3 changed files with 42 additions and 13 deletions

View File

@ -12,6 +12,7 @@
#include "cmAddLibraryCommand.h" #include "cmAddLibraryCommand.h"
#include "cmake.h" #include "cmake.h"
#include "cmQtAutomoc.h"
// cmLibraryCommand // cmLibraryCommand
bool cmAddLibraryCommand bool cmAddLibraryCommand
@ -31,13 +32,14 @@ bool cmAddLibraryCommand
} }
bool excludeFromAll = false; bool excludeFromAll = false;
bool importTarget = false; bool importTarget = false;
bool doAutomoc = false;
std::vector<std::string>::const_iterator s = args.begin(); std::vector<std::string>::const_iterator s = args.begin();
std::string libName = *s; std::string libName = *s;
++s; ++s;
// If the second argument is "SHARED" or "STATIC", then it controls // If the second argument is "SHARED" or "STATIC", then it controls
// the type of library. Otherwise, it is treated as a source or // the type of library. Otherwise, it is treated as a source or
// source list name. There may be two keyword arguments, check for them // source list name. There may be two keyword arguments, check for them
@ -79,6 +81,11 @@ bool cmAddLibraryCommand
++s; ++s;
importTarget = true; importTarget = true;
} }
else if (*s == "AUTOMOC")
{
++s;
doAutomoc = true;
}
else else
{ {
break; break;
@ -103,16 +110,23 @@ bool cmAddLibraryCommand
type = cmTarget::STATIC_LIBRARY; type = cmTarget::STATIC_LIBRARY;
} }
// The IMPORTED signature requires a type to be specified explicitly.
if(importTarget && !haveSpecifiedType)
{
this->SetError("called with IMPORTED argument but no library type.");
return false;
}
// Handle imported target creation. // Handle imported target creation.
if(importTarget) if(importTarget)
{ {
// The IMPORTED signature requires a type to be specified explicitly.
if (!haveSpecifiedType)
{
this->SetError("called with IMPORTED argument but no library type.");
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. // Make sure the target does not already exist.
if(this->Makefile->FindTargetToUse(libName.c_str())) if(this->Makefile->FindTargetToUse(libName.c_str()))
{ {
@ -164,8 +178,22 @@ bool cmAddLibraryCommand
++s; ++s;
} }
this->Makefile->AddLibrary(libName.c_str(), type, srclists, cmQtAutomoc* automoc = 0;
excludeFromAll); if ( doAutomoc )
{
automoc = new cmQtAutomoc;
automoc->SetupAutomocTarget(this->Makefile, libName.c_str(), srclists);
}
cmTarget* tgt =this->Makefile->AddLibrary(libName.c_str(), type, srclists,
excludeFromAll);
if ( automoc )
{
automoc->AddTargetDependency(this->Makefile, tgt);
delete automoc;
automoc = 0;
}
return true; return true;
} }

View File

@ -1886,7 +1886,7 @@ void cmMakefile::AddGlobalLinkInformation(const char* name, cmTarget& target)
} }
void cmMakefile::AddLibrary(const char* lname, cmTarget::TargetType type, cmTarget* cmMakefile::AddLibrary(const char* lname, cmTarget::TargetType type,
const std::vector<std::string> &srcs, const std::vector<std::string> &srcs,
bool excludeFromAll) bool excludeFromAll)
{ {
@ -1909,6 +1909,7 @@ void cmMakefile::AddLibrary(const char* lname, cmTarget::TargetType type,
} }
target->AddSources(srcs); target->AddSources(srcs);
this->AddGlobalLinkInformation(lname, *target); this->AddGlobalLinkInformation(lname, *target);
return target;
} }
cmTarget* cmMakefile::AddExecutable(const char *exeName, cmTarget* cmMakefile::AddExecutable(const char *exeName,

View File

@ -325,7 +325,7 @@ public:
/** /**
* Set the name of the library. * Set the name of the library.
*/ */
void AddLibrary(const char *libname, cmTarget::TargetType type, cmTarget* AddLibrary(const char *libname, cmTarget::TargetType type,
const std::vector<std::string> &srcs, const std::vector<std::string> &srcs,
bool excludeFromAll = false); bool excludeFromAll = false);