diff options
author | Sebastian Holtermann <sebholt@web.de> | 2020-01-04 09:55:20 (GMT) |
---|---|---|
committer | Sebastian Holtermann <sebholt@web.de> | 2020-01-04 10:32:14 (GMT) |
commit | 4db1463e052255f9f72d9fa293986a5798026514 (patch) | |
tree | f95dd45f15f651b25a1b2e21a0f422bfd5bda27a | |
parent | 85287ff10d2f0918166f853357c4367e77df4159 (diff) | |
download | CMake-4db1463e052255f9f72d9fa293986a5798026514.zip CMake-4db1463e052255f9f72d9fa293986a5798026514.tar.gz CMake-4db1463e052255f9f72d9fa293986a5798026514.tar.bz2 |
Autogen: Try adding header suffix to moc output file name on name conflicts
In AUTOGEN, this changes the moc output file name computation on output name
conflicts to first try to add the header suffix to the moc output base name.
When that still conflicts, we try adding a range of sequential numbers.
If we still can't find an unique output name, we raise an error.
-rw-r--r-- | Source/cmQtAutoGenInitializer.cxx | 44 |
1 files changed, 31 insertions, 13 deletions
diff --git a/Source/cmQtAutoGenInitializer.cxx b/Source/cmQtAutoGenInitializer.cxx index ab47f3f..3c799b9 100644 --- a/Source/cmQtAutoGenInitializer.cxx +++ b/Source/cmQtAutoGenInitializer.cxx @@ -1634,21 +1634,39 @@ std::string cmQtAutoGenInitializer::GetMocBuildPath(MUFile const& muf) if (!muf.MocIt) { return res; } - { - std::string const basePath = - cmStrCat(this->PathCheckSum.getPart(muf.FullPath), "/moc_", - FileNameWithoutLastExtension(muf.FullPath)); - std::string suffix; - constexpr std::size_t num_tries_max = 256; - for (std::size_t ii = 0; ii != num_tries_max; ++ii) { - res = cmStrCat(basePath, suffix, ".cpp"); - if (this->Moc.EmittedBuildPaths.emplace(res).second) { - break; - } - // Compute new suffix - suffix = cmStrCat('_', ii + 1); + + std::string basePath = + cmStrCat(this->PathCheckSum.getPart(muf.FullPath), "/moc_", + FileNameWithoutLastExtension(muf.FullPath)); + + res = cmStrCat(basePath, ".cpp"); + if (this->Moc.EmittedBuildPaths.emplace(res).second) { + return res; + } + + // File name already emitted. + // Try appending the header suffix to the base path. + basePath = cmStrCat(basePath, '_', muf.SF->GetExtension()); + res = cmStrCat(basePath, ".cpp"); + if (this->Moc.EmittedBuildPaths.emplace(res).second) { + return res; + } + + // File name with header extension already emitted. + // Try adding a number to the base path. + constexpr std::size_t number_begin = 2; + constexpr std::size_t number_end = 256; + for (std::size_t ii = number_begin; ii != number_end; ++ii) { + res = cmStrCat(basePath, '_', ii, ".cpp"); + if (this->Moc.EmittedBuildPaths.emplace(res).second) { + return res; } } + + // Output file name conflict (unlikely, but still...) + cmSystemTools::Error( + cmStrCat("moc output file name conflict for ", muf.FullPath)); + return res; } |