summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
Diffstat (limited to 'Source')
-rw-r--r--Source/CMakeLists.txt4
-rw-r--r--Source/cmGlobalGenerator.cxx27
-rw-r--r--Source/cmGlobalGenerator.h2
-rw-r--r--Source/cmMakefile.cxx12
-rw-r--r--Source/cmMakefile.h5
-rw-r--r--Source/cmQtAutoGenerators.cxx (renamed from Source/cmQtAutomoc.cxx)983
-rw-r--r--Source/cmQtAutoGenerators.h (renamed from Source/cmQtAutomoc.h)55
-rw-r--r--Source/cmSourceFile.cxx11
-rw-r--r--Source/cmTarget.cxx4
-rw-r--r--Source/cmcmd.cxx10
10 files changed, 937 insertions, 176 deletions
diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt
index fd97a20..c01245c 100644
--- a/Source/CMakeLists.txt
+++ b/Source/CMakeLists.txt
@@ -250,8 +250,8 @@ set(SRCS
cmPropertyDefinitionMap.h
cmPropertyMap.cxx
cmPropertyMap.h
- cmQtAutomoc.cxx
- cmQtAutomoc.h
+ cmQtAutoGenerators.cxx
+ cmQtAutoGenerators.h
cmRST.cxx
cmRST.h
cmScriptGenerator.h
diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx
index 5b0df2c..465763d 100644
--- a/Source/cmGlobalGenerator.cxx
+++ b/Source/cmGlobalGenerator.cxx
@@ -18,7 +18,7 @@
#include "cmExternalMakefileProjectGenerator.h"
#include "cmake.h"
#include "cmMakefile.h"
-#include "cmQtAutomoc.h"
+#include "cmQtAutoGenerators.h"
#include "cmSourceFile.h"
#include "cmVersion.h"
#include "cmTargetExport.h"
@@ -1096,8 +1096,8 @@ void cmGlobalGenerator::Generate()
}
// Iterate through all targets and set up automoc for those which have
- // the AUTOMOC property set
- this->CreateAutomocTargets();
+ // the AUTOMOC, AUTOUIC or AUTORCC property set
+ this->CreateQtAutoGeneratorsTargets();
// For each existing cmLocalGenerator
unsigned int i;
@@ -1253,11 +1253,11 @@ bool cmGlobalGenerator::CheckTargets()
}
//----------------------------------------------------------------------------
-void cmGlobalGenerator::CreateAutomocTargets()
+void cmGlobalGenerator::CreateQtAutoGeneratorsTargets()
{
#ifdef CMAKE_BUILD_WITH_CMAKE
- typedef std::vector<std::pair<cmQtAutomoc, cmTarget*> > Automocs;
- Automocs automocs;
+ typedef std::vector<std::pair<cmQtAutoGenerators, cmTarget*> > Autogens;
+ Autogens autogens;
for(unsigned int i=0; i < this->LocalGenerators.size(); ++i)
{
cmTargets& targets =
@@ -1272,21 +1272,24 @@ void cmGlobalGenerator::CreateAutomocTargets()
target.GetType() == cmTarget::MODULE_LIBRARY ||
target.GetType() == cmTarget::OBJECT_LIBRARY)
{
- if(target.GetPropertyAsBool("AUTOMOC") && !target.IsImported())
+ if((target.GetPropertyAsBool("AUTOMOC")
+ || target.GetPropertyAsBool("AUTOUIC")
+ || target.GetPropertyAsBool("AUTORCC"))
+ && !target.IsImported())
{
- cmQtAutomoc automoc;
- if(automoc.InitializeMocSourceFile(&target))
+ cmQtAutoGenerators autogen;
+ if(autogen.InitializeMocSourceFile(&target))
{
- automocs.push_back(std::make_pair(automoc, &target));
+ autogens.push_back(std::make_pair(autogen, &target));
}
}
}
}
}
- for (Automocs::iterator it = automocs.begin(); it != automocs.end();
+ for (Autogens::iterator it = autogens.begin(); it != autogens.end();
++it)
{
- it->first.SetupAutomocTarget(it->second);
+ it->first.SetupAutoGenerateTarget(it->second);
}
#endif
}
diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h
index 3c4ddb2..1538cb5 100644
--- a/Source/cmGlobalGenerator.h
+++ b/Source/cmGlobalGenerator.h
@@ -319,7 +319,7 @@ protected:
virtual bool CheckALLOW_DUPLICATE_CUSTOM_TARGETS();
bool CheckTargets();
- void CreateAutomocTargets();
+ void CreateQtAutoGeneratorsTargets();
// Fill the ProjectMap, this must be called after LocalGenerators
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index ade4252..c18a7eb 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -4207,6 +4207,18 @@ bool cmMakefile::EnforceUniqueDir(const char* srcPath, const char* binPath)
}
//----------------------------------------------------------------------------
+void cmMakefile::AddQtUiFileWithOptions(cmSourceFile *sf)
+{
+ this->QtUiFilesWithOptions.push_back(sf);
+}
+
+//----------------------------------------------------------------------------
+std::vector<cmSourceFile*> cmMakefile::GetQtUiFilesWithOptions() const
+{
+ return this->QtUiFilesWithOptions;
+}
+
+//----------------------------------------------------------------------------
cmPolicies::PolicyStatus
cmMakefile::GetPolicyStatus(cmPolicies::PolicyID id)
{
diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h
index 918c8bf..76958ca 100644
--- a/Source/cmMakefile.h
+++ b/Source/cmMakefile.h
@@ -877,6 +877,9 @@ public:
bool IsGeneratingBuildSystem(){ return this->GeneratingBuildSystem; }
void SetGeneratingBuildSystem(){ this->GeneratingBuildSystem = true; }
+ void AddQtUiFileWithOptions(cmSourceFile *sf);
+ std::vector<cmSourceFile*> GetQtUiFilesWithOptions() const;
+
std::set<cmStdString> const & GetSystemIncludeDirectories() const
{ return this->SystemIncludeDirectories; }
@@ -1054,6 +1057,8 @@ private:
cmSourceFile* source);
void UpdateOutputToSourceMap(std::string const& output,
cmSourceFile* source);
+
+ std::vector<cmSourceFile*> QtUiFilesWithOptions;
};
//----------------------------------------------------------------------------
diff --git a/Source/cmQtAutomoc.cxx b/Source/cmQtAutoGenerators.cxx
index 651e0ad..5f7a26f 100644
--- a/Source/cmQtAutomoc.cxx
+++ b/Source/cmQtAutoGenerators.cxx
@@ -23,13 +23,14 @@
#include <cmsys/Terminal.h>
#include <cmsys/ios/sstream>
+#include <assert.h>
#include <string.h>
#if defined(__APPLE__)
#include <unistd.h>
#endif
-#include "cmQtAutomoc.h"
+#include "cmQtAutoGenerators.h"
static bool requiresMocing(const std::string& text, std::string &macroName)
@@ -113,10 +114,12 @@ static void copyTargetProperty(cmTarget* destinationTarget,
}
-cmQtAutomoc::cmQtAutomoc()
+cmQtAutoGenerators::cmQtAutoGenerators()
:Verbose(cmsys::SystemTools::GetEnv("VERBOSE") != 0)
,ColorOutput(true)
,RunMocFailed(false)
+,RunUicFailed(false)
+,RunRccFailed(false)
,GenerateAll(false)
{
@@ -135,7 +138,7 @@ cmQtAutomoc::cmQtAutomoc()
}
}
-bool cmQtAutomoc::InitializeMocSourceFile(cmTarget* target)
+bool cmQtAutoGenerators::InitializeMocSourceFile(cmTarget* target)
{
cmMakefile* makefile = target->GetMakefile();
// don't do anything if there is no Qt4 or Qt5Core (which contains moc):
@@ -149,18 +152,22 @@ bool cmQtAutomoc::InitializeMocSourceFile(cmTarget* target)
return false;
}
- std::string automocTargetName = target->GetName();
- automocTargetName += "_automoc";
- std::string mocCppFile = makefile->GetCurrentOutputDirectory();
- mocCppFile += "/";
- mocCppFile += automocTargetName;
- mocCppFile += ".cpp";
- cmSourceFile* mocCppSource = makefile->GetOrCreateSource(mocCppFile.c_str(),
- true);
- makefile->AppendProperty("ADDITIONAL_MAKE_CLEAN_FILES",
- mocCppFile.c_str(), false);
-
- target->AddSourceFile(mocCppSource);
+ if (target->GetPropertyAsBool("AUTOMOC"))
+ {
+ std::string automocTargetName = target->GetName();
+ automocTargetName += "_automoc";
+ std::string mocCppFile = makefile->GetCurrentOutputDirectory();
+ mocCppFile += "/";
+ mocCppFile += automocTargetName;
+ mocCppFile += ".cpp";
+ cmSourceFile* mocCppSource = makefile->GetOrCreateSource(
+ mocCppFile.c_str(),
+ true);
+ makefile->AppendProperty("ADDITIONAL_MAKE_CLEAN_FILES",
+ mocCppFile.c_str(), false);
+
+ target->AddSourceFile(mocCppSource);
+ }
return true;
}
@@ -201,27 +208,46 @@ static void GetCompileDefinitionsAndDirectories(cmTarget *target,
}
}
-void cmQtAutomoc::SetupAutomocTarget(cmTarget* target)
+void cmQtAutoGenerators::SetupAutoGenerateTarget(cmTarget* target)
{
cmMakefile* makefile = target->GetMakefile();
const char* targetName = target->GetName();
- bool relaxedMode = makefile->IsOn("CMAKE_AUTOMOC_RELAXED_MODE");
+ // forget the variables added here afterwards again:
+ cmMakefile::ScopePushPop varScope(makefile);
+ static_cast<void>(varScope);
- // create a custom target for running automoc at buildtime:
- std::string automocTargetName = targetName;
- automocTargetName += "_automoc";
+ const char *qtVersion = makefile->GetDefinition("Qt5Core_VERSION_MAJOR");
+ if (!qtVersion)
+ {
+ qtVersion = makefile->GetDefinition("QT_VERSION_MAJOR");
+ }
+ if (const char *targetQtVersion =
+ target->GetLinkInterfaceDependentStringProperty("QT_MAJOR_VERSION", 0))
+ {
+ qtVersion = targetQtVersion;
+ }
+ if (qtVersion)
+ {
+ makefile->AddDefinition("_target_qt_version", qtVersion);
+ }
+ // create a custom target for running generators at buildtime:
+ std::string autogenTargetName = targetName;
+ autogenTargetName += "_automoc";
+
+ makefile->AddDefinition("_moc_target_name",
+ cmLocalGenerator::EscapeForCMake(autogenTargetName.c_str()).c_str());
std::string targetDir = makefile->GetCurrentOutputDirectory();
targetDir += makefile->GetCMakeInstance()->GetCMakeFilesDirectory();
targetDir += "/";
- targetDir += automocTargetName;
+ targetDir += autogenTargetName;
targetDir += ".dir/";
cmCustomCommandLine currentLine;
currentLine.push_back(makefile->GetSafeDefinition("CMAKE_COMMAND"));
currentLine.push_back("-E");
- currentLine.push_back("cmake_automoc");
+ currentLine.push_back("cmake_autogen");
currentLine.push_back(targetDir);
currentLine.push_back("$<CONFIGURATION>");
@@ -232,8 +258,33 @@ void cmQtAutomoc::SetupAutomocTarget(cmTarget* target)
"", makefile->GetCurrentOutputDirectory());
std::vector<std::string> depends;
- std::string automocComment = "Automoc for target ";
- automocComment += targetName;
+ std::vector<std::string> toolNames;
+ if (target->GetPropertyAsBool("AUTOMOC"))
+ {
+ toolNames.push_back("moc");
+ }
+ if (target->GetPropertyAsBool("AUTOUIC"))
+ {
+ toolNames.push_back("uic");
+ }
+ if (target->GetPropertyAsBool("AUTORCC"))
+ {
+ toolNames.push_back("rcc");
+ }
+
+ std::string tools = toolNames[0];
+ toolNames.erase(toolNames.begin());
+ while (toolNames.size() > 1)
+ {
+ tools += ", " + toolNames[0];
+ toolNames.erase(toolNames.begin());
+ }
+ if (toolNames.size() == 1)
+ {
+ tools += " and " + toolNames[0];
+ }
+ std::string autogenComment = "Automatic " + tools + " for target ";
+ autogenComment += targetName;
#if defined(_WIN32) && !defined(__CYGWIN__)
bool usePRE_BUILD = false;
@@ -256,7 +307,7 @@ void cmQtAutomoc::SetupAutomocTarget(cmTarget* target)
// PRE_BUILD will work for an OBJECT_LIBRARY in this specific case.
std::vector<std::string> no_output;
cmCustomCommand cc(makefile, no_output, depends,
- commandLines, automocComment.c_str(),
+ commandLines, autogenComment.c_str(),
workingDirectory.c_str());
cc.SetEscapeOldStyle(false);
cc.SetEscapeAllowMakeVars(true);
@@ -265,27 +316,97 @@ void cmQtAutomoc::SetupAutomocTarget(cmTarget* target)
else
#endif
{
- cmTarget* automocTarget = makefile->AddUtilityCommand(
- automocTargetName.c_str(), true,
+ cmTarget* autogenTarget = makefile->AddUtilityCommand(
+ autogenTargetName.c_str(), true,
workingDirectory.c_str(), depends,
- commandLines, false, automocComment.c_str());
+ commandLines, false, autogenComment.c_str());
// Set target folder
- const char* automocFolder = makefile->GetCMakeInstance()->GetProperty(
+ const char* autogenFolder = makefile->GetCMakeInstance()->GetProperty(
"AUTOMOC_TARGETS_FOLDER");
- if (automocFolder && *automocFolder)
+ if (!autogenFolder)
{
- automocTarget->SetProperty("FOLDER", automocFolder);
+ autogenFolder = makefile->GetCMakeInstance()->GetProperty(
+ "AUTOGEN_TARGETS_FOLDER");
+ }
+ if (autogenFolder && *autogenFolder)
+ {
+ autogenTarget->SetProperty("FOLDER", autogenFolder);
}
else
{
// inherit FOLDER property from target (#13688)
- copyTargetProperty(automocTarget, target, "FOLDER");
+ copyTargetProperty(autogenTarget, target, "FOLDER");
}
- target->AddUtility(automocTargetName.c_str());
+ target->AddUtility(autogenTargetName.c_str());
+ }
+
+ std::map<std::string, std::string> configIncludes;
+ std::map<std::string, std::string> configDefines;
+
+ if (target->GetPropertyAsBool("AUTOMOC"))
+ {
+ this->SetupAutoMocTarget(target, autogenTargetName,
+ configIncludes, configDefines);
+ }
+ if (target->GetPropertyAsBool("AUTOUIC"))
+ {
+ this->SetupAutoUicTarget(target);
+ }
+ if (target->GetPropertyAsBool("AUTORCC"))
+ {
+ this->SetupAutoRccTarget(target);
}
- // configure a file to get all information to automoc at buildtime:
+ const char* cmakeRoot = makefile->GetSafeDefinition("CMAKE_ROOT");
+ std::string inputFile = cmakeRoot;
+ inputFile += "/Modules/AutogenInfo.cmake.in";
+ std::string outputFile = targetDir;
+ outputFile += "/AutogenInfo.cmake";
+ makefile->ConfigureFile(inputFile.c_str(), outputFile.c_str(),
+ false, true, false);
+
+ if (!configDefines.empty() || !configIncludes.empty())
+ {
+ std::ofstream infoFile(outputFile.c_str(), std::ios::app);
+ if ( !infoFile )
+ {
+ std::string error = "Internal CMake error when trying to open file: ";
+ error += outputFile.c_str();
+ error += " for writing.";
+ cmSystemTools::Error(error.c_str());
+ return;
+ }
+ if (!configDefines.empty())
+ {
+ for (std::map<std::string, std::string>::iterator
+ it = configDefines.begin(), end = configDefines.end();
+ it != end; ++it)
+ {
+ infoFile << "set(AM_MOC_COMPILE_DEFINITIONS_" << it->first <<
+ " " << it->second << ")\n";
+ }
+ }
+ if (!configIncludes.empty())
+ {
+ for (std::map<std::string, std::string>::iterator
+ it = configIncludes.begin(), end = configIncludes.end();
+ it != end; ++it)
+ {
+ infoFile << "set(AM_MOC_INCLUDES_" << it->first <<
+ " " << it->second << ")\n";
+ }
+ }
+ }
+}
+
+void cmQtAutoGenerators::SetupAutoMocTarget(cmTarget* target,
+ const std::string &autogenTargetName,
+ std::map<std::string, std::string> &configIncludes,
+ std::map<std::string, std::string> &configDefines)
+{
+ cmMakefile* makefile = target->GetMakefile();
+
std::string _moc_files;
std::string _moc_headers;
const char* sepFiles = "";
@@ -293,6 +414,9 @@ void cmQtAutomoc::SetupAutomocTarget(cmTarget* target)
const std::vector<cmSourceFile*>& srcFiles = target->GetSourceFiles();
+ std::string skip_moc;
+ const char *sep = "";
+
for(std::vector<cmSourceFile*>::const_iterator fileIt = srcFiles.begin();
fileIt != srcFiles.end();
++fileIt)
@@ -303,41 +427,46 @@ void cmQtAutomoc::SetupAutomocTarget(cmTarget* target)
bool skip = cmSystemTools::IsOn(sf->GetPropertyForUser("SKIP_AUTOMOC"));
bool generated = cmSystemTools::IsOn(sf->GetPropertyForUser("GENERATED"));
- if ((skip==false) && (generated == false))
+ if (!generated)
{
- std::string ext = sf->GetExtension();
- cmSystemTools::FileFormat fileType = cmSystemTools::GetFileFormat(
- ext.c_str());
- if (fileType == cmSystemTools::CXX_FILE_FORMAT)
+ if (skip)
{
- _moc_files += sepFiles;
- _moc_files += absFile;
- sepFiles = ";";
+ skip_moc += sep;
+ skip_moc += absFile;
+ sep = ";";
}
- else if (fileType == cmSystemTools::HEADER_FILE_FORMAT)
+ else
{
- _moc_headers += sepHeaders;
- _moc_headers += absFile;
- sepHeaders = ";";
+ std::string ext = sf->GetExtension();
+ 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 = ";";
+ }
}
}
}
const char* tmp = target->GetProperty("AUTOMOC_MOC_OPTIONS");
std::string _moc_options = (tmp!=0 ? tmp : "");
-
- // forget the variables added here afterwards again:
- cmMakefile::ScopePushPop varScope(makefile);
- static_cast<void>(varScope);
-
- makefile->AddDefinition("_moc_target_name",
- cmLocalGenerator::EscapeForCMake(automocTargetName.c_str()).c_str());
makefile->AddDefinition("_moc_options",
cmLocalGenerator::EscapeForCMake(_moc_options.c_str()).c_str());
makefile->AddDefinition("_moc_files",
cmLocalGenerator::EscapeForCMake(_moc_files.c_str()).c_str());
+ makefile->AddDefinition("_skip_moc",
+ cmLocalGenerator::EscapeForCMake(skip_moc.c_str()).c_str());
makefile->AddDefinition("_moc_headers",
cmLocalGenerator::EscapeForCMake(_moc_headers.c_str()).c_str());
+ bool relaxedMode = makefile->IsOn("CMAKE_AUTOMOC_RELAXED_MODE");
makefile->AddDefinition("_moc_relaxed_mode", relaxedMode ? "TRUE" : "FALSE");
std::string _moc_incs;
@@ -352,9 +481,6 @@ void cmQtAutomoc::SetupAutomocTarget(cmTarget* target)
makefile->AddDefinition("_moc_compile_defs",
cmLocalGenerator::EscapeForCMake(_moc_compile_defs.c_str()).c_str());
- std::map<std::string, std::string> configIncludes;
- std::map<std::string, std::string> configDefines;
-
for (std::vector<std::string>::const_iterator li = configs.begin();
li != configs.end(); ++li)
{
@@ -383,33 +509,17 @@ void cmQtAutomoc::SetupAutomocTarget(cmTarget* target)
}
}
- const char *qtVersion = makefile->GetDefinition("Qt5Core_VERSION_MAJOR");
- if (!qtVersion)
- {
- qtVersion = makefile->GetDefinition("QT_VERSION_MAJOR");
- }
- if (const char *targetQtVersion =
- target->GetLinkInterfaceDependentStringProperty("QT_MAJOR_VERSION", 0))
- {
- qtVersion = targetQtVersion;
- }
- if (qtVersion)
- {
- makefile->AddDefinition("_target_qt_version", qtVersion);
- }
-
- {
const char *qtMoc = makefile->GetSafeDefinition("QT_MOC_EXECUTABLE");
makefile->AddDefinition("_qt_moc_executable", qtMoc);
- }
+ const char *qtVersion = makefile->GetDefinition("_target_qt_version");
if (strcmp(qtVersion, "5") == 0)
{
cmTarget *qt5Moc = makefile->FindTargetToUse("Qt5::moc");
if (!qt5Moc)
{
cmSystemTools::Error("Qt5::moc target not found ",
- automocTargetName.c_str());
+ autogenTargetName.c_str());
return;
}
makefile->AddDefinition("_qt_moc_executable", qt5Moc->GetLocation(0));
@@ -419,68 +529,338 @@ void cmQtAutomoc::SetupAutomocTarget(cmTarget* target)
if (strcmp(qtVersion, "4") != 0)
{
cmSystemTools::Error("The CMAKE_AUTOMOC feature supports only Qt 4 and "
- "Qt 5 ", automocTargetName.c_str());
+ "Qt 5 ", autogenTargetName.c_str());
}
}
+}
- const char* cmakeRoot = makefile->GetSafeDefinition("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);
+void cmQtAutoGenerators::MergeUicOptions(std::vector<std::string> &opts,
+ const std::vector<std::string> &fileOpts,
+ bool isQt5)
+{
+ static const char* valueOptions[] = {
+ "tr",
+ "translate",
+ "postfix",
+ "generator",
+ "g"
+ };
+ std::vector<std::string> extraOpts;
+ for(std::vector<std::string>::const_iterator it = fileOpts.begin();
+ it != fileOpts.end(); ++it)
+ {
+ std::vector<std::string>::iterator existingIt
+ = std::find(opts.begin(), opts.end(), *it);
+ if (existingIt != opts.end())
+ {
+ const char *o = it->c_str();
+ if (*o == '-')
+ {
+ ++o;
+ }
+ if (isQt5 && *o == '-')
+ {
+ ++o;
+ }
+ if (std::find_if(cmArrayBegin(valueOptions), cmArrayEnd(valueOptions),
+ cmStrCmp(o)) != cmArrayEnd(valueOptions))
+ {
+ assert(existingIt + 1 != opts.end());
+ *(existingIt + 1) = *(it + 1);
+ ++it;
+ }
+ }
+ else
+ {
+ extraOpts.push_back(*it);
+ }
+ }
+ opts.insert(opts.end(), extraOpts.begin(), extraOpts.end());
+}
- if (!configDefines.empty() || !configIncludes.empty())
+void cmQtAutoGenerators::SetupAutoUicTarget(cmTarget* target)
+{
+ cmMakefile *makefile = target->GetMakefile();
+
+ const char *qtUic = makefile->GetSafeDefinition("QT_UIC_EXECUTABLE");
+ makefile->AddDefinition("_qt_uic_executable", qtUic);
+
+ const std::vector<cmSourceFile*>& srcFiles = target->GetSourceFiles();
+
+ std::string skip_uic;
+ const char *sep = "";
+
+ bool skip = target->GetPropertyAsBool("SKIP_AUTOUIC");
+
+ std::set<cmStdString> skipped;
+
+ for(std::vector<cmSourceFile*>::const_iterator fileIt = srcFiles.begin();
+ fileIt != srcFiles.end();
+ ++fileIt)
{
- std::ofstream infoFile(outputFile.c_str(), std::ios::app);
- if ( !infoFile )
+ cmSourceFile* sf = *fileIt;
+ std::string absFile = cmsys::SystemTools::GetRealPath(
+ sf->GetFullPath().c_str());
+ if (!skip)
{
- std::string error = "Internal CMake error when trying to open file: ";
- error += outputFile.c_str();
- error += " for writing.";
- cmSystemTools::Error(error.c_str());
- return;
+ skip = cmSystemTools::IsOn(sf->GetPropertyForUser("SKIP_AUTOUIC"));
}
- if (!configDefines.empty())
+
+ if (skip)
{
- for (std::map<std::string, std::string>::iterator
- it = configDefines.begin(), end = configDefines.end();
- it != end; ++it)
+ skip_uic += sep;
+ skip_uic += absFile;
+ sep = ";";
+ skipped.insert(absFile);
+ }
+ }
+
+ makefile->AddDefinition("_skip_uic",
+ cmLocalGenerator::EscapeForCMake(skip_uic.c_str()).c_str());
+
+ std::vector<cmSourceFile*> uiFilesWithOptions
+ = makefile->GetQtUiFilesWithOptions();
+
+ std::string uiFileFiles;
+ std::string uiFileOptions;
+ sep = "";
+
+ const char *qtVersion = makefile->GetDefinition("_target_qt_version");
+
+ if (const char* opts = target->GetProperty("AUTOUIC_OPTIONS"))
+ {
+ makefile->AddDefinition("_uic_target_options",
+ cmLocalGenerator::EscapeForCMake(opts).c_str());
+ }
+
+ for(std::vector<cmSourceFile*>::const_iterator fileIt =
+ uiFilesWithOptions.begin();
+ fileIt != uiFilesWithOptions.end();
+ ++fileIt)
+ {
+ cmSourceFile* sf = *fileIt;
+ std::string absFile = cmsys::SystemTools::GetRealPath(
+ sf->GetFullPath().c_str());
+
+ if (!skipped.insert(absFile).second)
+ {
+ continue;
+ }
+ uiFileFiles += sep;
+ uiFileFiles += absFile;
+ uiFileOptions += sep;
+ std::string opts = sf->GetProperty("AUTOUIC_OPTIONS");
+ cmSystemTools::ReplaceString(opts, ";", "@list_sep@");
+ uiFileOptions += opts;
+ sep = ";";
+ }
+
+ makefile->AddDefinition("_qt_uic_options_files",
+ cmLocalGenerator::EscapeForCMake(uiFileFiles.c_str()).c_str());
+ makefile->AddDefinition("_qt_uic_options_options",
+ cmLocalGenerator::EscapeForCMake(uiFileOptions.c_str()).c_str());
+
+ const char* targetName = target->GetName();
+ if (strcmp(qtVersion, "5") == 0)
+ {
+ cmTarget *qt5Uic = makefile->FindTargetToUse("Qt5::uic");
+ if (!qt5Uic)
+ {
+ // Project does not use Qt5Widgets, but has AUTOUIC ON anyway
+ makefile->RemoveDefinition("_qt_uic_executable");
+ }
+ else
+ {
+ makefile->AddDefinition("_qt_uic_executable", qt5Uic->GetLocation(0));
+ }
+ }
+ else
+ {
+ if (strcmp(qtVersion, "4") != 0)
+ {
+ cmSystemTools::Error("The CMAKE_AUTOUIC feature supports only Qt 4 and "
+ "Qt 5 ", targetName);
+ }
+ }
+}
+
+void cmQtAutoGenerators::MergeRccOptions(std::vector<std::string> &opts,
+ const std::vector<std::string> &fileOpts,
+ bool isQt5)
+{
+ static const char* valueOptions[] = {
+ "name",
+ "root",
+ "compress",
+ "threshold"
+ };
+ std::vector<std::string> extraOpts;
+ for(std::vector<std::string>::const_iterator it = fileOpts.begin();
+ it != fileOpts.end(); ++it)
+ {
+ std::vector<std::string>::iterator existingIt
+ = std::find(opts.begin(), opts.end(), *it);
+ if (existingIt != opts.end())
+ {
+ const char *o = it->c_str();
+ if (*o == '-')
{
- infoFile << "set(AM_MOC_COMPILE_DEFINITIONS_" << it->first <<
- " " << it->second << ")\n";
+ ++o;
+ }
+ if (isQt5 && *o == '-')
+ {
+ ++o;
+ }
+ if (std::find_if(cmArrayBegin(valueOptions), cmArrayEnd(valueOptions),
+ cmStrCmp(o)) != cmArrayEnd(valueOptions))
+ {
+ assert(existingIt + 1 != opts.end());
+ *(existingIt + 1) = *(it + 1);
+ ++it;
}
}
- if (!configIncludes.empty())
+ else
{
- for (std::map<std::string, std::string>::iterator
- it = configIncludes.begin(), end = configIncludes.end();
- it != end; ++it)
+ extraOpts.push_back(*it);
+ }
+ }
+ opts.insert(opts.end(), extraOpts.begin(), extraOpts.end());
+}
+
+void cmQtAutoGenerators::SetupAutoRccTarget(cmTarget* target)
+{
+ std::string _rcc_files;
+ const char* sepRccFiles = "";
+ cmMakefile *makefile = target->GetMakefile();
+
+ std::vector<cmSourceFile*> newFiles;
+
+ const std::vector<cmSourceFile*>& srcFiles = target->GetSourceFiles();
+
+ std::string rccFileFiles;
+ std::string rccFileOptions;
+ const char *sep = "";
+
+ const char *qtVersion = makefile->GetDefinition("_target_qt_version");
+
+ std::vector<std::string> rccOptions;
+ if (const char* opts = target->GetProperty("AUTORCC_OPTIONS"))
+ {
+ cmSystemTools::ExpandListArgument(opts, rccOptions);
+ }
+
+ for(std::vector<cmSourceFile*>::const_iterator fileIt = srcFiles.begin();
+ fileIt != srcFiles.end();
+ ++fileIt)
+ {
+ cmSourceFile* sf = *fileIt;
+ std::string ext = sf->GetExtension();
+ if (ext == "qrc")
+ {
+ std::string absFile = cmsys::SystemTools::GetRealPath(
+ sf->GetFullPath().c_str());
+ bool skip = cmSystemTools::IsOn(sf->GetPropertyForUser("SKIP_AUTORCC"));
+
+ if (!skip)
{
- infoFile << "set(AM_MOC_INCLUDES_" << it->first <<
- " " << it->second << ")\n";
+ _rcc_files += sepRccFiles;
+ _rcc_files += absFile;
+ sepRccFiles = ";";
+
+ std::string basename = cmsys::SystemTools::
+ GetFilenameWithoutLastExtension(absFile);
+
+ std::string rcc_output_file = makefile->GetCurrentOutputDirectory();
+ rcc_output_file += "/qrc_" + basename + ".cpp";
+ makefile->AppendProperty("ADDITIONAL_MAKE_CLEAN_FILES",
+ rcc_output_file.c_str(), false);
+ cmSourceFile* rccCppSource
+ = makefile->GetOrCreateSource(rcc_output_file.c_str(), true);
+ newFiles.push_back(rccCppSource);
+
+ if (const char *prop = sf->GetProperty("AUTORCC_OPTIONS"))
+ {
+ std::vector<std::string> optsVec;
+ cmSystemTools::ExpandListArgument(prop, optsVec);
+ this->MergeRccOptions(rccOptions, optsVec,
+ strcmp(qtVersion, "5") == 0);
+ }
+
+ if (!rccOptions.empty())
+ {
+ rccFileFiles += sep;
+ rccFileFiles += absFile;
+ rccFileOptions += sep;
+ }
+ const char *listSep = "";
+ for(std::vector<std::string>::const_iterator it = rccOptions.begin();
+ it != rccOptions.end();
+ ++it)
+ {
+ rccFileOptions += listSep;
+ rccFileOptions += *it;
+ listSep = "@list_sep@";
+ }
+ sep = ";";
}
}
}
-}
+ for(std::vector<cmSourceFile*>::const_iterator fileIt = newFiles.begin();
+ fileIt != newFiles.end();
+ ++fileIt)
+ {
+ target->AddSourceFile(*fileIt);
+ }
+
+ makefile->AddDefinition("_rcc_files",
+ cmLocalGenerator::EscapeForCMake(_rcc_files.c_str()).c_str());
-bool cmQtAutomoc::Run(const char* targetDirectory, const char *config)
+ makefile->AddDefinition("_qt_rcc_options_files",
+ cmLocalGenerator::EscapeForCMake(rccFileFiles.c_str()).c_str());
+ makefile->AddDefinition("_qt_rcc_options_options",
+ cmLocalGenerator::EscapeForCMake(rccFileOptions.c_str()).c_str());
+
+ const char *qtRcc = makefile->GetSafeDefinition("QT_RCC_EXECUTABLE");
+ makefile->AddDefinition("_qt_rcc_executable", qtRcc);
+
+ const char* targetName = target->GetName();
+ if (strcmp(qtVersion, "5") == 0)
+ {
+ cmTarget *qt5Rcc = makefile->FindTargetToUse("Qt5::rcc");
+ if (!qt5Rcc)
+ {
+ cmSystemTools::Error("Qt5::rcc target not found ",
+ targetName);
+ return;
+ }
+ makefile->AddDefinition("_qt_rcc_executable", qt5Rcc->GetLocation(0));
+ }
+ else
+ {
+ if (strcmp(qtVersion, "4") != 0)
+ {
+ cmSystemTools::Error("The CMAKE_AUTORCC feature supports only Qt 4 and "
+ "Qt 5 ", targetName);
+ }
+ }
+}
+
+bool cmQtAutoGenerators::Run(const char* targetDirectory, const char *config)
{
bool success = true;
cmake cm;
cmGlobalGenerator* gg = this->CreateGlobalGenerator(&cm, targetDirectory);
cmMakefile* makefile = gg->GetCurrentLocalGenerator()->GetMakefile();
- this->ReadAutomocInfoFile(makefile, targetDirectory, config);
+ this->ReadAutogenInfoFile(makefile, targetDirectory, config);
this->ReadOldMocDefinitionsFile(makefile, targetDirectory);
this->Init();
if (this->QtMajorVersion == "4" || this->QtMajorVersion == "5")
{
- success = this->RunAutomoc(makefile);
+ success = this->RunAutogen(makefile);
}
this->WriteOldMocDefinitionsFile(targetDirectory);
@@ -492,7 +872,7 @@ bool cmQtAutomoc::Run(const char* targetDirectory, const char *config)
}
-cmGlobalGenerator* cmQtAutomoc::CreateGlobalGenerator(cmake* cm,
+cmGlobalGenerator* cmQtAutoGenerators::CreateGlobalGenerator(cmake* cm,
const char* targetDirectory)
{
cmGlobalGenerator* gg = new cmGlobalGenerator();
@@ -509,13 +889,13 @@ cmGlobalGenerator* cmQtAutomoc::CreateGlobalGenerator(cmake* cm,
}
-bool cmQtAutomoc::ReadAutomocInfoFile(cmMakefile* makefile,
+bool cmQtAutoGenerators::ReadAutogenInfoFile(cmMakefile* makefile,
const char* targetDirectory,
const char *config)
{
std::string filename(cmSystemTools::CollapseFullPath(targetDirectory));
cmSystemTools::ConvertToUnixSlashes(filename);
- filename += "/AutomocInfo.cmake";
+ filename += "/AutogenInfo.cmake";
if (!makefile->ReadListFile(0, filename.c_str()))
{
@@ -530,12 +910,17 @@ bool cmQtAutomoc::ReadAutomocInfoFile(cmMakefile* makefile,
"AM_Qt5Core_VERSION_MAJOR");
}
this->Sources = makefile->GetSafeDefinition("AM_SOURCES");
+ this->RccSources = makefile->GetSafeDefinition("AM_RCC_SOURCES");
+ this->SkipMoc = makefile->GetSafeDefinition("AM_SKIP_MOC");
+ this->SkipUic = makefile->GetSafeDefinition("AM_SKIP_UIC");
this->Headers = makefile->GetSafeDefinition("AM_HEADERS");
this->IncludeProjectDirsBefore = makefile->IsOn(
"AM_CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE");
this->Srcdir = makefile->GetSafeDefinition("AM_CMAKE_CURRENT_SOURCE_DIR");
this->Builddir = makefile->GetSafeDefinition("AM_CMAKE_CURRENT_BINARY_DIR");
this->MocExecutable = makefile->GetSafeDefinition("AM_QT_MOC_EXECUTABLE");
+ this->UicExecutable = makefile->GetSafeDefinition("AM_QT_UIC_EXECUTABLE");
+ this->RccExecutable = makefile->GetSafeDefinition("AM_QT_RCC_EXECUTABLE");
std::string compileDefsPropOrig = "AM_MOC_COMPILE_DEFINITIONS";
std::string compileDefsProp = compileDefsPropOrig;
if(config)
@@ -561,6 +946,53 @@ bool cmQtAutomoc::ReadAutomocInfoFile(cmMakefile* makefile,
this->ProjectSourceDir = makefile->GetSafeDefinition("AM_CMAKE_SOURCE_DIR");
this->TargetName = makefile->GetSafeDefinition("AM_TARGET_NAME");
+ {
+ const char *uicOptionsFiles
+ = makefile->GetSafeDefinition("AM_UIC_OPTIONS_FILES");
+ const char *uicTargetOptions
+ = makefile->GetSafeDefinition("AM_UIC_TARGET_OPTIONS");
+ cmSystemTools::ExpandListArgument(uicTargetOptions, this->UicTargetOptions);
+ const char *uicOptionsOptions
+ = makefile->GetSafeDefinition("AM_UIC_OPTIONS_OPTIONS");
+ std::vector<std::string> uicFilesVec;
+ cmSystemTools::ExpandListArgument(uicOptionsFiles, uicFilesVec);
+ std::vector<std::string> uicOptionsVec;
+ cmSystemTools::ExpandListArgument(uicOptionsOptions, uicOptionsVec);
+ if (uicFilesVec.size() != uicOptionsVec.size())
+ {
+ return false;
+ }
+ for (std::vector<std::string>::iterator fileIt = uicFilesVec.begin(),
+ optionIt = uicOptionsVec.begin();
+ fileIt != uicFilesVec.end();
+ ++fileIt, ++optionIt)
+ {
+ cmSystemTools::ReplaceString(*optionIt, "@list_sep@", ";");
+ this->UicOptions[*fileIt] = *optionIt;
+ }
+ }
+ {
+ const char *rccOptionsFiles
+ = makefile->GetSafeDefinition("AM_RCC_OPTIONS_FILES");
+ const char *rccOptionsOptions
+ = makefile->GetSafeDefinition("AM_RCC_OPTIONS_OPTIONS");
+ std::vector<std::string> rccFilesVec;
+ cmSystemTools::ExpandListArgument(rccOptionsFiles, rccFilesVec);
+ std::vector<std::string> rccOptionsVec;
+ cmSystemTools::ExpandListArgument(rccOptionsOptions, rccOptionsVec);
+ if (rccFilesVec.size() != rccOptionsVec.size())
+ {
+ return false;
+ }
+ for (std::vector<std::string>::iterator fileIt = rccFilesVec.begin(),
+ optionIt = rccOptionsVec.begin();
+ fileIt != rccFilesVec.end();
+ ++fileIt, ++optionIt)
+ {
+ cmSystemTools::ReplaceString(*optionIt, "@list_sep@", ";");
+ this->RccOptions[*fileIt] = *optionIt;
+ }
+ }
this->CurrentCompileSettingsStr = this->MakeCompileSettingsString(makefile);
this->RelaxedMode = makefile->IsOn("AM_RELAXED_MODE");
@@ -569,7 +1001,7 @@ bool cmQtAutomoc::ReadAutomocInfoFile(cmMakefile* makefile,
}
-std::string cmQtAutomoc::MakeCompileSettingsString(cmMakefile* makefile)
+std::string cmQtAutoGenerators::MakeCompileSettingsString(cmMakefile* makefile)
{
std::string s;
s += makefile->GetSafeDefinition("AM_MOC_COMPILE_DEFINITIONS");
@@ -586,7 +1018,7 @@ std::string cmQtAutomoc::MakeCompileSettingsString(cmMakefile* makefile)
}
-bool cmQtAutomoc::ReadOldMocDefinitionsFile(cmMakefile* makefile,
+bool cmQtAutoGenerators::ReadOldMocDefinitionsFile(cmMakefile* makefile,
const char* targetDirectory)
{
std::string filename(cmSystemTools::CollapseFullPath(targetDirectory));
@@ -602,7 +1034,8 @@ bool cmQtAutomoc::ReadOldMocDefinitionsFile(cmMakefile* makefile,
}
-void cmQtAutomoc::WriteOldMocDefinitionsFile(const char* targetDirectory)
+void
+cmQtAutoGenerators::WriteOldMocDefinitionsFile(const char* targetDirectory)
{
std::string filename(cmSystemTools::CollapseFullPath(targetDirectory));
cmSystemTools::ConvertToUnixSlashes(filename);
@@ -619,7 +1052,7 @@ void cmQtAutomoc::WriteOldMocDefinitionsFile(const char* targetDirectory)
}
-void cmQtAutomoc::Init()
+void cmQtAutoGenerators::Init()
{
this->OutMocCppFilename = this->Builddir;
this->OutMocCppFilename += this->TargetName;
@@ -706,7 +1139,7 @@ void cmQtAutomoc::Init()
}
-bool cmQtAutomoc::RunAutomoc(cmMakefile* makefile)
+bool cmQtAutoGenerators::RunAutogen(cmMakefile* makefile)
{
if (!cmsys::SystemTools::FileExists(this->OutMocCppFilename.c_str())
|| (this->OldCompileSettingsStr != this->CurrentCompileSettingsStr))
@@ -733,26 +1166,56 @@ bool cmQtAutomoc::RunAutomoc(cmMakefile* makefile)
const std::vector<std::string>& headerExtensions =
makefile->GetHeaderExtensions();
+ std::vector<std::string> includedUis;
+ std::vector<std::string> skippedUis;
+ std::vector<std::string> uicSkipped;
+ cmSystemTools::ExpandListArgument(this->SkipUic, uicSkipped);
+
for (std::vector<std::string>::const_iterator it = sourceFiles.begin();
it != sourceFiles.end();
++it)
{
+ const bool skipUic = std::find(uicSkipped.begin(), uicSkipped.end(), *it)
+ != uicSkipped.end();
+ std::vector<std::string>& uiFiles = skipUic ? skippedUis : includedUis;
const std::string &absFilename = *it;
if (this->Verbose)
{
- std::cout << "AUTOMOC: Checking " << absFilename << std::endl;
+ std::cout << "AUTOGEN: Checking " << absFilename << std::endl;
}
if (this->RelaxedMode)
{
- this->ParseCppFile(absFilename, headerExtensions, includedMocs);
+ this->ParseCppFile(absFilename, headerExtensions, includedMocs,
+ uiFiles);
}
else
{
- this->StrictParseCppFile(absFilename, headerExtensions, includedMocs);
+ this->StrictParseCppFile(absFilename, headerExtensions, includedMocs,
+ uiFiles);
}
this->SearchHeadersForCppFile(absFilename, headerExtensions, headerFiles);
}
+ {
+ std::vector<std::string> mocSkipped;
+ cmSystemTools::ExpandListArgument(this->SkipMoc, mocSkipped);
+ for (std::vector<std::string>::const_iterator it = mocSkipped.begin();
+ it != mocSkipped.end();
+ ++it)
+ {
+ if (std::find(uicSkipped.begin(), uicSkipped.end(), *it)
+ != uicSkipped.end())
+ {
+ const std::string &absFilename = *it;
+ if (this->Verbose)
+ {
+ std::cout << "AUTOGEN: Checking " << absFilename << std::endl;
+ }
+ this->ParseForUic(absFilename, includedUis);
+ }
+ }
+ }
+
std::vector<std::string> headerFilesVec;
cmSystemTools::ExpandListArgument(this->Headers, headerFilesVec);
for (std::vector<std::string>::const_iterator it = headerFilesVec.begin();
@@ -764,7 +1227,7 @@ bool cmQtAutomoc::RunAutomoc(cmMakefile* makefile)
// key = moc source filepath, value = moc output filename
std::map<std::string, std::string> notIncludedMocs;
- this->ParseHeaders(headerFiles, includedMocs, notIncludedMocs);
+ this->ParseHeaders(headerFiles, includedMocs, notIncludedMocs, includedUis);
// run moc on all the moc's that are #included in source files
for(std::map<std::string, std::string>::const_iterator
@@ -774,6 +1237,17 @@ bool cmQtAutomoc::RunAutomoc(cmMakefile* makefile)
{
this->GenerateMoc(it->first, it->second);
}
+ for(std::vector<std::string>::const_iterator it = includedUis.begin();
+ it != includedUis.end();
+ ++it)
+ {
+ this->GenerateUi(*it);
+ }
+
+ if(!this->RccExecutable.empty())
+ {
+ this->GenerateQrc();
+ }
cmsys_ios::stringstream outStream;
outStream << "/* This file is autogenerated, do not edit*/\n";
@@ -806,6 +1280,17 @@ bool cmQtAutomoc::RunAutomoc(cmMakefile* makefile)
std::cerr << "moc failed..."<< std::endl;
return false;
}
+
+ if (this->RunUicFailed)
+ {
+ std::cerr << "uic failed..."<< std::endl;
+ return false;
+ }
+ if (this->RunRccFailed)
+ {
+ std::cerr << "rcc failed..."<< std::endl;
+ return false;
+ }
outStream.flush();
std::string automocSource = outStream.str();
if (!automocCppChanged)
@@ -830,9 +1315,10 @@ bool cmQtAutomoc::RunAutomoc(cmMakefile* makefile)
}
-void cmQtAutomoc::ParseCppFile(const std::string& absFilename,
+void cmQtAutoGenerators::ParseCppFile(const std::string& absFilename,
const std::vector<std::string>& headerExtensions,
- std::map<std::string, std::string>& includedMocs)
+ std::map<std::string, std::string>& includedMocs,
+ std::vector<std::string> &includedUis)
{
cmsys::RegularExpression mocIncludeRegExp(
"[\n][ \t]*#[ \t]*include[ \t]+"
@@ -841,7 +1327,7 @@ void cmQtAutomoc::ParseCppFile(const std::string& absFilename,
const std::string contentsString = this->ReadAll(absFilename);
if (contentsString.empty())
{
- std::cerr << "AUTOMOC: warning: " << absFilename << ": file is empty\n"
+ std::cerr << "AUTOGEN: warning: " << absFilename << ": file is empty\n"
<< std::endl;
return;
}
@@ -901,7 +1387,7 @@ void cmQtAutomoc::ParseCppFile(const std::string& absFilename,
}
else
{
- std::cerr << "AUTOMOC: error: " << absFilename << " The file "
+ std::cerr << "AUTOGEN: error: " << absFilename << " The file "
<< "includes the moc file \"" << currentMoc << "\", "
<< "but could not find header \"" << basename
<< '{' << this->Join(headerExtensions, ',') << "}\" ";
@@ -932,7 +1418,7 @@ void cmQtAutomoc::ParseCppFile(const std::string& absFilename,
fileToMoc = headerToMoc;
if ((requiresMoc==false) &&(basename==scannedFileBasename))
{
- std::cerr << "AUTOMOC: warning: " << absFilename << ": The file "
+ std::cerr << "AUTOGEN: warning: " << absFilename << ": The file "
"includes the moc file \"" << currentMoc <<
"\", but does not contain a " << macroName
<< " macro. Running moc on "
@@ -943,7 +1429,7 @@ void cmQtAutomoc::ParseCppFile(const std::string& absFilename,
}
else
{
- std::cerr << "AUTOMOC: warning: " << absFilename << ": The file "
+ std::cerr << "AUTOGEN: warning: " << absFilename << ": The file "
"includes the moc file \"" << currentMoc <<
"\" instead of \"moc_" << basename << ".cpp\". "
"Running moc on "
@@ -955,7 +1441,7 @@ void cmQtAutomoc::ParseCppFile(const std::string& absFilename,
}
else
{
- std::cerr <<"AUTOMOC: error: " << absFilename << ": The file "
+ std::cerr <<"AUTOGEN: error: " << absFilename << ": The file "
"includes the moc file \"" << currentMoc <<
"\", which seems to be the moc file from a different "
"source file. CMake also could not find a matching "
@@ -973,6 +1459,7 @@ void cmQtAutomoc::ParseCppFile(const std::string& absFilename,
matchOffset += mocIncludeRegExp.end();
} while(mocIncludeRegExp.find(contentsString.c_str() + matchOffset));
}
+ this->ParseForUic(absFilename, contentsString, includedUis);
// In this case, check whether the scanned file itself contains a Q_OBJECT.
// If this is the case, the moc_foo.cpp should probably be generated from
@@ -983,7 +1470,7 @@ void cmQtAutomoc::ParseCppFile(const std::string& absFilename,
if (mocUnderscoreIncluded == true)
{
// this is for KDE4 compatibility:
- std::cerr << "AUTOMOC: warning: " << absFilename << ": The file "
+ std::cerr << "AUTOGEN: warning: " << absFilename << ": The file "
<< "contains a " << macroName << " macro, but does not "
"include "
<< "\"" << scannedFileBasename << ".moc\", but instead "
@@ -999,7 +1486,7 @@ void cmQtAutomoc::ParseCppFile(const std::string& absFilename,
else
{
// otherwise always error out since it will not compile:
- std::cerr << "AUTOMOC: error: " << absFilename << ": The file "
+ std::cerr << "AUTOGEN: error: " << absFilename << ": The file "
<< "contains a " << macroName << " macro, but does not "
"include "
<< "\"" << scannedFileBasename << ".moc\" !\n"
@@ -1011,9 +1498,10 @@ void cmQtAutomoc::ParseCppFile(const std::string& absFilename,
}
-void cmQtAutomoc::StrictParseCppFile(const std::string& absFilename,
+void cmQtAutoGenerators::StrictParseCppFile(const std::string& absFilename,
const std::vector<std::string>& headerExtensions,
- std::map<std::string, std::string>& includedMocs)
+ std::map<std::string, std::string>& includedMocs,
+ std::vector<std::string>& includedUis)
{
cmsys::RegularExpression mocIncludeRegExp(
"[\n][ \t]*#[ \t]*include[ \t]+"
@@ -1022,7 +1510,7 @@ void cmQtAutomoc::StrictParseCppFile(const std::string& absFilename,
const std::string contentsString = this->ReadAll(absFilename);
if (contentsString.empty())
{
- std::cerr << "AUTOMOC: warning: " << absFilename << ": file is empty\n"
+ std::cerr << "AUTOGEN: warning: " << absFilename << ": file is empty\n"
<< std::endl;
return;
}
@@ -1069,7 +1557,7 @@ void cmQtAutomoc::StrictParseCppFile(const std::string& absFilename,
}
else
{
- std::cerr << "AUTOMOC: error: " << absFilename << " The file "
+ std::cerr << "AUTOGEN: error: " << absFilename << " The file "
<< "includes the moc file \"" << currentMoc << "\", "
<< "but could not find header \"" << basename
<< '{' << this->Join(headerExtensions, ',') << "}\" ";
@@ -1090,7 +1578,7 @@ void cmQtAutomoc::StrictParseCppFile(const std::string& absFilename,
{
if (basename != scannedFileBasename)
{
- std::cerr <<"AUTOMOC: error: " << absFilename << ": The file "
+ std::cerr <<"AUTOGEN: error: " << absFilename << ": The file "
"includes the moc file \"" << currentMoc <<
"\", which seems to be the moc file from a different "
"source file. This is not supported. "
@@ -1104,6 +1592,7 @@ void cmQtAutomoc::StrictParseCppFile(const std::string& absFilename,
matchOffset += mocIncludeRegExp.end();
} while(mocIncludeRegExp.find(contentsString.c_str() + matchOffset));
}
+ this->ParseForUic(absFilename, contentsString, includedUis);
// In this case, check whether the scanned file itself contains a Q_OBJECT.
// If this is the case, the moc_foo.cpp should probably be generated from
@@ -1114,7 +1603,7 @@ void cmQtAutomoc::StrictParseCppFile(const std::string& absFilename,
macroName)))
{
// otherwise always error out since it will not compile:
- std::cerr << "AUTOMOC: error: " << absFilename << ": The file "
+ std::cerr << "AUTOGEN: error: " << absFilename << ": The file "
<< "contains a " << macroName << " macro, but does not include "
<< "\"" << scannedFileBasename << ".moc\" !\n"
<< std::endl;
@@ -1124,7 +1613,63 @@ void cmQtAutomoc::StrictParseCppFile(const std::string& absFilename,
}
-void cmQtAutomoc::SearchHeadersForCppFile(const std::string& absFilename,
+void cmQtAutoGenerators::ParseForUic(const std::string& absFilename,
+ std::vector<std::string>& includedUis)
+{
+ if (this->UicExecutable.empty())
+ {
+ return;
+ }
+ const std::string contentsString = this->ReadAll(absFilename);
+ if (contentsString.empty())
+ {
+ std::cerr << "AUTOGEN: warning: " << absFilename << ": file is empty\n"
+ << std::endl;
+ return;
+ }
+ this->ParseForUic(absFilename, contentsString, includedUis);
+}
+
+
+void cmQtAutoGenerators::ParseForUic(const std::string&,
+ const std::string& contentsString,
+ std::vector<std::string>& includedUis)
+{
+ if (this->UicExecutable.empty())
+ {
+ return;
+ }
+ cmsys::RegularExpression uiIncludeRegExp(
+ "[\n][ \t]*#[ \t]*include[ \t]+"
+ "[\"<](([^ \">]+/)?ui_[^ \">/]+\\.h)[\">]");
+
+ std::string::size_type matchOffset = 0;
+
+ matchOffset = 0;
+ if ((strstr(contentsString.c_str(), "ui_") != NULL)
+ && (uiIncludeRegExp.find(contentsString)))
+ {
+ do
+ {
+ const std::string currentUi = uiIncludeRegExp.match(1);
+
+ std::string basename = cmsys::SystemTools::
+ GetFilenameWithoutLastExtension(currentUi);
+
+ // basename should be the part of the ui filename used for
+ // finding the correct header, so we need to remove the ui_ part
+ basename = basename.substr(3);
+
+ includedUis.push_back(basename);
+
+ matchOffset += uiIncludeRegExp.end();
+ } while(uiIncludeRegExp.find(contentsString.c_str() + matchOffset));
+ }
+}
+
+
+void
+cmQtAutoGenerators::SearchHeadersForCppFile(const std::string& absFilename,
const std::vector<std::string>& headerExtensions,
std::set<std::string>& absHeaders)
{
@@ -1160,28 +1705,29 @@ void cmQtAutomoc::SearchHeadersForCppFile(const std::string& absFilename,
}
-void cmQtAutomoc::ParseHeaders(const std::set<std::string>& absHeaders,
+void cmQtAutoGenerators::ParseHeaders(const std::set<std::string>& absHeaders,
const std::map<std::string, std::string>& includedMocs,
- std::map<std::string, std::string>& notIncludedMocs)
+ std::map<std::string, std::string>& notIncludedMocs,
+ std::vector<std::string>& includedUis)
{
for(std::set<std::string>::const_iterator hIt=absHeaders.begin();
hIt!=absHeaders.end();
++hIt)
{
const std::string& headerName = *hIt;
+ const std::string contents = this->ReadAll(headerName);
if (includedMocs.find(headerName) == includedMocs.end())
{
if (this->Verbose)
{
- std::cout << "AUTOMOC: Checking " << headerName << std::endl;
+ std::cout << "AUTOGEN: Checking " << headerName << std::endl;
}
const std::string basename = cmsys::SystemTools::
GetFilenameWithoutLastExtension(headerName);
const std::string currentMoc = "moc_" + basename + ".cpp";
- const std::string contents = this->ReadAll(headerName);
std::string macroName;
if (requiresMocing(contents, macroName))
{
@@ -1189,12 +1735,11 @@ void cmQtAutomoc::ParseHeaders(const std::set<std::string>& absHeaders,
notIncludedMocs[headerName] = currentMoc;
}
}
+ this->ParseForUic(headerName, contents, includedUis);
}
-
}
-
-bool cmQtAutomoc::GenerateMoc(const std::string& sourceFile,
+bool cmQtAutoGenerators::GenerateMoc(const std::string& sourceFile,
const std::string& mocFileName)
{
const std::string mocFilePath = this->Builddir + mocFileName;
@@ -1260,7 +1805,7 @@ bool cmQtAutomoc::GenerateMoc(const std::string& sourceFile,
bool result = cmSystemTools::RunSingleCommand(command, &output, &retVal);
if (!result || retVal)
{
- std::cerr << "AUTOMOC: error: process for " << mocFilePath <<" failed:\n"
+ std::cerr << "AUTOGEN: error: process for " << mocFilePath <<" failed:\n"
<< output << std::endl;
this->RunMocFailed = true;
cmSystemTools::RemoveFile(mocFilePath.c_str());
@@ -1270,8 +1815,152 @@ bool cmQtAutomoc::GenerateMoc(const std::string& sourceFile,
return false;
}
+bool cmQtAutoGenerators::GenerateUi(const std::string& uiFileName)
+{
+ if (!cmsys::SystemTools::FileExists(this->Builddir.c_str(), false))
+ {
+ cmsys::SystemTools::MakeDirectory(this->Builddir.c_str());
+ }
+
+ std::string ui_output_file = "ui_" + uiFileName + ".h";
+ std::string ui_input_file = this->Srcdir + uiFileName + ".ui";
+
+ int sourceNewerThanUi = 0;
+ bool success = cmsys::SystemTools::FileTimeCompare(ui_input_file.c_str(),
+ (this->Builddir + ui_output_file).c_str(),
+ &sourceNewerThanUi);
+ if (this->GenerateAll || !success || sourceNewerThanUi >= 0)
+ {
+ std::string msg = "Generating ";
+ msg += ui_output_file;
+ cmSystemTools::MakefileColorEcho(cmsysTerminal_Color_ForegroundBlue
+ |cmsysTerminal_Color_ForegroundBold,
+ msg.c_str(), true, this->ColorOutput);
+
+ std::vector<cmStdString> command;
+ command.push_back(this->UicExecutable);
+
+ std::string options;
+ std::vector<std::string> opts = this->UicTargetOptions;
+ std::map<std::string, std::string>::const_iterator optionIt
+ = this->UicOptions.find(ui_input_file);
+ if (optionIt != this->UicOptions.end())
+ {
+ std::vector<std::string> fileOpts;
+ cmSystemTools::ExpandListArgument(optionIt->second, fileOpts);
+ this->MergeUicOptions(opts, fileOpts, this->QtMajorVersion == "5");
+ }
+ for(std::vector<std::string>::const_iterator optIt = opts.begin();
+ optIt != opts.end();
+ ++optIt)
+ {
+ command.push_back(*optIt);
+ }
+
+ command.push_back("-o");
+ command.push_back(this->Builddir + ui_output_file);
+ command.push_back(ui_input_file);
+
+ if (this->Verbose)
+ {
+ for(std::vector<cmStdString>::const_iterator cmdIt = command.begin();
+ cmdIt != command.end();
+ ++cmdIt)
+ {
+ std::cout << *cmdIt << " ";
+ }
+ std::cout << std::endl;
+ }
+ std::string output;
+ int retVal = 0;
+ bool result = cmSystemTools::RunSingleCommand(command, &output, &retVal);
+ if (!result || retVal)
+ {
+ std::cerr << "AUTOUIC: error: process for " << ui_output_file <<
+ " failed:\n" << output << std::endl;
+ this->RunUicFailed = true;
+ cmSystemTools::RemoveFile(ui_output_file.c_str());
+ return false;
+ }
+ return true;
+ }
+ return false;
+}
+
+bool cmQtAutoGenerators::GenerateQrc()
+{
+ std::vector<std::string> sourceFiles;
+ cmSystemTools::ExpandListArgument(this->RccSources, sourceFiles);
+
+ for(std::vector<std::string>::const_iterator si = sourceFiles.begin();
+ si != sourceFiles.end(); ++si)
+ {
+ std::string ext = cmsys::SystemTools::GetFilenameLastExtension(*si);
+
+ if (ext != ".qrc")
+ {
+ continue;
+ }
+ std::vector<cmStdString> command;
+ command.push_back(this->RccExecutable);
+
+ std::string basename = cmsys::SystemTools::
+ GetFilenameWithoutLastExtension(*si);
+
+ std::string rcc_output_file = this->Builddir + "qrc_" + basename + ".cpp";
+
+ int sourceNewerThanQrc = 0;
+ bool success = cmsys::SystemTools::FileTimeCompare(si->c_str(),
+ rcc_output_file.c_str(),
+ &sourceNewerThanQrc);
+ if (this->GenerateAll || !success || sourceNewerThanQrc >= 0)
+ {
+ std::string options;
+ std::map<std::string, std::string>::const_iterator optionIt
+ = this->RccOptions.find(*si);
+ if (optionIt != this->RccOptions.end())
+ {
+ std::vector<std::string> opts;
+ cmSystemTools::ExpandListArgument(optionIt->second, opts);
+ for(std::vector<std::string>::const_iterator optIt = opts.begin();
+ optIt != opts.end();
+ ++optIt)
+ {
+ command.push_back(*optIt);
+ }
+ }
+
+ command.push_back("-o");
+ command.push_back(rcc_output_file);
+ command.push_back(*si);
+
+ if (this->Verbose)
+ {
+ for(std::vector<cmStdString>::const_iterator cmdIt = command.begin();
+ cmdIt != command.end();
+ ++cmdIt)
+ {
+ std::cout << *cmdIt << " ";
+ }
+ std::cout << std::endl;
+ }
+ std::string output;
+ int retVal = 0;
+ bool result = cmSystemTools::RunSingleCommand(command, &output, &retVal);
+ if (!result || retVal)
+ {
+ std::cerr << "AUTORCC: error: process for " << rcc_output_file <<
+ " failed:\n" << output << std::endl;
+ this->RunRccFailed = true;
+ cmSystemTools::RemoveFile(rcc_output_file.c_str());
+ return false;
+ }
+ }
+ }
+ return true;
+}
-std::string cmQtAutomoc::Join(const std::vector<std::string>& lst,
+std::string cmQtAutoGenerators::Join(const std::vector<std::string>& lst,
char separator)
{
if (lst.empty())
@@ -1291,13 +1980,15 @@ std::string cmQtAutomoc::Join(const std::vector<std::string>& lst,
}
-bool cmQtAutomoc::StartsWith(const std::string& str, const std::string& with)
+bool cmQtAutoGenerators::StartsWith(const std::string& str,
+ const std::string& with)
{
return (str.substr(0, with.length()) == with);
}
-bool cmQtAutomoc::EndsWith(const std::string& str, const std::string& with)
+bool cmQtAutoGenerators::EndsWith(const std::string& str,
+ const std::string& with)
{
if (with.length() > (str.length()))
{
@@ -1307,7 +1998,7 @@ bool cmQtAutomoc::EndsWith(const std::string& str, const std::string& with)
}
-std::string cmQtAutomoc::ReadAll(const std::string& filename)
+std::string cmQtAutoGenerators::ReadAll(const std::string& filename)
{
std::ifstream file(filename.c_str());
cmsys_ios::stringstream stream;
diff --git a/Source/cmQtAutomoc.h b/Source/cmQtAutoGenerators.h
index ebeeb0e..696abc8 100644
--- a/Source/cmQtAutomoc.h
+++ b/Source/cmQtAutoGenerators.h
@@ -11,26 +11,33 @@
See the License for more information.
============================================================================*/
-#ifndef cmQtAutomoc_h
-#define cmQtAutomoc_h
+#ifndef cmQtAutoGenerators_h
+#define cmQtAutoGenerators_h
class cmGlobalGenerator;
class cmMakefile;
-class cmQtAutomoc
+class cmQtAutoGenerators
{
public:
- cmQtAutomoc();
+ cmQtAutoGenerators();
bool Run(const char* targetDirectory, const char *config);
bool InitializeMocSourceFile(cmTarget* target);
- void SetupAutomocTarget(cmTarget* target);
+ void SetupAutoGenerateTarget(cmTarget* target);
private:
+ void SetupAutoMocTarget(cmTarget* target,
+ const std::string &autogenTargetName,
+ std::map<std::string, std::string> &configIncludes,
+ std::map<std::string, std::string> &configDefines);
+ void SetupAutoUicTarget(cmTarget* target);
+ void SetupAutoRccTarget(cmTarget* target);
+
cmGlobalGenerator* CreateGlobalGenerator(cmake* cm,
const char* targetDirectory);
- bool ReadAutomocInfoFile(cmMakefile* makefile,
+ bool ReadAutogenInfoFile(cmMakefile* makefile,
const char* targetDirectory,
const char *config);
bool ReadOldMocDefinitionsFile(cmMakefile* makefile,
@@ -39,22 +46,34 @@ private:
std::string MakeCompileSettingsString(cmMakefile* makefile);
- bool RunAutomoc(cmMakefile* makefile);
+ bool RunAutogen(cmMakefile* makefile);
bool GenerateMoc(const std::string& sourceFile,
const std::string& mocFileName);
+ bool GenerateUi(const std::string& uiFileName);
+ bool GenerateQrc();
void ParseCppFile(const std::string& absFilename,
const std::vector<std::string>& headerExtensions,
- std::map<std::string, std::string>& includedMocs);
+ std::map<std::string, std::string>& includedMocs,
+ std::vector<std::string>& includedUis);
void StrictParseCppFile(const std::string& absFilename,
const std::vector<std::string>& headerExtensions,
- std::map<std::string, std::string>& includedMocs);
+ std::map<std::string, std::string>& includedMocs,
+ std::vector<std::string>& includedUis);
void SearchHeadersForCppFile(const std::string& absFilename,
const std::vector<std::string>& headerExtensions,
std::set<std::string>& absHeaders);
void ParseHeaders(const std::set<std::string>& absHeaders,
const std::map<std::string, std::string>& includedMocs,
- std::map<std::string, std::string>& notIncludedMocs);
+ std::map<std::string, std::string>& notIncludedMocs,
+ std::vector<std::string>& includedUis);
+
+ void ParseForUic(const std::string& fileName,
+ const std::string& contentsString,
+ std::vector<std::string>& includedUis);
+
+ void ParseForUic(const std::string& fileName,
+ std::vector<std::string>& includedUis);
void Init();
@@ -63,13 +82,24 @@ private:
bool StartsWith(const std::string& str, const std::string& with);
std::string ReadAll(const std::string& filename);
+ void MergeUicOptions(std::vector<std::string> &opts,
+ const std::vector<std::string> &fileOpts, bool isQt5);
+
+ void MergeRccOptions(std::vector<std::string> &opts,
+ const std::vector<std::string> &fileOpts, bool isQt5);
+
std::string QtMajorVersion;
std::string Sources;
+ std::string RccSources;
+ std::string SkipMoc;
+ std::string SkipUic;
std::string Headers;
bool IncludeProjectDirsBefore;
std::string Srcdir;
std::string Builddir;
std::string MocExecutable;
+ std::string UicExecutable;
+ std::string RccExecutable;
std::string MocCompileDefinitionsStr;
std::string MocIncludesStr;
std::string MocOptionsStr;
@@ -84,10 +114,15 @@ private:
std::list<std::string> MocIncludes;
std::list<std::string> MocDefinitions;
std::vector<std::string> MocOptions;
+ std::vector<std::string> UicTargetOptions;
+ std::map<std::string, std::string> UicOptions;
+ std::map<std::string, std::string> RccOptions;
bool Verbose;
bool ColorOutput;
bool RunMocFailed;
+ bool RunUicFailed;
+ bool RunRccFailed;
bool GenerateAll;
bool RelaxedMode;
diff --git a/Source/cmSourceFile.cxx b/Source/cmSourceFile.cxx
index d747309..ec98c2c 100644
--- a/Source/cmSourceFile.cxx
+++ b/Source/cmSourceFile.cxx
@@ -287,6 +287,17 @@ void cmSourceFile::SetProperty(const char* prop, const char* value)
}
this->Properties.SetProperty(prop, value, cmProperty::SOURCE_FILE);
+
+ std::string ext =
+ cmSystemTools::GetFilenameLastExtension(this->Location.GetName());
+ if (ext == ".ui")
+ {
+ cmMakefile* mf = this->Location.GetMakefile();
+ if (strcmp(prop, "AUTOUIC_OPTIONS") == 0)
+ {
+ mf->AddQtUiFileWithOptions(this);
+ }
+ }
}
//----------------------------------------------------------------------------
diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx
index ea0b504..59c407b 100644
--- a/Source/cmTarget.cxx
+++ b/Source/cmTarget.cxx
@@ -274,7 +274,11 @@ void cmTarget::SetMakefile(cmMakefile* mf)
this->SetPropertyDefault("GNUtoMS", 0);
this->SetPropertyDefault("OSX_ARCHITECTURES", 0);
this->SetPropertyDefault("AUTOMOC", 0);
+ this->SetPropertyDefault("AUTOUIC", 0);
+ this->SetPropertyDefault("AUTORCC", 0);
this->SetPropertyDefault("AUTOMOC_MOC_OPTIONS", 0);
+ this->SetPropertyDefault("AUTOUIC_OPTIONS", 0);
+ this->SetPropertyDefault("AUTORCC_OPTIONS", 0);
this->SetPropertyDefault("LINK_DEPENDS_NO_SHARED", 0);
this->SetPropertyDefault("LINK_INTERFACE_LIBRARIES", 0);
this->SetPropertyDefault("WIN32_EXECUTABLE", 0);
diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx
index 9814aea..26251b3 100644
--- a/Source/cmcmd.cxx
+++ b/Source/cmcmd.cxx
@@ -13,7 +13,7 @@
#include "cmMakefile.h"
#include "cmLocalGenerator.h"
#include "cmGlobalGenerator.h"
-#include "cmQtAutomoc.h"
+#include "cmQtAutoGenerators.h"
#include "cmVersion.h"
#if defined(CMAKE_BUILD_WITH_CMAKE)
@@ -632,12 +632,12 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
{
return cmcmd::ExecuteEchoColor(args);
}
- else if (args[1] == "cmake_automoc")
+ else if (args[1] == "cmake_autogen")
{
- cmQtAutomoc automoc;
+ cmQtAutoGenerators autogen;
const char *config = args[3].empty() ? 0 : args[3].c_str();
- bool automocSuccess = automoc.Run(args[2].c_str(), config);
- return automocSuccess ? 0 : 1;
+ bool autogenSuccess = autogen.Run(args[2].c_str(), config);
+ return autogenSuccess ? 0 : 1;
}
#endif