From 83b730cd1aeeafc05473d163e13fb5489817c149 Mon Sep 17 00:00:00 2001 From: Alex Neundorf Date: Wed, 10 Aug 2011 19:51:07 +0200 Subject: [PATCH] Add AUTOMOC to the add_library() command Alex --- Source/cmAddLibraryCommand.cxx | 50 ++++++++++++++++++++++++++-------- Source/cmMakefile.cxx | 3 +- Source/cmMakefile.h | 2 +- 3 files changed, 42 insertions(+), 13 deletions(-) diff --git a/Source/cmAddLibraryCommand.cxx b/Source/cmAddLibraryCommand.cxx index f522cee9e..2e0604eb6 100644 --- a/Source/cmAddLibraryCommand.cxx +++ b/Source/cmAddLibraryCommand.cxx @@ -12,6 +12,7 @@ #include "cmAddLibraryCommand.h" #include "cmake.h" +#include "cmQtAutomoc.h" // cmLibraryCommand bool cmAddLibraryCommand @@ -31,13 +32,14 @@ bool cmAddLibraryCommand } bool excludeFromAll = false; bool importTarget = false; - + bool doAutomoc = false; + std::vector::const_iterator s = args.begin(); std::string libName = *s; ++s; - + // If the second argument is "SHARED" or "STATIC", then it controls // the type of library. Otherwise, it is treated as a source or // source list name. There may be two keyword arguments, check for them @@ -79,6 +81,11 @@ bool cmAddLibraryCommand ++s; importTarget = true; } + else if (*s == "AUTOMOC") + { + ++s; + doAutomoc = true; + } else { break; @@ -103,16 +110,23 @@ bool cmAddLibraryCommand 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. 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. if(this->Makefile->FindTargetToUse(libName.c_str())) { @@ -164,8 +178,22 @@ bool cmAddLibraryCommand ++s; } - this->Makefile->AddLibrary(libName.c_str(), type, srclists, - excludeFromAll); + 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, + excludeFromAll); + + if ( automoc ) + { + automoc->AddTargetDependency(this->Makefile, tgt); + delete automoc; + automoc = 0; + } return true; } diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index a5cdee4cc..45165e571 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -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 &srcs, bool excludeFromAll) { @@ -1909,6 +1909,7 @@ void cmMakefile::AddLibrary(const char* lname, cmTarget::TargetType type, } target->AddSources(srcs); this->AddGlobalLinkInformation(lname, *target); + return target; } cmTarget* cmMakefile::AddExecutable(const char *exeName, diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index c01bb5d8a..618f4f391 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -325,7 +325,7 @@ public: /** * 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 &srcs, bool excludeFromAll = false);