Yes, sorry about that.

Le mer. 16 mars 2016 à 15:46, Brad King <[email protected]> a écrit :

> On 03/16/2016 04:59 AM, Charles Huet wrote:
> > Sure, done.
> >
> > If you have other ideas on how to improve this patch, I'll be happy to
> > implement them.
>
> Great.  Did you mean to attach a revised patch?
>
> Thanks,
> -Brad
>
>
From 25308102899bdcab9693da736184a4dc38001b4b Mon Sep 17 00:00:00 2001
From: Charles Huet <[email protected]>
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 | 69 +++++++++++++++++++++++++++++++++++++++
 Source/cmGlobalNinjaGenerator.h   |  1 +
 2 files changed, 70 insertions(+)

diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx
index 0f06e43..0fa76a0 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);
 
@@ -1042,6 +1043,74 @@ 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)
+        {
+        std::string currentSourceDir(stateIt->GetDirectory().GetCurrentSource());
+        std::string subdir = currentSourceDir.substr(rootSourceDir.length() + 1, currentSourceDir.length()) + "/all";
+        targetsPerFolder[currentSourceFolder].push_back(subdir);
+        }
+    }
+
+  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 folderRule = currentSourceDir.substr(rootSourceDir.length() + 1, currentSourceDir.length()) + "/all";
+    const std::string comment = "Folder: " + std::string(it->first);
+    cmNinjaDeps output(1);
+    output.push_back(folderRule);
+
+    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..e95a295 100644
--- a/Source/cmGlobalNinjaGenerator.h
+++ b/Source/cmGlobalNinjaGenerator.h
@@ -342,6 +342,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

Reply via email to