summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorAlex Neundorf <neundorf@kde.org>2011-08-09 07:18:37 (GMT)
committerAlex Neundorf <neundorf@kde.org>2011-08-14 13:58:00 (GMT)
commit126c6ead7707ac29f3b2fa779752025c7cc0da32 (patch)
tree04480eb055d4baf3a9631c8ce8fbabbb02145012 /Source
parentde91feb367c127294a56b492799c4bf042954fd8 (diff)
downloadCMake-126c6ead7707ac29f3b2fa779752025c7cc0da32.zip
CMake-126c6ead7707ac29f3b2fa779752025c7cc0da32.tar.gz
CMake-126c6ead7707ac29f3b2fa779752025c7cc0da32.tar.bz2
Add the cmake module required currently for automoc
Alex
Diffstat (limited to 'Source')
-rw-r--r--Source/cmAddExecutableCommand.cxx30
-rw-r--r--Source/cmQtAutomoc.cxx126
-rw-r--r--Source/cmQtAutomoc.h6
-rw-r--r--Source/cmake.cxx7
-rw-r--r--Source/cmake.h1
5 files changed, 169 insertions, 1 deletions
diff --git a/Source/cmAddExecutableCommand.cxx b/Source/cmAddExecutableCommand.cxx
index a625c47..9710d20 100644
--- a/Source/cmAddExecutableCommand.cxx
+++ b/Source/cmAddExecutableCommand.cxx
@@ -10,6 +10,7 @@
See the License for more information.
============================================================================*/
#include "cmAddExecutableCommand.h"
+#include "cmQtAutomoc.h"
// cmExecutableCommand
bool cmAddExecutableCommand
@@ -29,6 +30,7 @@ bool cmAddExecutableCommand
bool use_macbundle = false;
bool excludeFromAll = false;
bool importTarget = false;
+ bool doAutomoc = false;
while ( s != args.end() )
{
if (*s == "WIN32")
@@ -41,6 +43,11 @@ bool cmAddExecutableCommand
++s;
use_macbundle = true;
}
+ else if ( *s == "AUTOMOC" )
+ {
+ ++s;
+ doAutomoc = true;
+ }
else if(*s == "EXCLUDE_FROM_ALL")
{
++s;
@@ -58,12 +65,18 @@ bool cmAddExecutableCommand
}
// Special modifiers are not allowed with IMPORTED signature.
- if(importTarget && (use_win32 || use_macbundle || excludeFromAll))
+ if(importTarget
+ && (use_win32 || use_macbundle || excludeFromAll || doAutomoc))
{
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(
@@ -113,6 +126,14 @@ bool cmAddExecutableCommand
}
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,
excludeFromAll);
if ( use_win32 )
@@ -124,5 +145,12 @@ bool cmAddExecutableCommand
tgt->SetProperty("MACOSX_BUNDLE", "ON");
}
+ if ( automoc )
+ {
+ automoc->AddTargetDependency(this->Makefile, tgt);
+ delete automoc;
+ automoc = 0;
+ }
+
return true;
}
diff --git a/Source/cmQtAutomoc.cxx b/Source/cmQtAutomoc.cxx
index 5494b2a..1431551 100644
--- a/Source/cmQtAutomoc.cxx
+++ b/Source/cmQtAutomoc.cxx
@@ -1,6 +1,7 @@
#include "cmGlobalGenerator.h"
#include "cmLocalGenerator.h"
#include "cmMakefile.h"
+#include "cmSourceFile.h"
#include "cmSystemTools.h"
#include "cmQtAutomoc.h"
@@ -16,6 +17,131 @@ cmQtAutomoc::cmQtAutomoc()
}
+void cmQtAutomoc::SetupAutomocTarget(cmMakefile* makefile,
+ const char* targetName,
+ std::vector<std::string>& srcs)
+{
+ // don't do anything if there is no Qt4:
+ std::string qtMajorVersion = makefile->GetSafeDefinition("QT_VERSION_MAJOR");
+ if (qtMajorVersion != "4")
+ {
+ return;
+ }
+
+ std::string automocTargetName = targetName;
+ automocTargetName += "_automoc";
+
+ std::string targetDir = makefile->GetCurrentOutputDirectory();
+ targetDir += makefile->GetCMakeInstance()->GetCMakeFilesDirectory();
+ targetDir += "/";
+ targetDir += automocTargetName;
+ targetDir += ".dir/";
+
+ cmCustomCommandLine currentLine;
+ currentLine.push_back(makefile->GetCMakeInstance()->GetCMakeCommand());
+ currentLine.push_back("-E");
+ currentLine.push_back("cmake_automoc");
+ currentLine.push_back(targetDir);
+
+ cmCustomCommandLines commandLines;
+ commandLines.push_back(currentLine);
+
+ std::string workingDirectory = cmSystemTools::CollapseFullPath(
+ "", makefile->GetCurrentOutputDirectory());
+
+ std::vector<std::string> depends;
+
+ cmTarget* target = makefile->AddUtilityCommand(automocTargetName.c_str(),
+ true,
+ workingDirectory.c_str(), depends,
+ commandLines, false, "Automoc target");
+
+ std::string _moc_files;
+ std::string _moc_headers;
+ const char* sepFiles = "";
+ const char* sepHeaders = "";
+ for(std::vector<std::string>::const_iterator fileIt = srcs.begin();
+ fileIt != srcs.end();
+ ++fileIt)
+ {
+ std::string absFile = cmSystemTools::CollapseFullPath(
+ fileIt->c_str(), makefile->GetCurrentDirectory());
+
+ bool skip = false;
+ 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))
+ {
+ std::string ext = cmSystemTools::GetFilenameExtension(fileIt->c_str());
+ cmSystemTools::FileFormat fileType = cmSystemTools::GetFileFormat(ext.c_str());
+ if (fileType == cmSystemTools::CXX_FILE_FORMAT)
+ {
+ _moc_files += sepFiles;
+ _moc_files += absFile;
+ sepFiles = ";";
+ }
+ else if (fileType == cmSystemTools::HEADER_FILE_FORMAT)
+ {
+ _moc_headers += sepHeaders;
+ _moc_headers += absFile;
+ sepHeaders = ";";
+ }
+ }
+ }
+
+ std::string _moc_incs = makefile->GetProperty("INCLUDE_DIRECTORIES");
+ std::string _moc_defs = makefile->GetProperty("DEFINITIONS");
+ std::string _moc_compile_defs = makefile->GetProperty("COMPILE_DEFINITIONS");
+ // forget the variables added here afterwards again:
+ cmMakefile::ScopePushPop varScope(makefile);
+ static_cast<void>(varScope);
+
+ makefile->AddDefinition("_moc_target_name", automocTargetName.c_str());
+ makefile->AddDefinition("_moc_incs", _moc_incs.c_str());
+ makefile->AddDefinition("_moc_defs", _moc_defs.c_str());
+ makefile->AddDefinition("_moc_compile_defs", _moc_compile_defs.c_str());
+ makefile->AddDefinition("_moc_files", _moc_files.c_str());
+ makefile->AddDefinition("_moc_headers", _moc_headers.c_str());
+
+ const char* cmakeRoot = makefile->GetDefinition("CMAKE_ROOT");
+ std::string inputFile = cmakeRoot;
+ inputFile += "/Modules/AutomocInfo.cmake.in";
+ std::string outputFile = targetDir;
+ outputFile += "/AutomocInfo.cmake";
+ makefile->ConfigureFile(inputFile.c_str(), outputFile.c_str(),
+ false, true, false);
+
+ std::string mocCppFile = makefile->GetCurrentOutputDirectory();
+ mocCppFile += "/";
+ mocCppFile += automocTargetName;
+ mocCppFile += ".cpp";
+ makefile->GetOrCreateSource(mocCppFile.c_str(), true);
+ srcs.push_back(mocCppFile);
+
+}
+
+
+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)
{
cmake cm;
diff --git a/Source/cmQtAutomoc.h b/Source/cmQtAutomoc.h
index 891b47a..e573610 100644
--- a/Source/cmQtAutomoc.h
+++ b/Source/cmQtAutomoc.h
@@ -10,6 +10,12 @@ public:
cmQtAutomoc();
bool Run(const char* targetDirectory);
+ void SetupAutomocTarget(cmMakefile* makefile,
+ const char* targetName,
+ std::vector<std::string>& srcs);
+
+ void AddTargetDependency(cmMakefile* makefile, cmTarget* target);
+
private:
cmGlobalGenerator* CreateGlobalGenerator(cmake* cm,
const char* targetDirectory);
diff --git a/Source/cmake.cxx b/Source/cmake.cxx
index 06229e0..c5eff1c 100644
--- a/Source/cmake.cxx
+++ b/Source/cmake.cxx
@@ -2927,6 +2927,13 @@ const char* cmake::GetCPackCommand()
return this->CPackCommand.c_str();
}
+
+const char* cmake::GetCMakeCommand()
+{
+ return this->CMakeCommand.c_str();
+}
+
+
void cmake::MarkCliAsUsed(const std::string& variable)
{
this->UsedCliVariables[variable] = true;
diff --git a/Source/cmake.h b/Source/cmake.h
index f2a2ae3..09f6c37 100644
--- a/Source/cmake.h
+++ b/Source/cmake.h
@@ -301,6 +301,7 @@ class cmake
*/
const char* GetCTestCommand();
const char* GetCPackCommand();
+ const char* GetCMakeCommand();
// Do we want debug output during the cmake run.
bool GetDebugOutput() { return this->DebugOutput; }