mirror of
https://github.com/reactos/CMake.git
synced 2025-02-16 09:37:36 +00:00
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
This commit is contained in:
parent
16c687825d
commit
747463d1b3
@ -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
|
||||
|
@ -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));
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user