diff options
author | Sebastian Holtermann <sebholt@xwmw.org> | 2019-02-19 14:49:09 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2019-02-25 13:20:19 (GMT) |
commit | 747463d1b36a8bea31764db88ed4d9677b76f27f (patch) | |
tree | 1932fe24175f8ee70640561da78cda4b5579b807 | |
parent | 16c687825daef4008d52b9b68bfa603ba493ac03 (diff) | |
download | CMake-747463d1b36a8bea31764db88ed4d9677b76f27f.zip CMake-747463d1b36a8bea31764db88ed4d9677b76f27f.tar.gz CMake-747463d1b36a8bea31764db88ed4d9677b76f27f.tar.bz2 |
Autogen: Move additional source header search to configuration stage
The computation of additional source headers and and private headers for
AUTOGEN is moved from the _autogen target to the configuration stage. This
makes them available for _autogen target dependency computations.
Closes: #18949
-rw-r--r-- | Source/cmQtAutoGenInitializer.cxx | 61 | ||||
-rw-r--r-- | Source/cmQtAutoGeneratorMocUic.cxx | 33 |
2 files changed, 65 insertions, 29 deletions
diff --git a/Source/cmQtAutoGenInitializer.cxx b/Source/cmQtAutoGenInitializer.cxx index 239426c..2fb6fdf 100644 --- a/Source/cmQtAutoGenInitializer.cxx +++ b/Source/cmQtAutoGenInitializer.cxx @@ -704,6 +704,67 @@ bool cmQtAutoGenInitializer::InitScanFiles() // mocs_compilation.cpp source acknowledged by this target. this->Target->ClearSourcesCache(); + // For source files find additional headers and private headers + if (this->MocOrUicEnabled()) { + std::vector<MUFileHandle> extraHeaders; + extraHeaders.reserve(this->AutogenTarget.Sources.size() * 2); + // Header search suffixes and extensions + std::array<std::string, 2> const suffixes{ { "", "_p" } }; + auto const& exts = makefile->GetCMakeInstance()->GetHeaderExtensions(); + // Scan through sources + for (auto const& pair : this->AutogenTarget.Sources) { + MUFile const& muf = *pair.second; + if (muf.MocIt || muf.UicIt) { + // Search for the default header file and a private header + std::string const& realPath = muf.RealPath; + std::string basePath = cmQtAutoGen::SubDirPrefix(realPath); + basePath += cmSystemTools::GetFilenameWithoutLastExtension(realPath); + for (auto const& suffix : suffixes) { + std::string const suffixedPath = basePath + suffix; + for (auto const& ext : exts) { + std::string fullPath = suffixedPath; + fullPath += '.'; + fullPath += ext; + + auto constexpr locationKind = cmSourceFileLocationKind::Known; + cmSourceFile* sf = makefile->GetSource(fullPath, locationKind); + if (sf != nullptr) { + // Check if we know about this header already + if (this->AutogenTarget.Headers.find(sf) != + this->AutogenTarget.Headers.end()) { + continue; + } + // We only accept not-GENERATED files that do exist. + if (!sf->GetIsGenerated() && + !cmSystemTools::FileExists(fullPath)) { + continue; + } + } else if (cmSystemTools::FileExists(fullPath)) { + // Create a new source file for the existing file + sf = makefile->CreateSource(fullPath, false, locationKind); + } + + if (sf != nullptr) { + auto eMuf = makeMUFile(sf, fullPath, true); + // Ony process moc/uic when the parent is processed as well + if (!muf.MocIt) { + eMuf->MocIt = false; + } + if (!muf.UicIt) { + eMuf->UicIt = false; + } + extraHeaders.emplace_back(std::move(eMuf)); + } + } + } + } + } + // Move generated files to main headers list + for (auto& eMuf : extraHeaders) { + addMUFile(std::move(eMuf), true); + } + } + // Scan through all source files in the makefile to extract moc and uic // parameters. Historically we support non target source file parameters. // The reason is that their file names might be discovered from source files diff --git a/Source/cmQtAutoGeneratorMocUic.cxx b/Source/cmQtAutoGeneratorMocUic.cxx index 0673f1d..b02cd44 100644 --- a/Source/cmQtAutoGeneratorMocUic.cxx +++ b/Source/cmQtAutoGeneratorMocUic.cxx @@ -9,7 +9,6 @@ #include <memory> #include <set> #include <sstream> -#include <unordered_set> #include <utility> #include "cmAlgorithms.h" @@ -1374,35 +1373,11 @@ bool cmQtAutoGeneratorMocUic::Init(cmMakefile* makefile) // - Headers and sources { - std::unordered_set<std::string> headers; - auto addHeader = [this, &headers](std::string&& hdr, bool moc, bool uic) { - if (headers.emplace(hdr).second) { - this->JobQueues_.Headers.emplace_back( - cm::make_unique<JobParseT>(std::move(hdr), moc, uic, true)); - } + auto addHeader = [this](std::string&& hdr, bool moc, bool uic) { + this->JobQueues_.Headers.emplace_back( + cm::make_unique<JobParseT>(std::move(hdr), moc, uic, true)); }; - auto addSource = [this, &addHeader](std::string&& src, bool moc, - bool uic) { - // Search for the default header file and a private header - { - std::array<std::string, 2> bases; - bases[0] = FileSys().SubDirPrefix(src); - bases[0] += FileSys().GetFilenameWithoutLastExtension(src); - bases[1] = bases[0]; - bases[1] += "_p"; - for (std::string const& headerBase : bases) { - std::string header; - if (Base().FindHeader(header, headerBase)) { - bool const hdrMoc = moc && !Moc().skipped(header); - bool const hdrUic = uic && !Uic().skipped(header); - if (hdrMoc || hdrUic) { - // Add additional header job - addHeader(std::move(header), hdrMoc, hdrUic); - } - } - } - } - // Add actual source job + auto addSource = [this](std::string&& src, bool moc, bool uic) { this->JobQueues_.Sources.emplace_back( cm::make_unique<JobParseT>(std::move(src), moc, uic, false)); }; |