Here is a prototype that adds a target for each folder the has the
EXCLUDE_FROM_ALL property set.

Please review it and I'll get it in acceptable shape.

I used the folder name as target for now, this is not final but it was easy
for prototyping.
I am not satisfied with the way I exclude some build targets, but I could
not find the correct way to do it (Install target and such).

I used C++11, but I don't know if this is OK in CMake, I'll refactor if not.

Best

Le jeu. 10 mars 2016 à 15:28, Brad King <[email protected]> a écrit :

> On 03/10/2016 02:58 AM, Charles Huet wrote:
> > Maybe even adding such a target for each 'project', which regroups all
> the
> > targets of a project would make sense, as these are grouped as 'projects'
> [snip]
> > To avoid name collisions these could be suffixed with something like
> '_dir',
> > '_project' or such.
> >
> > Do you think this would be a good enough solution ?
>
> I think such targets makes sense and does not disallow full subproject
> generation in the future.  To avoid name collisions we should use a
> prefix or suffix with a "/" in its name since that is not allowed by
> CMake for the actual target names.
>
> Thanks,
> -Brad
>
>
From e95c65c80501444358c50d7c4d44ca6759ea9c9f 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 | 59 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 59 insertions(+)

diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx
index 0f06e43..76aed95 100644
--- a/Source/cmGlobalNinjaGenerator.cxx
+++ b/Source/cmGlobalNinjaGenerator.cxx
@@ -1040,6 +1040,65 @@ void cmGlobalNinjaGenerator::WriteTargetAliases(std::ostream& os)
                           cmNinjaDeps(1, i->first),
                           deps);
   }
+
+  cmGlobalNinjaGenerator::WriteDivider(os);
+  os << "# Folder targets.\n\n";
+
+  std::map<std::string, cmNinjaDeps > targetsPerFolder;
+  std::vector<std::string> excludedSourceFolders;
+
+  auto isExcludedFromAll = [&excludedSourceFolders]( const cmLocalGenerator* localGenerator ) -> std::string {
+    for ( const std::string& folder : excludedSourceFolders )
+    {
+      const std::string currentSourceDir( localGenerator->GetStateSnapshot().GetDirectory().GetCurrentSource() );
+      if ( currentSourceDir.find( folder ) != std::string::npos )
+      {
+        return folder;
+      }
+    }
+    return std::string();
+  };
+
+  for ( const cmLocalGenerator* localGenerator : this->LocalGenerators )
+  {
+    if ( localGenerator->GetStateSnapshot().GetDirectory().GetPropertyAsBool( "EXCLUDE_FROM_ALL" ) )
+    {
+      excludedSourceFolders.push_back( localGenerator->GetStateSnapshot().GetDirectory().GetCurrentSource() );
+    }
+
+    const std::string excludedSourceFolder = isExcludedFromAll( localGenerator );
+    if ( !excludedSourceFolder.empty() )
+    {
+      for ( const cmGeneratorTarget* generatorTarget : localGenerator->GetGeneratorTargets() )
+      {
+        if ( generatorTarget->GetName() != GetTestTargetName() &&
+             generatorTarget->GetName() != GetInstallLocalTargetName() &&
+             generatorTarget->GetName() != GetInstallStripTargetName() &&
+             generatorTarget->GetName() != GetInstallTargetName() &&
+             generatorTarget->GetName() != GetEditCacheTargetName() &&
+             generatorTarget->GetName() != GetRebuildCacheTargetName() &&
+             generatorTarget->GetName() != GetRebuildCacheTargetName() &&
+             generatorTarget->GetName().find( "list_install_components" ) == std::string::npos &&
+             generatorTarget->GetName().find( "_automoc" ) == std::string::npos )
+        {
+          targetsPerFolder[excludedSourceFolder].push_back( generatorTarget->GetName() );
+        }
+      }
+    }
+  }
+
+  for ( auto it = targetsPerFolder.begin(); it != targetsPerFolder.end(); ++it )
+  {
+    if ( it->second.empty() )
+      continue;
+
+    cmGlobalNinjaGenerator::WriteDivider( os );
+
+    cmNinjaDeps output(1);
+    output.push_back( it->first );
+
+    this->WritePhonyBuild(os, "Folder: " + std::string(it->first), output, it->second);
+  }
 }
 
 void cmGlobalNinjaGenerator::WriteUnknownExplicitDependencies(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