QtAutogen: Allow multiple qrc files with the same name

Use cmFilePathUuid for qrc files.
This commit is contained in:
Sebastian Holtermann 2016-08-06 14:57:52 +02:00 committed by Brad King
parent 41c9e14afb
commit 4e9b97d739
3 changed files with 93 additions and 48 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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,