summaryrefslogtreecommitdiff
path: root/Source/cmGeneratorTarget.cxx
diff options
context:
space:
mode:
authorKyle Edwards <kyle.edwards@kitware.com>2020-07-29 14:19:56 -0400
committerBrad King <brad.king@kitware.com>2020-08-12 11:31:07 -0400
commit2e42651dff43c4e962f03fc24281cbf446880ded (patch)
tree5a1fa6f2098d9cb5bdc04c7f9285dc454c3a5ebf /Source/cmGeneratorTarget.cxx
parent0cd3b5d0ca8d541fc3769f467db71a07a95be7f6 (diff)
downloadcmake-2e42651dff43c4e962f03fc24281cbf446880ded.tar.gz
Add option to optimize link dependencies for static libraries
Add an `OPTIMIZE_DEPENDENCIES` target property and supporting `CMAKE_OPTIMIZE_DEPENDENCIES` variable to optionally enable pruning and flattening of outgoing dependencies from static libraries. Since they do not actually link, they only depend on side effects of their dependencies. Therefore we can drop dependencies that contribute no side effects.
Diffstat (limited to 'Source/cmGeneratorTarget.cxx')
-rw-r--r--Source/cmGeneratorTarget.cxx31
1 files changed, 31 insertions, 0 deletions
diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx
index 889ad7c17b..9611e142e7 100644
--- a/Source/cmGeneratorTarget.cxx
+++ b/Source/cmGeneratorTarget.cxx
@@ -1084,6 +1084,37 @@ std::vector<cmCustomCommand> const& cmGeneratorTarget::GetPostBuildCommands()
return this->Target->GetPostBuildCommands();
}
+void cmGeneratorTarget::AppendCustomCommandSideEffects(
+ std::set<cmGeneratorTarget const*>& sideEffects) const
+{
+ if (!this->GetPreBuildCommands().empty() ||
+ !this->GetPreLinkCommands().empty() ||
+ !this->GetPostBuildCommands().empty()) {
+ sideEffects.insert(this);
+ } else {
+ for (auto const& source : this->GetAllConfigSources()) {
+ if (source.Source->GetCustomCommand() != nullptr) {
+ sideEffects.insert(this);
+ break;
+ }
+ }
+ }
+}
+
+void cmGeneratorTarget::AppendLanguageSideEffects(
+ std::map<std::string, std::set<cmGeneratorTarget const*>>& sideEffects) const
+{
+ static const std::set<cm::string_view> LANGS_WITH_NO_SIDE_EFFECTS = {
+ "C"_s, "CXX"_s, "OBJC"_s, "OBJCXX"_s, "ASM"_s, "CUDA"_s,
+ };
+
+ for (auto const& lang : this->GetAllConfigCompileLanguages()) {
+ if (!LANGS_WITH_NO_SIDE_EFFECTS.count(lang)) {
+ sideEffects[lang].insert(this);
+ }
+ }
+}
+
bool cmGeneratorTarget::IsInBuildSystem() const
{
if (this->IsImported()) {