summaryrefslogtreecommitdiff
path: root/Source
diff options
context:
space:
mode:
authorSebastian Holtermann <sebholt@xwmw.org>2016-08-06 14:57:52 +0200
committerBrad King <brad.king@kitware.com>2016-08-10 13:21:33 -0400
commit4e9b97d7397fd526e6b4e4ce43dd305cb8341ac8 (patch)
tree17c2347fe0973fafe2e6f931075c737bf2668b43 /Source
parent41c9e14afb0bc7e68e4530f76329b7c11cdfa0e4 (diff)
downloadcmake-4e9b97d7397fd526e6b4e4ce43dd305cb8341ac8.tar.gz
QtAutogen: Allow multiple qrc files with the same name
Use cmFilePathUuid for qrc files.
Diffstat (limited to 'Source')
-rw-r--r--Source/cmQtAutoGeneratorInitializer.cxx76
-rw-r--r--Source/cmQtAutoGenerators.cxx62
-rw-r--r--Source/cmQtAutoGenerators.h3
3 files changed, 93 insertions, 48 deletions
diff --git a/Source/cmQtAutoGeneratorInitializer.cxx b/Source/cmQtAutoGeneratorInitializer.cxx
index d5634e8ba0..7efb333a79 100644
--- a/Source/cmQtAutoGeneratorInitializer.cxx
+++ b/Source/cmQtAutoGeneratorInitializer.cxx
@@ -13,6 +13,7 @@
#include "cmQtAutoGeneratorInitializer.h"
+#include "cmFilePathUuid.h"
#include "cmLocalGenerator.h"
#include "cmMakefile.h"
#include "cmSourceFile.h"
@@ -25,6 +26,34 @@
#include "cmGlobalVisualStudioGenerator.h"
#endif
+static std::string GetAutogenTargetName(cmGeneratorTarget const* target)
+{
+ std::string autogenTargetName = target->GetName();
+ autogenTargetName += "_automoc";
+ return autogenTargetName;
+}
+
+static std::string GetAutogenTargetDir(cmGeneratorTarget const* target)
+{
+ cmMakefile* makefile = target->Target->GetMakefile();
+ std::string targetDir = makefile->GetCurrentBinaryDirectory();
+ targetDir += makefile->GetCMakeInstance()->GetCMakeFilesDirectory();
+ targetDir += "/";
+ targetDir += GetAutogenTargetName(target);
+ targetDir += ".dir/";
+ return targetDir;
+}
+
+static std::string GetAutogenTargetBuildDir(cmGeneratorTarget const* target)
+{
+ cmMakefile* makefile = target->Target->GetMakefile();
+ std::string targetDir = makefile->GetCurrentBinaryDirectory();
+ targetDir += "/";
+ targetDir += GetAutogenTargetName(target);
+ targetDir += ".dir/";
+ return targetDir;
+}
+
static void SetupSourceFiles(cmGeneratorTarget const* target,
std::vector<std::string>& skipMoc,
std::vector<std::string>& mocSources,
@@ -38,6 +67,7 @@ static void SetupSourceFiles(cmGeneratorTarget const* target,
std::vector<std::string> newRccFiles;
+ cmFilePathUuid fpathUuid(makefile);
for (std::vector<cmSourceFile*>::const_iterator fileIt = srcFiles.begin();
fileIt != srcFiles.end(); ++fileIt) {
cmSourceFile* sf = *fileIt;
@@ -55,13 +85,12 @@ static void SetupSourceFiles(cmGeneratorTarget const* target,
if (target->GetPropertyAsBool("AUTORCC")) {
if (ext == "qrc" &&
!cmSystemTools::IsOn(sf->GetPropertyForUser("SKIP_AUTORCC"))) {
- std::string basename =
- cmsys::SystemTools::GetFilenameWithoutLastExtension(absFile);
- std::string rcc_output_dir = target->GetSupportDirectory();
- cmSystemTools::MakeDirectory(rcc_output_dir.c_str());
- std::string rcc_output_file = rcc_output_dir;
- rcc_output_file += "/qrc_" + basename + ".cpp";
+ std::string rcc_output_file = GetAutogenTargetBuildDir(target);
+ // Create output directory
+ cmSystemTools::MakeDirectory(rcc_output_file.c_str());
+ rcc_output_file += fpathUuid.get(absFile, "qrc_", ".cpp");
+
makefile->AppendProperty("ADDITIONAL_MAKE_CLEAN_FILES",
rcc_output_file.c_str(), false);
makefile->GetOrCreateSource(rcc_output_file, true);
@@ -365,24 +394,6 @@ static void MergeRccOptions(std::vector<std::string>& opts,
opts.insert(opts.end(), extraOpts.begin(), extraOpts.end());
}
-std::string GetAutogenTargetName(cmGeneratorTarget const* target)
-{
- std::string autogenTargetName = target->GetName();
- autogenTargetName += "_automoc";
- return autogenTargetName;
-}
-
-std::string GetAutogenTargetDir(cmGeneratorTarget const* target)
-{
- cmMakefile* makefile = target->Target->GetMakefile();
- std::string targetDir = makefile->GetCurrentBinaryDirectory();
- targetDir += makefile->GetCMakeInstance()->GetCMakeFilesDirectory();
- targetDir += "/";
- targetDir += GetAutogenTargetName(target);
- targetDir += ".dir/";
- return targetDir;
-}
-
static void copyTargetProperty(cmTarget* destinationTarget,
cmTarget* sourceTarget,
const std::string& propertyName)
@@ -737,6 +748,7 @@ void cmQtAutoGeneratorInitializer::InitializeAutogenTarget(
) {
std::vector<cmSourceFile*> srcFiles;
target->GetConfigCommonSourceFiles(srcFiles);
+ cmFilePathUuid fpathUuid(makefile);
for (std::vector<cmSourceFile*>::const_iterator fileIt = srcFiles.begin();
fileIt != srcFiles.end(); ++fileIt) {
cmSourceFile* sf = *fileIt;
@@ -747,15 +759,13 @@ void cmQtAutoGeneratorInitializer::InitializeAutogenTarget(
if (target->GetPropertyAsBool("AUTORCC")) {
if (ext == "qrc" &&
!cmSystemTools::IsOn(sf->GetPropertyForUser("SKIP_AUTORCC"))) {
- std::string basename =
- cmsys::SystemTools::GetFilenameWithoutLastExtension(absFile);
-
- std::string rcc_output_dir = target->GetSupportDirectory();
- cmSystemTools::MakeDirectory(rcc_output_dir.c_str());
- std::string rcc_output_file = rcc_output_dir;
- rcc_output_file += "/qrc_" + basename + ".cpp";
- rcc_output.push_back(rcc_output_file);
-
+ {
+ std::string rcc_output_file = GetAutogenTargetBuildDir(target);
+ // Create output directory
+ cmSystemTools::MakeDirectory(rcc_output_file.c_str());
+ rcc_output_file += fpathUuid.get(absFile, "qrc_", ".cpp");
+ rcc_output.push_back(rcc_output_file);
+ }
if (!cmSystemTools::IsOn(sf->GetPropertyForUser("GENERATED"))) {
if (qtMajorVersion == "5") {
ListQt5RccInputs(sf, target, depends);
diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx
index 33f7a54a9b..a261962a25 100644
--- a/Source/cmQtAutoGenerators.cxx
+++ b/Source/cmQtAutoGenerators.cxx
@@ -88,6 +88,23 @@ static std::string extractSubDir(const std::string& absPath,
return subDir;
}
+static bool FileNameIsUnique(const std::string& filePath,
+ const std::map<std::string, std::string>& fileMap)
+{
+ size_t count(0);
+ const std::string fileName = cmsys::SystemTools::GetFilenameName(filePath);
+ for (std::map<std::string, std::string>::const_iterator si = fileMap.begin();
+ si != fileMap.end(); ++si) {
+ if (cmsys::SystemTools::GetFilenameName(si->first) == fileName) {
+ ++count;
+ if (count > 1) {
+ return false;
+ }
+ }
+ }
+ return true;
+}
+
cmQtAutoGenerators::cmQtAutoGenerators()
: Verbose(cmsys::SystemTools::HasEnv("VERBOSE"))
, ColorOutput(true)
@@ -1257,15 +1274,18 @@ bool cmQtAutoGenerators::GenerateQrcFiles()
{
// generate single map with input / output names
std::map<std::string, std::string> qrcGenMap;
- for (std::vector<std::string>::const_iterator si = this->RccSources.begin();
- si != this->RccSources.end(); ++si) {
- const std::string ext = cmsys::SystemTools::GetFilenameLastExtension(*si);
- if (ext == ".qrc") {
- std::string basename =
- cmsys::SystemTools::GetFilenameWithoutLastExtension(*si);
- std::string qrcOutputFile = "CMakeFiles/" + this->OriginTargetName +
- ".dir/qrc_" + basename + ".cpp";
- qrcGenMap[*si] = qrcOutputFile;
+ {
+ cmFilePathUuid fpathUuid(this->Srcdir, this->Builddir,
+ this->ProjectSourceDir, this->ProjectBinaryDir);
+ for (std::vector<std::string>::const_iterator si =
+ this->RccSources.begin();
+ si != this->RccSources.end(); ++si) {
+ const std::string ext =
+ cmsys::SystemTools::GetFilenameLastExtension(*si);
+ if (ext == ".qrc") {
+ qrcGenMap[*si] =
+ (this->TargetBuildSubDir + fpathUuid.get(*si, "qrc_", ".cpp"));
+ }
}
}
@@ -1287,7 +1307,8 @@ bool cmQtAutoGenerators::GenerateQrcFiles()
for (std::map<std::string, std::string>::const_iterator si =
qrcGenMap.begin();
si != qrcGenMap.end(); ++si) {
- if (!this->GenerateQrc(si->first, si->second)) {
+ bool unique = FileNameIsUnique(si->first, qrcGenMap);
+ if (!this->GenerateQrc(si->first, si->second, unique)) {
if (this->RunRccFailed) {
return false;
}
@@ -1297,10 +1318,23 @@ bool cmQtAutoGenerators::GenerateQrcFiles()
}
bool cmQtAutoGenerators::GenerateQrc(const std::string& qrcInputFile,
- const std::string& qrcOutputFile)
+ const std::string& qrcOutputFile,
+ bool unique_n)
{
- const std::string basename =
- cmsys::SystemTools::GetFilenameWithoutLastExtension(qrcInputFile);
+ std::string symbolName;
+ if (unique_n) {
+ symbolName =
+ cmsys::SystemTools::GetFilenameWithoutLastExtension(qrcInputFile);
+ } else {
+ symbolName =
+ cmsys::SystemTools::GetFilenameWithoutLastExtension(qrcOutputFile);
+ // Remove "qrc_" at string begin
+ symbolName.erase(0, 4);
+ }
+ // Replace '-' with '_'. The former is valid for
+ // file names but not for symbol names.
+ std::replace(symbolName.begin(), symbolName.end(), '-', '_');
+
const std::string qrcBuildFile = this->Builddir + qrcOutputFile;
int sourceNewerThanQrc = 0;
@@ -1327,7 +1361,7 @@ bool cmQtAutoGenerators::GenerateQrc(const std::string& qrcInputFile,
}
command.push_back("-name");
- command.push_back(basename);
+ command.push_back(symbolName);
command.push_back("-o");
command.push_back(qrcBuildFile);
command.push_back(qrcInputFile);
diff --git a/Source/cmQtAutoGenerators.h b/Source/cmQtAutoGenerators.h
index 216b0b0346..fab2d1934b 100644
--- a/Source/cmQtAutoGenerators.h
+++ b/Source/cmQtAutoGenerators.h
@@ -51,7 +51,8 @@ private:
const std::string& uiOutputFile);
bool GenerateQrcFiles();
bool GenerateQrc(const std::string& qrcInputFile,
- const std::string& qrcOutputFile);
+ const std::string& qrcOutputFile, bool unique_n);
+
void ParseCppFile(
const std::string& absFilename,
const std::vector<std::string>& headerExtensions,