From 63d3ca4c1cab0c7b9c71d6c051c3b4c053eb7627 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Wed, 28 Dec 2016 11:43:25 +0100 Subject: AUTOGEN: Make skipMoc and skipUic blacklists behave the same way Before skipMoc was a list of files that were not included in the sources. Now the skipMoc files are added to the sources as well in case they are needed for uic processing. skipMoc becomes a blacklist just like skipUic. --- Source/cmQtAutoGeneratorInitializer.cxx | 49 +++++++++----- Source/cmQtAutoGenerators.cxx | 113 ++++++++++++++------------------ 2 files changed, 82 insertions(+), 80 deletions(-) diff --git a/Source/cmQtAutoGeneratorInitializer.cxx b/Source/cmQtAutoGeneratorInitializer.cxx index f0847b1..0ed43b1 100644 --- a/Source/cmQtAutoGeneratorInitializer.cxx +++ b/Source/cmQtAutoGeneratorInitializer.cxx @@ -100,8 +100,8 @@ static std::string GetQtMajorVersion(cmGeneratorTarget const* target) static void SetupSourceFiles(cmGeneratorTarget const* target, std::vector& skipMoc, - std::vector& mocSources, - std::vector& mocHeaders, + std::vector& sources, + std::vector& headers, std::vector& skipUic) { cmMakefile* makefile = target->Target->GetMakefile(); @@ -113,26 +113,39 @@ static void SetupSourceFiles(cmGeneratorTarget const* target, for (std::vector::const_iterator fileIt = srcFiles.begin(); fileIt != srcFiles.end(); ++fileIt) { cmSourceFile* sf = *fileIt; + const cmSystemTools::FileFormat fileType = + cmSystemTools::GetFileFormat(sf->GetExtension().c_str()); + + if (!(fileType == cmSystemTools::CXX_FILE_FORMAT) && + !(fileType == cmSystemTools::HEADER_FILE_FORMAT)) { + continue; + } + if (cmSystemTools::IsOn(sf->GetPropertyForUser("GENERATED"))) { + continue; + } + const bool fileSkipUic = + cmSystemTools::IsOn(sf->GetPropertyForUser("SKIP_AUTOUIC")); + const bool fileSkipMoc = + cmSystemTools::IsOn(sf->GetPropertyForUser("SKIP_AUTOMOC")); + if (fileSkipUic && fileSkipMoc) { + continue; + } + + // Use file const std::string absFile = cmsys::SystemTools::GetRealPath(sf->GetFullPath()); - const std::string ext = sf->GetExtension(); - - if (cmSystemTools::IsOn(sf->GetPropertyForUser("SKIP_AUTOUIC"))) { + // Add file name to sources or headers list + if (fileType == cmSystemTools::CXX_FILE_FORMAT) { + sources.push_back(absFile); + } else if (fileType == cmSystemTools::HEADER_FILE_FORMAT) { + headers.push_back(absFile); + } + // Add file name to skip lists on demand + if (fileSkipUic) { skipUic.push_back(absFile); } - - if (!cmSystemTools::IsOn(sf->GetPropertyForUser("GENERATED"))) { - if (cmSystemTools::IsOn(sf->GetPropertyForUser("SKIP_AUTOMOC"))) { - skipMoc.push_back(absFile); - } else { - cmSystemTools::FileFormat fileType = - cmSystemTools::GetFileFormat(ext.c_str()); - if (fileType == cmSystemTools::CXX_FILE_FORMAT) { - mocSources.push_back(absFile); - } else if (fileType == cmSystemTools::HEADER_FILE_FORMAT) { - mocHeaders.push_back(absFile); - } - } + if (fileSkipMoc) { + skipMoc.push_back(absFile); } } } diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx index 5877619..4b5e113 100644 --- a/Source/cmQtAutoGenerators.cxx +++ b/Source/cmQtAutoGenerators.cxx @@ -89,6 +89,12 @@ static std::string ReadAll(const std::string& filename) return stream.str(); } +static bool ListContains(const std::vector& list, + const std::string& entry) +{ + return (std::find(list.begin(), list.end(), entry) != list.end()); +} + cmQtAutoGenerators::cmQtAutoGenerators() : Verbose(cmsys::SystemTools::HasEnv("VERBOSE")) , ColorOutput(true) @@ -502,56 +508,35 @@ bool cmQtAutoGenerators::RunAutogen(cmMakefile* makefile) // key = moc source filepath, value = moc output filepath std::map includedMocs; - // collect all headers which may need to be mocced + std::map notIncludedMocs; + std::map > includedUis; + // collects all headers which may need to be mocced std::set headerFiles; - const std::vector& headerExtensions = - makefile->GetCMakeInstance()->GetHeaderExtensions(); - - std::map > includedUis; - std::map > skippedUis; - - for (std::vector::const_iterator it = this->Sources.begin(); - it != this->Sources.end(); ++it) { - const std::string& absFilename = *it; - const bool skipUic = std::find(this->SkipUic.begin(), this->SkipUic.end(), - absFilename) != this->SkipUic.end(); - std::map >& uiFiles = - skipUic ? skippedUis : includedUis; - if (this->Verbose) { - std::ostringstream err; - err << "AUTOGEN: Checking " << absFilename << std::endl; - this->LogInfo(err.str()); - } - // Parse source file for MOC/UIC - if (!this->ParseSourceFile(absFilename, headerExtensions, includedMocs, - uiFiles, this->MocRelaxedMode)) { - return false; - } - // Find additional headers - this->SearchHeadersForCppFile(absFilename, headerExtensions, headerFiles); - } + // Parse sources + { + const std::vector& headerExtensions = + makefile->GetCMakeInstance()->GetHeaderExtensions(); - for (std::vector::const_iterator it = this->SkipMoc.begin(); - it != this->SkipMoc.end(); ++it) { - if (std::find(this->SkipUic.begin(), this->SkipUic.end(), *it) != - this->SkipUic.end()) { + for (std::vector::const_iterator it = this->Sources.begin(); + it != this->Sources.end(); ++it) { const std::string& absFilename = *it; - if (this->Verbose) { - std::ostringstream err; - err << "AUTOGEN: Checking " << absFilename << std::endl; - this->LogInfo(err.str()); + // Parse source file for MOC/UIC + if (!this->ParseSourceFile(absFilename, headerExtensions, includedMocs, + includedUis, this->MocRelaxedMode)) { + return false; } - this->ParseForUic(absFilename, includedUis); + // Find additional headers + this->SearchHeadersForCppFile(absFilename, headerExtensions, + headerFiles); } } + // Parse headers headerFiles.insert(this->Headers.begin(), this->Headers.end()); - - // key = moc source filepath, value = moc output filename - std::map notIncludedMocs; this->ParseHeaders(headerFiles, includedMocs, notIncludedMocs, includedUis); + // Generate files if (!this->MocExecutable.empty()) { if (!this->GenerateMocFiles(includedMocs, notIncludedMocs)) { return false; @@ -588,11 +573,13 @@ bool cmQtAutoGenerators::ParseSourceFile( << "The file is empty\n"; this->LogWarning(err.str()); } else { - // Parse source contents for UIC - this->ParseContentForUic(absFilename, contentsString, includedUis); // Parse source contents for MOC success = this->ParseContentForMoc( absFilename, contentsString, headerExtensions, includedMocs, relaxed); + // Parse source contents for UIC + if (success) { + this->ParseContentForUic(absFilename, contentsString, includedUis); + } } return success; } @@ -616,31 +603,21 @@ bool cmQtAutoGenerators::requiresMocing(const std::string& text, return false; } -void cmQtAutoGenerators::ParseForUic( - const std::string& absFilename, +void cmQtAutoGenerators::ParseContentForUic( + const std::string& absFilename, const std::string& contentsString, std::map >& includedUis) { - if (this->UicExecutable.empty()) { + if (this->UicExecutable.empty() || + ListContains(this->SkipUic, absFilename)) { return; } - const std::string contentsString = ReadAll(absFilename); - if (contentsString.empty()) { + + if (this->Verbose) { std::ostringstream err; - err << "AUTOGEN: warning: " << absFilename << ": file is empty\n" - << std::endl; - this->LogWarning(err.str()); - return; + err << "AUTOUIC: Checking " << absFilename << "\n"; + this->LogInfo(err.str()); } - this->ParseContentForUic(absFilename, contentsString, includedUis); -} -void cmQtAutoGenerators::ParseContentForUic( - const std::string& absFilename, const std::string& contentsString, - std::map >& includedUis) -{ - if (this->UicExecutable.empty()) { - return; - } const std::string realName = cmsys::SystemTools::GetRealPath(absFilename); const char* contentChars = contentsString.c_str(); if (strstr(contentChars, "ui_") != CM_NULLPTR) { @@ -664,10 +641,17 @@ bool cmQtAutoGenerators::ParseContentForMoc( const std::vector& headerExtensions, std::map& includedMocs, bool relaxed) { - if (this->MocExecutable.empty()) { + if (this->MocExecutable.empty() || + ListContains(this->SkipMoc, absFilename)) { return true; } + if (this->Verbose) { + std::ostringstream err; + err << "AUTOMOC: Checking " << absFilename << "\n"; + this->LogInfo(err.str()); + } + const std::string scannedFileAbsPath = cmsys::SystemTools::GetFilenamePath( cmsys::SystemTools::GetRealPath(absFilename)) + @@ -887,11 +871,14 @@ void cmQtAutoGenerators::ParseHeaders( const std::string& headerName = *hIt; const std::string contents = ReadAll(headerName); + // Parse header content for MOC if (!this->MocExecutable.empty() && - includedMocs.find(headerName) == includedMocs.end()) { + !ListContains(this->SkipMoc, headerName) && + (includedMocs.find(headerName) == includedMocs.end())) { + if (this->Verbose) { std::ostringstream err; - err << "AUTOGEN: Checking " << headerName << std::endl; + err << "AUTOMOC: Checking " << headerName << "\n"; this->LogInfo(err.str()); } @@ -903,6 +890,8 @@ void cmQtAutoGenerators::ParseHeaders( ".cpp"; } } + + // Parse header content for UIC this->ParseContentForUic(headerName, contents, includedUis); } } -- cgit v0.12