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 "cmQtAutoGeneratorInitializer.h"
#include "cmFilePathUuid.h"
#include "cmLocalGenerator.h" #include "cmLocalGenerator.h"
#include "cmMakefile.h" #include "cmMakefile.h"
#include "cmSourceFile.h" #include "cmSourceFile.h"
@ -25,6 +26,34 @@
#include "cmGlobalVisualStudioGenerator.h" #include "cmGlobalVisualStudioGenerator.h"
#endif #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, static void SetupSourceFiles(cmGeneratorTarget const* target,
std::vector<std::string>& skipMoc, std::vector<std::string>& skipMoc,
std::vector<std::string>& mocSources, std::vector<std::string>& mocSources,
@ -38,6 +67,7 @@ static void SetupSourceFiles(cmGeneratorTarget const* target,
std::vector<std::string> newRccFiles; std::vector<std::string> newRccFiles;
cmFilePathUuid fpathUuid(makefile);
for (std::vector<cmSourceFile*>::const_iterator fileIt = srcFiles.begin(); for (std::vector<cmSourceFile*>::const_iterator fileIt = srcFiles.begin();
fileIt != srcFiles.end(); ++fileIt) { fileIt != srcFiles.end(); ++fileIt) {
cmSourceFile* sf = *fileIt; cmSourceFile* sf = *fileIt;
@ -55,13 +85,12 @@ static void SetupSourceFiles(cmGeneratorTarget const* target,
if (target->GetPropertyAsBool("AUTORCC")) { if (target->GetPropertyAsBool("AUTORCC")) {
if (ext == "qrc" && if (ext == "qrc" &&
!cmSystemTools::IsOn(sf->GetPropertyForUser("SKIP_AUTORCC"))) { !cmSystemTools::IsOn(sf->GetPropertyForUser("SKIP_AUTORCC"))) {
std::string basename =
cmsys::SystemTools::GetFilenameWithoutLastExtension(absFile);
std::string rcc_output_dir = target->GetSupportDirectory(); std::string rcc_output_file = GetAutogenTargetBuildDir(target);
cmSystemTools::MakeDirectory(rcc_output_dir.c_str()); // Create output directory
std::string rcc_output_file = rcc_output_dir; cmSystemTools::MakeDirectory(rcc_output_file.c_str());
rcc_output_file += "/qrc_" + basename + ".cpp"; rcc_output_file += fpathUuid.get(absFile, "qrc_", ".cpp");
makefile->AppendProperty("ADDITIONAL_MAKE_CLEAN_FILES", makefile->AppendProperty("ADDITIONAL_MAKE_CLEAN_FILES",
rcc_output_file.c_str(), false); rcc_output_file.c_str(), false);
makefile->GetOrCreateSource(rcc_output_file, true); 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()); 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, static void copyTargetProperty(cmTarget* destinationTarget,
cmTarget* sourceTarget, cmTarget* sourceTarget,
const std::string& propertyName) const std::string& propertyName)
@ -737,6 +748,7 @@ void cmQtAutoGeneratorInitializer::InitializeAutogenTarget(
) { ) {
std::vector<cmSourceFile*> srcFiles; std::vector<cmSourceFile*> srcFiles;
target->GetConfigCommonSourceFiles(srcFiles); target->GetConfigCommonSourceFiles(srcFiles);
cmFilePathUuid fpathUuid(makefile);
for (std::vector<cmSourceFile*>::const_iterator fileIt = srcFiles.begin(); for (std::vector<cmSourceFile*>::const_iterator fileIt = srcFiles.begin();
fileIt != srcFiles.end(); ++fileIt) { fileIt != srcFiles.end(); ++fileIt) {
cmSourceFile* sf = *fileIt; cmSourceFile* sf = *fileIt;
@ -747,15 +759,13 @@ void cmQtAutoGeneratorInitializer::InitializeAutogenTarget(
if (target->GetPropertyAsBool("AUTORCC")) { if (target->GetPropertyAsBool("AUTORCC")) {
if (ext == "qrc" && if (ext == "qrc" &&
!cmSystemTools::IsOn(sf->GetPropertyForUser("SKIP_AUTORCC"))) { !cmSystemTools::IsOn(sf->GetPropertyForUser("SKIP_AUTORCC"))) {
std::string basename = {
cmsys::SystemTools::GetFilenameWithoutLastExtension(absFile); std::string rcc_output_file = GetAutogenTargetBuildDir(target);
// Create output directory
std::string rcc_output_dir = target->GetSupportDirectory(); cmSystemTools::MakeDirectory(rcc_output_file.c_str());
cmSystemTools::MakeDirectory(rcc_output_dir.c_str()); rcc_output_file += fpathUuid.get(absFile, "qrc_", ".cpp");
std::string rcc_output_file = rcc_output_dir; rcc_output.push_back(rcc_output_file);
rcc_output_file += "/qrc_" + basename + ".cpp"; }
rcc_output.push_back(rcc_output_file);
if (!cmSystemTools::IsOn(sf->GetPropertyForUser("GENERATED"))) { if (!cmSystemTools::IsOn(sf->GetPropertyForUser("GENERATED"))) {
if (qtMajorVersion == "5") { if (qtMajorVersion == "5") {
ListQt5RccInputs(sf, target, depends); ListQt5RccInputs(sf, target, depends);

View File

@ -88,6 +88,23 @@ static std::string extractSubDir(const std::string& absPath,
return subDir; 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() cmQtAutoGenerators::cmQtAutoGenerators()
: Verbose(cmsys::SystemTools::HasEnv("VERBOSE")) : Verbose(cmsys::SystemTools::HasEnv("VERBOSE"))
, ColorOutput(true) , ColorOutput(true)
@ -1257,15 +1274,18 @@ bool cmQtAutoGenerators::GenerateQrcFiles()
{ {
// generate single map with input / output names // generate single map with input / output names
std::map<std::string, std::string> qrcGenMap; std::map<std::string, std::string> qrcGenMap;
for (std::vector<std::string>::const_iterator si = this->RccSources.begin(); {
si != this->RccSources.end(); ++si) { cmFilePathUuid fpathUuid(this->Srcdir, this->Builddir,
const std::string ext = cmsys::SystemTools::GetFilenameLastExtension(*si); this->ProjectSourceDir, this->ProjectBinaryDir);
if (ext == ".qrc") { for (std::vector<std::string>::const_iterator si =
std::string basename = this->RccSources.begin();
cmsys::SystemTools::GetFilenameWithoutLastExtension(*si); si != this->RccSources.end(); ++si) {
std::string qrcOutputFile = "CMakeFiles/" + this->OriginTargetName + const std::string ext =
".dir/qrc_" + basename + ".cpp"; cmsys::SystemTools::GetFilenameLastExtension(*si);
qrcGenMap[*si] = qrcOutputFile; 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 = for (std::map<std::string, std::string>::const_iterator si =
qrcGenMap.begin(); qrcGenMap.begin();
si != qrcGenMap.end(); ++si) { 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) { if (this->RunRccFailed) {
return false; return false;
} }
@ -1297,10 +1318,23 @@ bool cmQtAutoGenerators::GenerateQrcFiles()
} }
bool cmQtAutoGenerators::GenerateQrc(const std::string& qrcInputFile, bool cmQtAutoGenerators::GenerateQrc(const std::string& qrcInputFile,
const std::string& qrcOutputFile) const std::string& qrcOutputFile,
bool unique_n)
{ {
const std::string basename = std::string symbolName;
cmsys::SystemTools::GetFilenameWithoutLastExtension(qrcInputFile); 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; const std::string qrcBuildFile = this->Builddir + qrcOutputFile;
int sourceNewerThanQrc = 0; int sourceNewerThanQrc = 0;
@ -1327,7 +1361,7 @@ bool cmQtAutoGenerators::GenerateQrc(const std::string& qrcInputFile,
} }
command.push_back("-name"); command.push_back("-name");
command.push_back(basename); command.push_back(symbolName);
command.push_back("-o"); command.push_back("-o");
command.push_back(qrcBuildFile); command.push_back(qrcBuildFile);
command.push_back(qrcInputFile); command.push_back(qrcInputFile);

View File

@ -51,7 +51,8 @@ private:
const std::string& uiOutputFile); const std::string& uiOutputFile);
bool GenerateQrcFiles(); bool GenerateQrcFiles();
bool GenerateQrc(const std::string& qrcInputFile, bool GenerateQrc(const std::string& qrcInputFile,
const std::string& qrcOutputFile); const std::string& qrcOutputFile, bool unique_n);
void ParseCppFile( void ParseCppFile(
const std::string& absFilename, const std::string& absFilename,
const std::vector<std::string>& headerExtensions, const std::vector<std::string>& headerExtensions,