diff options
author | Kai Wang <wangkai86@huawei.com> | 2020-12-18 06:47:37 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2021-01-05 12:48:27 (GMT) |
commit | b696f7807303b421c3f59ff2bf8229c96f09f1fa (patch) | |
tree | 246f99b964b4cf5b43178adde879025dc01c4c37 /Source | |
parent | da2474626b8a02e957021b30453f5afc8d7246b9 (diff) | |
download | CMake-b696f7807303b421c3f59ff2bf8229c96f09f1fa.zip CMake-b696f7807303b421c3f59ff2bf8229c96f09f1fa.tar.gz CMake-b696f7807303b421c3f59ff2bf8229c96f09f1fa.tar.bz2 |
cmDepends: merge dependers of depend makefile
Since one depender has multiple dependees, depend makefile generated
same depender line by line, to reduce file size and refine make file
parse speed, merge same dependers to one. And add a testcase for
large depend.make which generated source file includes 20000 header
files and run build and incremental build
Signed-off-by: Wangkai <wangkai86@huawei.com>
Signed-off-by: Zhaoyingdong <zhaoyingdong@huawei.com>
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmDependsC.cxx | 31 | ||||
-rw-r--r-- | Source/cmDependsCompiler.cxx | 19 | ||||
-rw-r--r-- | Source/cmDependsFortran.cxx | 29 | ||||
-rw-r--r-- | Source/cmGlobalBorlandMakefileGenerator.cxx | 9 | ||||
-rw-r--r-- | Source/cmGlobalUnixMakefileGenerator3.h | 10 |
5 files changed, 77 insertions, 21 deletions
diff --git a/Source/cmDependsC.cxx b/Source/cmDependsC.cxx index e6aef92..60e8cbf 100644 --- a/Source/cmDependsC.cxx +++ b/Source/cmDependsC.cxx @@ -7,6 +7,7 @@ #include "cmsys/FStream.hxx" #include "cmFileTime.h" +#include "cmGlobalUnixMakefileGenerator3.h" #include "cmLocalUnixMakefileGenerator3.h" #include "cmMakefile.h" #include "cmProperty.h" @@ -215,16 +216,28 @@ bool cmDependsC::WriteDependencies(const std::set<std::string>& sources, // directory. We must do the same here. std::string obj_m = this->LocalGenerator->ConvertToMakefilePath(obj_i); internalDepends << obj_i << '\n'; - - for (std::string const& dep : dependencies) { - makeDepends << obj_m << ": " - << this->LocalGenerator->ConvertToMakefilePath( - this->LocalGenerator->MaybeConvertToRelativePath(binDir, - dep)) - << '\n'; - internalDepends << ' ' << dep << '\n'; + if (!dependencies.empty()) { + const auto& lineContinue = static_cast<cmGlobalUnixMakefileGenerator3*>( + this->LocalGenerator->GetGlobalGenerator()) + ->LineContinueDirective; + bool supportLongLineDepend = static_cast<cmGlobalUnixMakefileGenerator3*>( + this->LocalGenerator->GetGlobalGenerator()) + ->SupportsLongLineDependencies(); + if (supportLongLineDepend) { + makeDepends << obj_m << ':'; + } + for (std::string const& dep : dependencies) { + std::string dependee = this->LocalGenerator->ConvertToMakefilePath( + this->LocalGenerator->MaybeConvertToRelativePath(binDir, dep)); + if (supportLongLineDepend) { + makeDepends << ' ' << lineContinue << ' ' << dependee; + } else { + makeDepends << obj_m << ": " << dependee << '\n'; + } + internalDepends << ' ' << dep << '\n'; + } + makeDepends << '\n'; } - makeDepends << '\n'; return true; } diff --git a/Source/cmDependsCompiler.cxx b/Source/cmDependsCompiler.cxx index beb080f..97534bc 100644 --- a/Source/cmDependsCompiler.cxx +++ b/Source/cmDependsCompiler.cxx @@ -196,6 +196,9 @@ void cmDependsCompiler::WriteDependencies( const auto& lineContinue = static_cast<cmGlobalUnixMakefileGenerator3*>( this->LocalGenerator->GetGlobalGenerator()) ->LineContinueDirective; + bool supportLongLineDepend = static_cast<cmGlobalUnixMakefileGenerator3*>( + this->LocalGenerator->GetGlobalGenerator()) + ->SupportsLongLineDependencies(); const auto& binDir = this->LocalGenerator->GetBinaryDirectory(); cmDepends::DependencyMap makeDependencies(dependencies); std::unordered_set<cm::string_view> phonyTargets; @@ -213,13 +216,19 @@ void cmDependsCompiler::WriteDependencies( }); bool first_dep = true; - makeDepends << target << ": "; + if (supportLongLineDepend) { + makeDepends << target << ": "; + } for (const auto& dep : deps) { - if (first_dep) { - first_dep = false; - makeDepends << dep; + if (supportLongLineDepend) { + if (first_dep) { + first_dep = false; + makeDepends << dep; + } else { + makeDepends << ' ' << lineContinue << " " << dep; + } } else { - makeDepends << ' ' << lineContinue << " " << dep; + makeDepends << target << ": " << dep << std::endl; } phonyTargets.emplace(dep.data(), dep.length()); diff --git a/Source/cmDependsFortran.cxx b/Source/cmDependsFortran.cxx index a239418..1a06f31 100644 --- a/Source/cmDependsFortran.cxx +++ b/Source/cmDependsFortran.cxx @@ -12,6 +12,7 @@ #include "cmFortranParser.h" /* Interface to parser object. */ #include "cmGeneratedFileStream.h" +#include "cmGlobalUnixMakefileGenerator3.h" #include "cmLocalUnixMakefileGenerator3.h" #include "cmMakefile.h" #include "cmOutputConverter.h" @@ -320,14 +321,28 @@ bool cmDependsFortran::WriteDependenciesReal(std::string const& obj, std::string obj_i = this->MaybeConvertToRelativePath(binDir, obj); std::string obj_m = cmSystemTools::ConvertToOutputPath(obj_i); internalDepends << obj_i << "\n " << src << '\n'; - for (std::string const& i : info.Includes) { - makeDepends << obj_m << ": " - << cmSystemTools::ConvertToOutputPath( - this->MaybeConvertToRelativePath(binDir, i)) - << '\n'; - internalDepends << ' ' << i << '\n'; + if (!info.Includes.empty()) { + const auto& lineContinue = static_cast<cmGlobalUnixMakefileGenerator3*>( + this->LocalGenerator->GetGlobalGenerator()) + ->LineContinueDirective; + bool supportLongLineDepend = static_cast<cmGlobalUnixMakefileGenerator3*>( + this->LocalGenerator->GetGlobalGenerator()) + ->SupportsLongLineDependencies(); + if (supportLongLineDepend) { + makeDepends << obj_m << ':'; + } + for (std::string const& i : info.Includes) { + std::string dependee = cmSystemTools::ConvertToOutputPath( + this->MaybeConvertToRelativePath(binDir, i)); + if (supportLongLineDepend) { + makeDepends << ' ' << lineContinue << ' ' << dependee; + } else { + makeDepends << obj_m << ": " << dependee << '\n'; + } + internalDepends << ' ' << i << '\n'; + } + makeDepends << '\n'; } - makeDepends << '\n'; // Write module requirements to the output stream. for (std::string const& i : info.Requires) { diff --git a/Source/cmGlobalBorlandMakefileGenerator.cxx b/Source/cmGlobalBorlandMakefileGenerator.cxx index 06943e7..996fcff 100644 --- a/Source/cmGlobalBorlandMakefileGenerator.cxx +++ b/Source/cmGlobalBorlandMakefileGenerator.cxx @@ -26,6 +26,15 @@ cmGlobalBorlandMakefileGenerator::cmGlobalBorlandMakefileGenerator(cmake* cm) this->DefineWindowsNULL = true; this->PassMakeflags = true; this->UnixCD = false; + + /* + * Borland Make does not support long line depend rule, as we have tested + * generate one source file includes 40000 header files, and generate + * depend.make in one line(use line continued tag), and error occured: + * ** Fatal CMakeFiles\main.dir\depend.make 1224: Rule line too long ** + * we disable long line dependencies rule generation for Borland make + */ + this->ToolSupportsLongLineDependencies = false; } void cmGlobalBorlandMakefileGenerator::EnableLanguage( diff --git a/Source/cmGlobalUnixMakefileGenerator3.h b/Source/cmGlobalUnixMakefileGenerator3.h index 09679a7..c15f491 100644 --- a/Source/cmGlobalUnixMakefileGenerator3.h +++ b/Source/cmGlobalUnixMakefileGenerator3.h @@ -139,6 +139,12 @@ public: return this->ToolSupportsCompilerDependencies; } + // Make tool supports long line dependencies + bool SupportsLongLineDependencies() + { + return this->ToolSupportsLongLineDependencies; + } + /** Get the command to use for a target that has no rule. This is used for multiple output dependencies and for cmake_force. */ std::string GetEmptyRuleHackCommand() { return this->EmptyRuleHackCommand; } @@ -235,6 +241,10 @@ protected: // generated by the compiler bool ToolSupportsCompilerDependencies = true; + // some Make generator, such as Borland not support long line dependencies, + // we add SupportsLongLineDependencies to predicate. + bool ToolSupportsLongLineDependencies = true; + // Some make programs (Borland) do not keep a rule if there are no // dependencies or commands. This is a problem for creating rules // that might not do anything but might have other dependencies |