diff options
author | Bill Hoffman <bill.hoffman@kitware.com> | 2016-06-02 22:08:30 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2016-06-17 14:56:40 (GMT) |
commit | 96242f8022fa4bc718ef36cda43f5dfe6236c066 (patch) | |
tree | eb344591def11380b95fba62e71aa950e3671b87 /Source/cmMakefileExecutableTargetGenerator.cxx | |
parent | ba92e11f8b461513566d5cc3c0b53b2215bb85f7 (diff) | |
download | CMake-96242f8022fa4bc718ef36cda43f5dfe6236c066.zip CMake-96242f8022fa4bc718ef36cda43f5dfe6236c066.tar.gz CMake-96242f8022fa4bc718ef36cda43f5dfe6236c066.tar.bz2 |
Add options to run `ldd -u -r` as a "link-what-you-use" tool
Create a LINK_WHAT_YOU_USE target property and corresponding
CMAKE_LINK_WHAT_YOU_USE variable to enable this behavior.
Extend link commands by running `ldd -u -r` to detect shared
libraries that are linked but not needed.
Diffstat (limited to 'Source/cmMakefileExecutableTargetGenerator.cxx')
-rw-r--r-- | Source/cmMakefileExecutableTargetGenerator.cxx | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/Source/cmMakefileExecutableTargetGenerator.cxx b/Source/cmMakefileExecutableTargetGenerator.cxx index 9d42257..ba4c6e6 100644 --- a/Source/cmMakefileExecutableTargetGenerator.cxx +++ b/Source/cmMakefileExecutableTargetGenerator.cxx @@ -187,6 +187,9 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink) this->LocalGenerator->AppendFlags( linkFlags, this->Makefile->GetDefinition(export_flag_var)); } + if (this->GeneratorTarget->GetProperty("LINK_WHAT_YOU_USE")) { + this->LocalGenerator->AppendFlags(linkFlags, " -Wl,--no-as-needed"); + } // Add language feature flags. this->AddFeatureFlags(flags, linkLanguage); @@ -356,6 +359,15 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink) vars.LinkFlags = linkFlags.c_str(); vars.Manifests = manifests.c_str(); + if (this->GeneratorTarget->GetProperty("LINK_WHAT_YOU_USE")) { + std::string cmakeCommand = + this->Convert(cmSystemTools::GetCMakeCommand(), cmLocalGenerator::NONE, + cmLocalGenerator::SHELL); + cmakeCommand += " -E __run_iwyu --lwyu="; + cmakeCommand += targetOutPathReal; + real_link_commands.push_back(cmakeCommand); + } + // Expand placeholders in the commands. this->LocalGenerator->TargetImplib = targetOutPathImport; for (std::vector<std::string>::iterator i = real_link_commands.begin(); |