ConvertToNinjaPath sadly makes the path relative to the binary dir, not the source dir.
I added a utility function 'ConvertToNinjaFolderRule' that does the same thing as ConvertToNinjaPath, but makes relative to the source dir, and adds the '/all' suffix. I also made the lines less than 79 chars. Best Le jeu. 17 mars 2016 à 15:53, Brad King <brad.k...@kitware.com> a écrit : > On 03/16/2016 12:13 PM, Charles Huet wrote: > >> On 03/16/2016 04:59 AM, Charles Huet wrote: > >>> If you have other ideas on how to improve this patch, I'll be happy to > >>> implement them. > > All paths that are given to WritePhonyBuild in the outputs and depends > options should be sent through ConvertToNinjaPath. This makes paths > relative and formats slashes for Windows. This should avoid the need > to do string manipulation on the paths (e.g. substr) too. Just be sure > to append the "/all" before calling the conversion method. > > Also please keep source lines to 79 characters or less. > > Thanks, > -Brad > >
From d204066149e098b9e33fc1004807a6d19d3f022b Mon Sep 17 00:00:00 2001 From: Charles Huet <charles.h...@gmail.com> Date: Fri, 11 Mar 2016 16:26:29 +0100 Subject: [PATCH] Added a target for each EXCLUDED_FROM_ALL folder that holds all the targets in said folder --- Source/cmGlobalNinjaGenerator.cxx | 85 +++++++++++++++++++++++++++++++++++++++ Source/cmGlobalNinjaGenerator.h | 3 ++ 2 files changed, 88 insertions(+) diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx index 0f06e43..49acfe3 100644 --- a/Source/cmGlobalNinjaGenerator.cxx +++ b/Source/cmGlobalNinjaGenerator.cxx @@ -577,6 +577,7 @@ void cmGlobalNinjaGenerator::Generate() this->WriteAssumedSourceDependencies(); this->WriteTargetAliases(*this->BuildFileStream); + this->WriteFolderTargets(*this->BuildFileStream); this->WriteUnknownExplicitDependencies(*this->BuildFileStream); this->WriteBuiltinTargets(*this->BuildFileStream); @@ -849,6 +850,18 @@ std::string cmGlobalNinjaGenerator::ConvertToNinjaPath(const std::string& path) return convPath; } +std::string cmGlobalNinjaGenerator::ConvertToNinjaFolderRule(const std::string& path) +{ + cmLocalNinjaGenerator *ng = + static_cast<cmLocalNinjaGenerator *>(this->LocalGenerators[0]); + std::string convPath = ng->Convert(path, cmOutputConverter::HOME); +#ifdef _WIN32 + cmSystemTools::ReplaceString(convPath, "/", "\\"); +#endif + return convPath + "/all"; +} + + void cmGlobalNinjaGenerator::AddCXXCompileCommand( const std::string &commandLine, const std::string &sourceFile) @@ -1042,6 +1055,78 @@ void cmGlobalNinjaGenerator::WriteTargetAliases(std::ostream& os) } } +void cmGlobalNinjaGenerator::WriteFolderTargets(std::ostream& os) +{ + cmGlobalNinjaGenerator::WriteDivider(os); + os << "# Folder targets.\n\n"; + + cmLocalGenerator* firstLocalGenerator = this->LocalGenerators[0]; + const std::string rootSourceDir = firstLocalGenerator->GetSourceDirectory(); + + std::map<std::string, cmNinjaDeps > targetsPerFolder; + + for ( std::vector<cmLocalGenerator *>::const_iterator generatorIt = + this->LocalGenerators.begin(); + generatorIt != this->LocalGenerators.end(); + ++generatorIt) + { + const cmLocalGenerator* localGenerator = *generatorIt; + const std::string currentSourceFolder( + localGenerator->GetStateSnapshot().GetDirectory().GetCurrentSource()); + targetsPerFolder[currentSourceFolder] = cmNinjaDeps(); + for ( std::vector<cmGeneratorTarget*>::const_iterator targetIt = + localGenerator->GetGeneratorTargets().begin(); + targetIt != localGenerator->GetGeneratorTargets().end(); + ++targetIt) + { + const cmGeneratorTarget* generatorTarget = *targetIt; + + const int type = generatorTarget->GetType(); + if((type == cmState::EXECUTABLE) || + (type == cmState::STATIC_LIBRARY) || + (type == cmState::SHARED_LIBRARY) || + (type == cmState::MODULE_LIBRARY) || + (type == cmState::OBJECT_LIBRARY) || + (type == cmState::UTILITY) && + (!generatorTarget->GetPropertyAsBool("EXCLUDE_FROM_ALL")) + ) + { + targetsPerFolder[currentSourceFolder].push_back( + generatorTarget->GetName()); + } + } + + // The directory-level rule should depend on the directory-level + // rules of the subdirectories. + std::vector<cmState::Snapshot> children + = localGenerator->GetStateSnapshot().GetChildren(); + for(std::vector<cmState::Snapshot>::const_iterator + stateIt = children.begin(); stateIt != children.end(); ++stateIt) + { + targetsPerFolder[currentSourceFolder].push_back( + ConvertToNinjaFolderRule(stateIt->GetDirectory(). + GetCurrentSource())); + } + } + + for ( std::map<std::string, cmNinjaDeps >::const_iterator it = + targetsPerFolder.begin(); it != targetsPerFolder.end(); ++it ) + { + cmGlobalNinjaGenerator::WriteDivider( os ); + std::string currentSourceDir(it->first); + + //do not generate a rule for the root source dir + if(rootSourceDir.length() >= currentSourceDir.length()) + continue; + + const std::string comment = "Folder: " + std::string(it->first); + cmNinjaDeps output(1); + output.push_back(ConvertToNinjaFolderRule(currentSourceDir)); + + this->WritePhonyBuild(os, comment, output, it->second); + } +} + void cmGlobalNinjaGenerator::WriteUnknownExplicitDependencies(std::ostream& os) { if (!this->ComputingUnknownDependencies) diff --git a/Source/cmGlobalNinjaGenerator.h b/Source/cmGlobalNinjaGenerator.h index 8656590..3023a95 100644 --- a/Source/cmGlobalNinjaGenerator.h +++ b/Source/cmGlobalNinjaGenerator.h @@ -228,6 +228,8 @@ public: return this->RulesFileStream; } std::string ConvertToNinjaPath(const std::string& path); + std::string ConvertToNinjaFolderRule(const std::string& path); + struct MapToNinjaPathImpl { cmGlobalNinjaGenerator* GG; @@ -342,6 +344,7 @@ private: void WriteAssumedSourceDependencies(); void WriteTargetAliases(std::ostream& os); + void WriteFolderTargets(std::ostream& os); void WriteUnknownExplicitDependencies(std::ostream& os); void WriteBuiltinTargets(std::ostream& os); -- 1.8.3.1
-- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: http://public.kitware.com/mailman/listinfo/cmake-developers