summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2017-05-01 13:15:40 (GMT)
committerKitware Robot <kwrobot@kitware.com>2017-05-01 13:15:46 (GMT)
commita2a13e8b48b5b55f2c6fd4e457936f91fe23f699 (patch)
treed6ab0ff0dd4c62d1ceb864fcaa262dd0f50fba47 /Source
parent6b7ec8ea1c3cfbfeb46c5f12a3304f292a1b88bb (diff)
parent7d057b2738e229192ae5afe71d50354681813235 (diff)
downloadCMake-a2a13e8b48b5b55f2c6fd4e457936f91fe23f699.zip
CMake-a2a13e8b48b5b55f2c6fd4e457936f91fe23f699.tar.gz
CMake-a2a13e8b48b5b55f2c6fd4e457936f91fe23f699.tar.bz2
Merge topic 'ipo-clang'
7d057b27 Clang IPO (LTO) support Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !717
Diffstat (limited to 'Source')
-rw-r--r--Source/cmLocalGenerator.cxx40
-rw-r--r--Source/cmLocalGenerator.h3
-rw-r--r--Source/cmMakefileExecutableTargetGenerator.cxx3
-rw-r--r--Source/cmMakefileLibraryTargetGenerator.cxx2
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 ||