Hi, I modified my patch a bit to use C++98 only, and try to stick to the coding conventions.
This now adds a target per folder, which contains all the targets in the folder and all its children folders. These targets are prefixed with "path/" in order to set them apart of normal CMake targets. Please tell me if more modifications are required. Best. Le ven. 11 mars 2016 à 16:58, Brad King <[email protected]> a écrit : > On 03/11/2016 10:48 AM, Charles Huet wrote: > > Here is a prototype that adds a target for each folder the > > has the EXCLUDE_FROM_ALL property set. > > Is there any reason to limit this to EXCLUDE_FROM_ALL? Why not > have a target for every directory with a CMakeLists.txt file? > > > 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). > > See cmGlobalUnixMakefileGenerator3::WriteDirectoryRule2 and > its call sites for how the Makefile generator decides which > targets are part of "all" for each directory. These targets > in build.ninja should be equivalent to "cd dir; make" in the > Makefile generator. > > > I used C++11, but I don't know if this is OK in CMake, I'll refactor if > not. > > Please use C++98. > > Thanks! > -Brad > >
From f3417b48ed8b676b10c06ede83e38fce6703f29a 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 | 56 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx index 0f06e43..050bc0e 100644 --- a/Source/cmGlobalNinjaGenerator.cxx +++ b/Source/cmGlobalNinjaGenerator.cxx @@ -1040,6 +1040,62 @@ 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; + + 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)) + { + + // insert the current target in every folder whose name contains the current target's folder + for ( std::map<std::string, cmNinjaDeps >::iterator it = targetsPerFolder.begin(); it != targetsPerFolder.end(); ++it ) + { + if( currentSourceFolder.find( it->first ) != std::string::npos ) + { + it->second.push_back( generatorTarget->GetName() ); + } + } + } + } + } + + for ( std::map<std::string, cmNinjaDeps >::const_iterator it = targetsPerFolder.begin(); it != targetsPerFolder.end(); ++it ) + { + if ( it->second.empty() ) + continue; + + cmGlobalNinjaGenerator::WriteDivider( os ); + + cmLocalGenerator* firstLocalGenerator = this->LocalGenerators[0]; + const std::string rootSourceDir = firstLocalGenerator->GetSourceDirectory(); + const std::string folderRelativeToSource = "path/" + std::string(it->first).replace( 0, rootSourceDir.size() + 1, "" ); + const std::string comment = "Folder: " + std::string(it->first); + cmNinjaDeps output(1); + output.push_back( folderRelativeToSource ); + + this->WritePhonyBuild(os, comment, 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
