mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-09 07:11:05 -06:00
Autogen: AUTOMOC support for files with the same name but different extensions
This adds support for AUTOMOC to moc header files with the same but different extensions (e.g `obj.h`, `obj.hpp`, `obj.hxx`). If a moc file would appear multiple times in `mocs_compilation.cpp`, a number suffix is appended to the name to make it unique. Closes #14489
This commit is contained in:
@@ -678,19 +678,21 @@ void cmQtAutoGeneratorMocUic::JobMocT::Process(WorkerT& wrk)
|
||||
BuildFile += '/';
|
||||
BuildFile += IncludeString;
|
||||
} else {
|
||||
std::string rel = wrk.FileSys().GetFilePathChecksum(SourceFile);
|
||||
rel += "/moc_";
|
||||
rel += wrk.FileSys().GetFilenameWithoutLastExtension(SourceFile);
|
||||
rel += ".cpp";
|
||||
// Register relative file path
|
||||
wrk.Gen().ParallelMocAutoRegister(rel);
|
||||
// Relative build path
|
||||
std::string relPath = wrk.FileSys().GetFilePathChecksum(SourceFile);
|
||||
relPath += "/moc_";
|
||||
relPath += wrk.FileSys().GetFilenameWithoutLastExtension(SourceFile);
|
||||
|
||||
// Register relative file path with duplication check
|
||||
relPath = wrk.Gen().ParallelMocAutoRegister(relPath);
|
||||
|
||||
// Absolute build path
|
||||
if (wrk.Base().MultiConfig) {
|
||||
BuildFile = wrk.Base().AutogenIncludeDir;
|
||||
BuildFile += '/';
|
||||
BuildFile += rel;
|
||||
BuildFile += relPath;
|
||||
} else {
|
||||
BuildFile = wrk.Base().AbsoluteBuildPath(rel);
|
||||
BuildFile = wrk.Base().AbsoluteBuildPath(relPath);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1953,11 +1955,31 @@ bool cmQtAutoGeneratorMocUic::ParallelMocIncluded(
|
||||
return (MocIncludedFiles_.find(sourceFile) != MocIncludedFiles_.end());
|
||||
}
|
||||
|
||||
void cmQtAutoGeneratorMocUic::ParallelMocAutoRegister(
|
||||
std::string const& mocFile)
|
||||
std::string cmQtAutoGeneratorMocUic::ParallelMocAutoRegister(
|
||||
std::string const& baseName)
|
||||
{
|
||||
std::lock_guard<std::mutex> mocLock(JobsMutex_);
|
||||
MocAutoFiles_.emplace(mocFile);
|
||||
std::string res;
|
||||
{
|
||||
std::lock_guard<std::mutex> mocLock(JobsMutex_);
|
||||
res = baseName;
|
||||
res += ".cpp";
|
||||
if (MocAutoFiles_.find(res) == MocAutoFiles_.end()) {
|
||||
MocAutoFiles_.emplace(res);
|
||||
} else {
|
||||
// Append number suffix to the file name
|
||||
for (unsigned int ii = 2; ii != 1024; ++ii) {
|
||||
res = baseName;
|
||||
res += '_';
|
||||
res += std::to_string(ii);
|
||||
res += ".cpp";
|
||||
if (MocAutoFiles_.find(res) == MocAutoFiles_.end()) {
|
||||
MocAutoFiles_.emplace(res);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
void cmQtAutoGeneratorMocUic::ParallelMocAutoUpdated()
|
||||
|
||||
@@ -389,7 +389,7 @@ public:
|
||||
bool ParallelJobPushMoc(JobHandleT& jobHandle);
|
||||
bool ParallelJobPushUic(JobHandleT& jobHandle);
|
||||
bool ParallelMocIncluded(std::string const& sourceFile);
|
||||
void ParallelMocAutoRegister(std::string const& mocFile);
|
||||
std::string ParallelMocAutoRegister(std::string const& baseName);
|
||||
void ParallelMocAutoUpdated();
|
||||
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user