diff options
author | Ruslan Baratov <ruslan_baratov@yahoo.com> | 2017-04-28 14:13:56 (GMT) |
---|---|---|
committer | Ruslan Baratov <ruslan_baratov@yahoo.com> | 2017-04-28 14:13:56 (GMT) |
commit | 7d057b2738e229192ae5afe71d50354681813235 (patch) | |
tree | bebcaf0fcca709a89a4d6e9dde390ef7003cef38 /Source | |
parent | d828d0eb084cf094119d2b47dae0053267aba138 (diff) | |
download | CMake-7d057b2738e229192ae5afe71d50354681813235.zip CMake-7d057b2738e229192ae5afe71d50354681813235.tar.gz CMake-7d057b2738e229192ae5afe71d50354681813235.tar.bz2 |
Clang IPO (LTO) support
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmLocalGenerator.cxx | 40 | ||||
-rw-r--r-- | Source/cmLocalGenerator.h | 3 | ||||
-rw-r--r-- | Source/cmMakefileExecutableTargetGenerator.cxx | 3 | ||||
-rw-r--r-- | Source/cmMakefileLibraryTargetGenerator.cxx | 2 |
4 files changed, 45 insertions, 3 deletions
diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 57b744c..33e32d1 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -915,6 +915,9 @@ void cmLocalGenerator::GetTargetFlags( const char* libraryLinkVariable = "CMAKE_SHARED_LINKER_FLAGS"; // default to shared library + const std::string linkLanguage = + linkLineComputer->GetLinkerLanguage(target, buildType); + switch (target->GetType()) { case cmStateEnums::STATIC_LIBRARY: this->GetStaticLibraryFlags(linkFlags, buildType, target); @@ -976,9 +979,6 @@ void cmLocalGenerator::GetTargetFlags( linkFlags += this->Makefile->GetSafeDefinition(build); linkFlags += " "; } - - const std::string linkLanguage = - linkLineComputer->GetLinkerLanguage(target, buildType); if (linkLanguage.empty()) { cmSystemTools::Error( "CMake can not determine linker language for target: ", @@ -1040,6 +1040,8 @@ void cmLocalGenerator::GetTargetFlags( default: break; } + + this->AppendIPOLinkerFlags(linkFlags, target, config, linkLanguage); } void cmLocalGenerator::GetTargetCompileFlags(cmGeneratorTarget* target, @@ -1769,6 +1771,38 @@ void cmLocalGenerator::AppendFlagEscape(std::string& flags, this->AppendFlags(flags, this->EscapeForShell(rawFlag)); } +void cmLocalGenerator::AppendIPOLinkerFlags(std::string& flags, + cmGeneratorTarget* target, + const std::string& config, + const std::string& lang) +{ + if (!target->IsIPOEnabled(config)) { + return; + } + + switch (target->GetType()) { + case cmStateEnums::EXECUTABLE: + case cmStateEnums::SHARED_LIBRARY: + case cmStateEnums::MODULE_LIBRARY: + break; + default: + return; + } + + const std::string name = "CMAKE_" + lang + "_LINK_OPTIONS_IPO"; + const char* rawFlagsList = this->Makefile->GetDefinition(name); + if (rawFlagsList == CM_NULLPTR) { + return; + } + + std::vector<std::string> flagsList; + cmSystemTools::ExpandListArgument(rawFlagsList, flagsList); + for (std::vector<std::string>::const_iterator oi = flagsList.begin(); + oi != flagsList.end(); ++oi) { + this->AppendFlagEscape(flags, *oi); + } +} + void cmLocalGenerator::AppendDefines(std::set<std::string>& defines, const char* defines_list) const { diff --git a/Source/cmLocalGenerator.h b/Source/cmLocalGenerator.h index 2eda0e5..1a238a8 100644 --- a/Source/cmLocalGenerator.h +++ b/Source/cmLocalGenerator.h @@ -115,6 +115,9 @@ public: virtual void AppendFlags(std::string& flags, const char* newFlags); virtual void AppendFlagEscape(std::string& flags, const std::string& rawFlag); + void AppendIPOLinkerFlags(std::string& flags, cmGeneratorTarget* target, + const std::string& config, + const std::string& lang); ///! Get the include flags for the current makefile and language std::string GetIncludeFlags(const std::vector<std::string>& includes, cmGeneratorTarget* target, diff --git a/Source/cmMakefileExecutableTargetGenerator.cxx b/Source/cmMakefileExecutableTargetGenerator.cxx index 272d45b..fb39f01 100644 --- a/Source/cmMakefileExecutableTargetGenerator.cxx +++ b/Source/cmMakefileExecutableTargetGenerator.cxx @@ -457,6 +457,9 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink) this->AddModuleDefinitionFlag(linkLineComputer.get(), linkFlags); } + this->LocalGenerator->AppendIPOLinkerFlags(linkFlags, this->GeneratorTarget, + this->ConfigName, linkLanguage); + // Construct a list of files associated with this executable that // may need to be cleaned. std::vector<std::string> exeCleanFiles; diff --git a/Source/cmMakefileLibraryTargetGenerator.cxx b/Source/cmMakefileLibraryTargetGenerator.cxx index ec01208..5ee9f45 100644 --- a/Source/cmMakefileLibraryTargetGenerator.cxx +++ b/Source/cmMakefileLibraryTargetGenerator.cxx @@ -494,6 +494,8 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules( // Create set of linking flags. std::string linkFlags; this->LocalGenerator->AppendFlags(linkFlags, extraFlags); + this->LocalGenerator->AppendIPOLinkerFlags(linkFlags, this->GeneratorTarget, + this->ConfigName, linkLanguage); // Add OSX version flags, if any. if (this->GeneratorTarget->GetType() == cmStateEnums::SHARED_LIBRARY || |