From 3cc42863a43cd4256efdeb2eda2d235d5533bad9 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Wed, 15 Feb 2017 12:53:39 +0100 Subject: [PATCH] Autogen: Overhaul moc include list generation --- Source/cmQtAutoGenerators.cxx | 98 +++++++++++++++++++---------------- Source/cmQtAutoGenerators.h | 3 +- 2 files changed, 54 insertions(+), 47 deletions(-) diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx index a167705960..f67543f45a 100644 --- a/Source/cmQtAutoGenerators.cxx +++ b/Source/cmQtAutoGenerators.cxx @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -539,58 +540,65 @@ void cmQtAutoGenerators::Init() this->ProjectSourceDir, this->ProjectBinaryDir); - std::vector incPaths; - cmSystemTools::ExpandListArgument(this->MocInfoIncludes, incPaths); - - std::set frameworkPaths; - for (std::vector::const_iterator it = incPaths.begin(); - it != incPaths.end(); ++it) { - const std::string& path = *it; - this->MocIncludes.push_back("-I" + path); - if (cmHasLiteralSuffix(path, ".framework/Headers")) { - // Go up twice to get to the framework root - std::vector pathComponents; - cmsys::SystemTools::SplitPath(path, pathComponents); - std::string frameworkPath = cmsys::SystemTools::JoinPath( - pathComponents.begin(), pathComponents.end() - 2); - frameworkPaths.insert(frameworkPath); + // Compose moc includes list + std::list mocIncludes; + { + std::set frameworkPaths; + { + std::vector incPaths; + cmSystemTools::ExpandListArgument(this->MocInfoIncludes, incPaths); + for (std::vector::const_iterator it = incPaths.begin(); + it != incPaths.end(); ++it) { + const std::string& path = *it; + mocIncludes.push_back("-I" + path); + // Extract framework path + if (cmHasLiteralSuffix(path, ".framework/Headers")) { + // Go up twice to get to the framework root + std::vector pathComponents; + cmsys::SystemTools::SplitPath(path, pathComponents); + std::string frameworkPath = cmsys::SystemTools::JoinPath( + pathComponents.begin(), pathComponents.end() - 2); + frameworkPaths.insert(frameworkPath); + } + } + } + // Append framework includes + for (std::set::const_iterator it = frameworkPaths.begin(); + it != frameworkPaths.end(); ++it) { + mocIncludes.push_back("-F"); + mocIncludes.push_back(*it); } } - - for (std::set::const_iterator it = frameworkPaths.begin(); - it != frameworkPaths.end(); ++it) { - this->MocIncludes.push_back("-F"); - this->MocIncludes.push_back(*it); - } - if (this->IncludeProjectDirsBefore) { - const std::string binDir = "-I" + this->ProjectBinaryDir; - const std::string srcDir = "-I" + this->ProjectSourceDir; + // Extract project includes + std::vector mocSortedIncludes; + { + std::vector movePaths; + movePaths.push_back("-I" + this->ProjectBinaryDir); + movePaths.push_back("-I" + this->ProjectSourceDir); - std::list sortedMocIncludes; - std::list::iterator it = this->MocIncludes.begin(); - while (it != this->MocIncludes.end()) { - if (cmsys::SystemTools::StringStartsWith(*it, binDir.c_str())) { - sortedMocIncludes.push_back(*it); - it = this->MocIncludes.erase(it); - } else { - ++it; + for (std::vector::const_iterator mpit = movePaths.begin(); + mpit != movePaths.end(); ++mpit) { + std::list::iterator it = mocIncludes.begin(); + while (it != mocIncludes.end()) { + const std::string& path = *it; + if (cmsys::SystemTools::StringStartsWith(path, mpit->c_str())) { + mocSortedIncludes.push_back(path); + it = mocIncludes.erase(it); + } else { + ++it; + } + } } } - it = this->MocIncludes.begin(); - while (it != this->MocIncludes.end()) { - if (cmsys::SystemTools::StringStartsWith(*it, srcDir.c_str())) { - sortedMocIncludes.push_back(*it); - it = this->MocIncludes.erase(it); - } else { - ++it; - } - } - sortedMocIncludes.insert(sortedMocIncludes.end(), - this->MocIncludes.begin(), - this->MocIncludes.end()); - this->MocIncludes = sortedMocIncludes; + // Place extracted includes at the begin + this->MocIncludes.insert(this->MocIncludes.end(), + mocSortedIncludes.begin(), + mocSortedIncludes.end()); } + // Append remaining includes + this->MocIncludes.insert(this->MocIncludes.end(), mocIncludes.begin(), + mocIncludes.end()); } bool cmQtAutoGenerators::RunAutogen(cmMakefile* makefile) diff --git a/Source/cmQtAutoGenerators.h b/Source/cmQtAutoGenerators.h index e60320b95d..f6caed98d6 100644 --- a/Source/cmQtAutoGenerators.h +++ b/Source/cmQtAutoGenerators.h @@ -7,7 +7,6 @@ #include #include -#include #include #include #include @@ -146,7 +145,7 @@ private: std::string MocInfoIncludes; std::string OutMocCppFilenameRel; std::string OutMocCppFilenameAbs; - std::list MocIncludes; + std::vector MocIncludes; std::vector MocDefinitions; std::vector MocOptions; // - Uic