Re: [cmake-developers] Ninja and add_subdirectory EXCLUDE_FROM_ALL
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 -- 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
Re: [cmake-developers] Ninja and add_subdirectory EXCLUDE_FROM_ALL
Yes, sorry about that. Le mer. 16 mars 2016 à 15:46, Brad King 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 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 targetsPerFolder; + + for ( std::vector::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::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 children + = localGenerator->GetStateSnapshot().GetChildren(); + for(std::vector::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::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: CMa
Re: [cmake-developers] Ninja and add_subdirectory EXCLUDE_FROM_ALL
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 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 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(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 targetsPerFolder; + + for ( std::vector::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::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 children + = localGenerator->GetStateSnapshot().GetChildren(); + for(std::vector::const_iterator +stateIt = children.begin(); stateIt != children.end(); ++stateIt) +{ +targetsPerFolder[currentSourceFolder].push_back( + ConvertToNinjaFolderRule(stateIt->GetDirectory(). + GetCurrentSource())); +} +} + + for ( std::map::const_iterator it = +targetsPerFolder.begin(); it != targetsPerFolder.end(); ++it ) +{ +cmGlobalNinjaGenerator::WriteDivider( os ); +std::string currentSourceDir(it->first);
Re: [cmake-developers] Ninja and add_subdirectory EXCLUDE_FROM_ALL
Awesome, thanks! I'll check monday and report, but this looks like it'll work the same as the patch I sent last, which I've been using the past few days. Looking forward to have this feature in CMake ! Le ven. 18 mars 2016 à 16:03, Brad King a écrit : > On 03/17/2016 11:23 AM, Charles Huet wrote: > > 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. > > Great. I've applied the patch with a few style changes and > logic fixes. I also added documentation and a test: > > Ninja: Add `$subdir/all` targets > https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=ca575fe9 > > Ninja: Add test for `$subdir/all` targets > https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=86c851e6 > > Help: Add notes for topic 'ninja-directory-targets' > https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=133aed8f > > Please try out that version to make sure it still works for you. > > Thanks, > -Brad > > -- 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
Re: [cmake-developers] Ninja and add_subdirectory EXCLUDE_FROM_ALL
On 03/17/2016 11:23 AM, Charles Huet wrote: > 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. Great. I've applied the patch with a few style changes and logic fixes. I also added documentation and a test: Ninja: Add `$subdir/all` targets https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=ca575fe9 Ninja: Add test for `$subdir/all` targets https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=86c851e6 Help: Add notes for topic 'ninja-directory-targets' https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=133aed8f Please try out that version to make sure it still works for you. Thanks, -Brad -- 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
Re: [cmake-developers] Ninja and add_subdirectory EXCLUDE_FROM_ALL
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 -- 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
Re: [cmake-developers] Ninja and add_subdirectory EXCLUDE_FROM_ALL
> This is per-target and is different than add_subdirectory EXCLUDE_FROM_ALL. We should still honor this. Ok, done. > The rules we're generating here could work like that too. Each one depends on all the targets defined in its own directory and on the directory-level target for subdirectories. The goal is to match the Makefile generator behavior for target selection in each directory. I don't think matching subdirectory name prefixes is needed for that. Ah, yes, this makes a lot of sense. Now I feel a bit dumb for not going this way in the first place. > I think the names can instead use a "/all" suffix e.g. "sub/dir/all". This would be consistent with the "ninja all" one can now do at the top. Sure, done. If you have other ideas on how to improve this patch, I'll be happy to implement them. I've been using Cmake 3.5 with this added feature and I must say it's pretty sweet for my use case. Best Le mar. 15 mars 2016 à 18:58, Brad King a écrit : > On 03/14/2016 05:04 AM, Charles Huet wrote: > > I modified my patch a bit to use C++98 only, and try to stick > > to the coding conventions. > > Thanks. While reviewing the logic I realized my suggestion to include > all targets was not quite consistent with my observation that this matches > the Makefile generator "cd dir; make" behavior. The latter still excludes > targets that have the EXCLUDE_FROM_ALL target property, as seen by this > code in cmGlobalUnixMakefileGenerator3::WriteDirectoryRule2: > > > if((!check_all || !gtarget->GetPropertyAsBool("EXCLUDE_FROM_ALL")) && > > This is per-target and is different than add_subdirectory EXCLUDE_FROM_ALL. > We should still honor this. Such targets are meant to be built only upon > explicit request. Also later in WriteDirectoryRule2 is this section: > > > // The directory-level rule should depend on the directory-level > > // rules of the subdirectories. > > The rules we're generating here could work like that too. Each one > depends on all the targets defined in its own directory and on the > directory-level target for subdirectories. The goal is to match the > Makefile generator behavior for target selection in each directory. > I don't think matching subdirectory name prefixes is needed for that. > > > These targets are prefixed with "path/" in order to set them apart of > > normal CMake targets. > > I think the names can instead use a "/all" suffix e.g. "sub/dir/all". > This would be consistent with the "ninja all" one can now do at the > top. > > Thanks, > -Brad > > -- 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
Re: [cmake-developers] Ninja and add_subdirectory EXCLUDE_FROM_ALL
On 03/14/2016 05:04 AM, Charles Huet wrote: > I modified my patch a bit to use C++98 only, and try to stick > to the coding conventions. Thanks. While reviewing the logic I realized my suggestion to include all targets was not quite consistent with my observation that this matches the Makefile generator "cd dir; make" behavior. The latter still excludes targets that have the EXCLUDE_FROM_ALL target property, as seen by this code in cmGlobalUnixMakefileGenerator3::WriteDirectoryRule2: > if((!check_all || !gtarget->GetPropertyAsBool("EXCLUDE_FROM_ALL")) && This is per-target and is different than add_subdirectory EXCLUDE_FROM_ALL. We should still honor this. Such targets are meant to be built only upon explicit request. Also later in WriteDirectoryRule2 is this section: > // The directory-level rule should depend on the directory-level > // rules of the subdirectories. The rules we're generating here could work like that too. Each one depends on all the targets defined in its own directory and on the directory-level target for subdirectories. The goal is to match the Makefile generator behavior for target selection in each directory. I don't think matching subdirectory name prefixes is needed for that. > These targets are prefixed with "path/" in order to set them apart of > normal CMake targets. I think the names can instead use a "/all" suffix e.g. "sub/dir/all". This would be consistent with the "ninja all" one can now do at the top. Thanks, -Brad -- 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
Re: [cmake-developers] Ninja and add_subdirectory EXCLUDE_FROM_ALL
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 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 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 targetsPerFolder; + + for ( std::vector::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::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::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::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
Re: [cmake-developers] Ninja and add_subdirectory EXCLUDE_FROM_ALL
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 -- 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
Re: [cmake-developers] Ninja and add_subdirectory EXCLUDE_FROM_ALL
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 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 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 targetsPerFolder; + std::vector 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
Re: [cmake-developers] Ninja and add_subdirectory EXCLUDE_FROM_ALL
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 -- 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
Re: [cmake-developers] Ninja and add_subdirectory EXCLUDE_FROM_ALL
Hi, I was looking into this yesterday, and it seems non-trivial as far as code modifications go to make this happen. But I wonder if this would even be the best way to go. Having multiple ninja files would mean (as far as I understand) duplicating lots of values in the sub ninja files. I think it would be easier to just add a new target for each folder added with 'EXCLUDE_FROM_ALL' that groups all the targets added within. 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' in MSVC, whereas a folder added with 'EXCLUDE_FROM_ALL' is added as a 'solution'. This would make ninja easy to use in a fashion relatively similar to MSVC. 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 ? Le mer. 10 févr. 2016 à 19:47, Brad King a écrit : > On 02/10/2016 10:57 AM, Charles Huet wrote: > > When using Unix Makefiles (or MSVC) this causes the subfolder to contain > > a new Makefile, allowing me to build easily the whole subdir. > > > > I cannot find such a facility with Ninja > > The Makefile generator naturally lays makefiles out with launch points > in each directory. The Xcode generator and Visual Studio generators > generate projects that can be loaded in the respective IDEs for each > source directory with a project() command in its CMakeLists.txt file: > > > https://cmake.org/gitweb?p=cmake.git;a=blob;f=Source/cmGlobalXCodeGenerator.cxx;hb=v3.4.3#l407 > > https://cmake.org/gitweb?p=cmake.git;a=blob;f=Source/cmGlobalVisualStudio7Generator.cxx;hb=v3.4.3#l383 > > They contain the relevant subsets of the build system needed for their > subdirectories. Currently the Ninja generator does not have this > feature. It may be possible to add but would take some investigation > into how intrusive the changes would be. > > -Brad > > -- 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
Re: [cmake-developers] Ninja and add_subdirectory EXCLUDE_FROM_ALL
On 02/10/2016 10:57 AM, Charles Huet wrote: > When using Unix Makefiles (or MSVC) this causes the subfolder to contain > a new Makefile, allowing me to build easily the whole subdir. > > I cannot find such a facility with Ninja The Makefile generator naturally lays makefiles out with launch points in each directory. The Xcode generator and Visual Studio generators generate projects that can be loaded in the respective IDEs for each source directory with a project() command in its CMakeLists.txt file: https://cmake.org/gitweb?p=cmake.git;a=blob;f=Source/cmGlobalXCodeGenerator.cxx;hb=v3.4.3#l407 https://cmake.org/gitweb?p=cmake.git;a=blob;f=Source/cmGlobalVisualStudio7Generator.cxx;hb=v3.4.3#l383 They contain the relevant subsets of the build system needed for their subdirectories. Currently the Ninja generator does not have this feature. It may be possible to add but would take some investigation into how intrusive the changes would be. -Brad -- 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
[cmake-developers] Ninja and add_subdirectory EXCLUDE_FROM_ALL
Hi, I have a folder in my build that is added as such: "add_subdirectory(folder EXCLUDE_FROM_ALL)" When using Unix Makefiles (or MSVC) this causes the subfolder to contain a new Makefile, allowing me to build easily the whole subdir. I cannot find such a facility with Ninja, which is very annoying (since the folder I add this way are demos, there are quite a lot of targets to build). Am I missing something or is this a feature I could add ? Best -- 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