diff options
author | Brad King <brad.king@kitware.com> | 2017-03-31 14:37:56 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2017-03-31 14:38:08 (GMT) |
commit | 8772fc81c4ab745eb5abbae58c6a69706f610429 (patch) | |
tree | cf974aec17ed5a474680b488d1effbf137a7db5e /Source | |
parent | 60dde287e71efbad71b107902991098a6c77556d (diff) | |
parent | dfa8263f4be4f1413b73c81649fdc4567a71e56a (diff) | |
download | CMake-8772fc81c4ab745eb5abbae58c6a69706f610429.zip CMake-8772fc81c4ab745eb5abbae58c6a69706f610429.tar.gz CMake-8772fc81c4ab745eb5abbae58c6a69706f610429.tar.bz2 |
Merge topic 'ipo-policy-CMP0069'
dfa8263f Implement interprocedural optimization for GNU compilers
1588a577 Add policy CMP0069 to enforce INTERPROCEDURAL_OPTIMIZATION
a7575700 Refactoring: s,GetFeatureAsBool,IsIPOEnabled,
e05835c3 CheckIPOSupported: Visual Studio and Xcode generators do not support IPO
Acked-by: Kitware Robot <kwrobot@kitware.com>
Reviewed-by: Brad King <brad.king@kitware.com>
Reviewed-by: Nils Gladitz <nilsgladitz@gmail.com>
Merge-request: !568
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmCommonTargetGenerator.cxx | 7 | ||||
-rw-r--r-- | Source/cmCommonTargetGenerator.h | 1 | ||||
-rw-r--r-- | Source/cmGeneratorTarget.cxx | 85 | ||||
-rw-r--r-- | Source/cmGeneratorTarget.h | 8 | ||||
-rw-r--r-- | Source/cmGlobalGenerator.h | 2 | ||||
-rw-r--r-- | Source/cmGlobalNinjaGenerator.h | 2 | ||||
-rw-r--r-- | Source/cmGlobalUnixMakefileGenerator3.h | 2 | ||||
-rw-r--r-- | Source/cmGlobalXCodeGenerator.cxx | 3 | ||||
-rw-r--r-- | Source/cmLocalGenerator.cxx | 2 | ||||
-rw-r--r-- | Source/cmLocalVisualStudio7Generator.cxx | 3 | ||||
-rw-r--r-- | Source/cmMakefileLibraryTargetGenerator.cxx | 21 | ||||
-rw-r--r-- | Source/cmNinjaNormalTargetGenerator.cxx | 8 | ||||
-rw-r--r-- | Source/cmPolicies.h | 6 | ||||
-rw-r--r-- | Source/cmVisualStudio10TargetGenerator.cxx | 3 |
14 files changed, 125 insertions, 28 deletions
diff --git a/Source/cmCommonTargetGenerator.cxx b/Source/cmCommonTargetGenerator.cxx index fd1ad36..fe2c0fe 100644 --- a/Source/cmCommonTargetGenerator.cxx +++ b/Source/cmCommonTargetGenerator.cxx @@ -43,18 +43,13 @@ const char* cmCommonTargetGenerator::GetFeature(const std::string& feature) return this->GeneratorTarget->GetFeature(feature, this->ConfigName); } -bool cmCommonTargetGenerator::GetFeatureAsBool(const std::string& feature) -{ - return this->GeneratorTarget->GetFeatureAsBool(feature, this->ConfigName); -} - void cmCommonTargetGenerator::AddFeatureFlags(std::string& flags, const std::string& lang) { // Add language-specific flags. this->LocalGenerator->AddLanguageFlags(flags, lang, this->ConfigName); - if (this->GetFeatureAsBool("INTERPROCEDURAL_OPTIMIZATION")) { + if (this->GeneratorTarget->IsIPOEnabled(this->ConfigName)) { this->LocalGenerator->AppendFeatureOptions(flags, lang, "IPO"); } } diff --git a/Source/cmCommonTargetGenerator.h b/Source/cmCommonTargetGenerator.h index 8d68123..425ff91 100644 --- a/Source/cmCommonTargetGenerator.h +++ b/Source/cmCommonTargetGenerator.h @@ -32,7 +32,6 @@ protected: // Feature query methods. const char* GetFeature(const std::string& feature); - bool GetFeatureAsBool(const std::string& feature); // Helper to add flag for windows .def file. void AddModuleDefinitionFlag(cmLinkLineComputer* linkLineComputer, diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index f78a933..73d2009 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -286,6 +286,7 @@ cmGeneratorTarget::cmGeneratorTarget(cmTarget* t, cmLocalGenerator* lg) , FortranModuleDirectoryCreated(false) , SourceFileFlagsConstructed(false) , PolicyWarnedCMP0022(false) + , PolicyReportedCMP0069(false) , DebugIncludesDone(false) , DebugCompileOptionsDone(false) , DebugCompileFeaturesDone(false) @@ -656,10 +657,65 @@ const char* cmGeneratorTarget::GetFeature(const std::string& feature, return this->LocalGenerator->GetFeature(feature, config); } -bool cmGeneratorTarget::GetFeatureAsBool(const std::string& feature, - const std::string& config) const +bool cmGeneratorTarget::IsIPOEnabled(const std::string& config) const { - return cmSystemTools::IsOn(this->GetFeature(feature, config)); + const char* feature = "INTERPROCEDURAL_OPTIMIZATION"; + const bool result = cmSystemTools::IsOn(this->GetFeature(feature, config)); + + if (!result) { + // 'INTERPROCEDURAL_OPTIMIZATION' is off, no need to check policies + return false; + } + + cmPolicies::PolicyStatus cmp0069 = this->GetPolicyStatusCMP0069(); + + if (cmp0069 == cmPolicies::OLD || cmp0069 == cmPolicies::WARN) { + if (this->Makefile->IsOn("_CMAKE_IPO_LEGACY_BEHAVIOR")) { + return true; + } + if (this->PolicyReportedCMP0069) { + // problem is already reported, no need to issue a message + return false; + } + if (cmp0069 == cmPolicies::WARN) { + std::ostringstream w; + w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0069) << "\n"; + w << "INTERPROCEDURAL_OPTIMIZATION property will be ignored for target " + << "'" << this->GetName() << "'."; + this->LocalGenerator->GetCMakeInstance()->IssueMessage( + cmake::AUTHOR_WARNING, w.str(), this->GetBacktrace()); + + this->PolicyReportedCMP0069 = true; + } + return false; + } + + // Note: check consistency with messages from CheckIPOSupported + const char* message = CM_NULLPTR; + if (!this->Makefile->IsOn("_CMAKE_IPO_SUPPORTED_BY_CMAKE")) { + message = "CMake doesn't support IPO for current compiler"; + } else if (!this->Makefile->IsOn( + "_CMAKE_IPO_MAY_BE_SUPPORTED_BY_COMPILER")) { + message = "Compiler doesn't support IPO"; + } else if (!this->GlobalGenerator->IsIPOSupported()) { + message = "CMake doesn't support IPO for current generator"; + } + + if (!message) { + // No error/warning messages + return true; + } + + if (this->PolicyReportedCMP0069) { + // problem is already reported, no need to issue a message + return false; + } + + this->PolicyReportedCMP0069 = true; + + this->LocalGenerator->GetCMakeInstance()->IssueMessage( + cmake::FATAL_ERROR, message, this->GetBacktrace()); + return false; } const std::string& cmGeneratorTarget::GetObjectName(cmSourceFile const* file) @@ -2410,19 +2466,28 @@ void cmGeneratorTarget::GetAppleArchs(const std::string& config, } } +//---------------------------------------------------------------------------- +std::string cmGeneratorTarget::GetFeatureSpecificLinkRuleVariable( + std::string const& var, std::string const& config) const +{ + if (this->IsIPOEnabled(config)) { + std::string varIPO = var + "_IPO"; + if (this->Makefile->IsDefinitionSet(varIPO)) { + return varIPO; + } + } + + return var; +} + +//---------------------------------------------------------------------------- std::string cmGeneratorTarget::GetCreateRuleVariable( std::string const& lang, std::string const& config) const { switch (this->GetType()) { case cmStateEnums::STATIC_LIBRARY: { std::string var = "CMAKE_" + lang + "_CREATE_STATIC_LIBRARY"; - if (this->GetFeatureAsBool("INTERPROCEDURAL_OPTIMIZATION", config)) { - std::string varIPO = var + "_IPO"; - if (this->Makefile->GetDefinition(varIPO)) { - return varIPO; - } - } - return var; + return this->GetFeatureSpecificLinkRuleVariable(var, config); } case cmStateEnums::SHARED_LIBRARY: return "CMAKE_" + lang + "_CREATE_SHARED_LIBRARY"; diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h index d60ad24..fcab4aa 100644 --- a/Source/cmGeneratorTarget.h +++ b/Source/cmGeneratorTarget.h @@ -112,8 +112,8 @@ public: const char* GetFeature(const std::string& feature, const std::string& config) const; - bool GetFeatureAsBool(const std::string& feature, - const std::string& config) const; + + bool IsIPOEnabled(const std::string& config) const; bool IsLinkInterfaceDependentBoolProperty(const std::string& p, const std::string& config) const; @@ -309,6 +309,9 @@ public: void GetAppleArchs(const std::string& config, std::vector<std::string>& archVec) const; + std::string GetFeatureSpecificLinkRuleVariable( + std::string const& var, std::string const& config) const; + /** Return the rule variable used to create this type of target. */ std::string GetCreateRuleVariable(std::string const& lang, std::string const& config) const; @@ -745,6 +748,7 @@ private: mutable std::set<cmLinkItem> UtilityItems; cmPolicies::PolicyMap PolicyMap; mutable bool PolicyWarnedCMP0022; + mutable bool PolicyReportedCMP0069; mutable bool DebugIncludesDone; mutable bool DebugCompileOptionsDone; mutable bool DebugCompileFeaturesDone; diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h index 2558fee..b228d41 100644 --- a/Source/cmGlobalGenerator.h +++ b/Source/cmGlobalGenerator.h @@ -333,6 +333,8 @@ public: virtual bool UseFolderProperty() const; + virtual bool IsIPOSupported() const { return false; } + /** Return whether the generator should use EFFECTIVE_PLATFORM_NAME. This is relevant for mixed macOS and iOS builds. */ virtual bool UseEffectivePlatformName(cmMakefile*) const { return false; } diff --git a/Source/cmGlobalNinjaGenerator.h b/Source/cmGlobalNinjaGenerator.h index a51e919..956af51 100644 --- a/Source/cmGlobalNinjaGenerator.h +++ b/Source/cmGlobalNinjaGenerator.h @@ -99,6 +99,8 @@ public: */ static bool SupportsPlatform() { return false; } + bool IsIPOSupported() const CM_OVERRIDE { return true; } + /** * Write a build statement to @a os with the @a comment using * the @a rule the list of @a outputs files and inputs. diff --git a/Source/cmGlobalUnixMakefileGenerator3.h b/Source/cmGlobalUnixMakefileGenerator3.h index 67d7bc9..bbf9f0f 100644 --- a/Source/cmGlobalUnixMakefileGenerator3.h +++ b/Source/cmGlobalUnixMakefileGenerator3.h @@ -149,6 +149,8 @@ public: /** Does the make tool tolerate .DELETE_ON_ERROR? */ virtual bool AllowDeleteOnError() const { return true; } + bool IsIPOSupported() const CM_OVERRIDE { return true; } + void ComputeTargetObjectDirectory(cmGeneratorTarget* gt) const CM_OVERRIDE; std::string IncludeDirective; diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index 42dd997..416af14 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -1707,6 +1707,9 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt, return; } + // Check IPO related warning/error. + gtgt->IsIPOEnabled(configName); + // Add define flags this->CurrentLocalGenerator->AppendFlags( defFlags, this->CurrentMakefile->GetDefineFlags()); diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 82bf0b9..9333ed7 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -1052,7 +1052,7 @@ void cmLocalGenerator::GetTargetCompileFlags(cmGeneratorTarget* target, // Add language-specific flags. this->AddLanguageFlags(flags, lang, config); - if (target->GetFeatureAsBool("INTERPROCEDURAL_OPTIMIZATION", config)) { + if (target->IsIPOEnabled(config)) { this->AppendFeatureOptions(flags, lang, "IPO"); } diff --git a/Source/cmLocalVisualStudio7Generator.cxx b/Source/cmLocalVisualStudio7Generator.cxx index 3117ef3..260a84b 100644 --- a/Source/cmLocalVisualStudio7Generator.cxx +++ b/Source/cmLocalVisualStudio7Generator.cxx @@ -670,6 +670,9 @@ void cmLocalVisualStudio7Generator::WriteConfiguration( // Add the target-specific flags. this->AddCompileOptions(flags, target, linkLanguage, configName); + + // Check IPO related warning/error. + target->IsIPOEnabled(configName); } if (this->FortranProject) { diff --git a/Source/cmMakefileLibraryTargetGenerator.cxx b/Source/cmMakefileLibraryTargetGenerator.cxx index e5fae13..cc8a6b3 100644 --- a/Source/cmMakefileLibraryTargetGenerator.cxx +++ b/Source/cmMakefileLibraryTargetGenerator.cxx @@ -129,14 +129,9 @@ void cmMakefileLibraryTargetGenerator::WriteStaticLibraryRules() { std::string linkLanguage = this->GeneratorTarget->GetLinkerLanguage(this->ConfigName); - std::string linkRuleVar = "CMAKE_"; - linkRuleVar += linkLanguage; - linkRuleVar += "_CREATE_STATIC_LIBRARY"; - if (this->GetFeatureAsBool("INTERPROCEDURAL_OPTIMIZATION") && - this->Makefile->GetDefinition(linkRuleVar + "_IPO")) { - linkRuleVar += "_IPO"; - } + std::string linkRuleVar = this->GeneratorTarget->GetCreateRuleVariable( + linkLanguage, this->ConfigName); std::string extraFlags; this->LocalGenerator->GetStaticLibraryFlags( @@ -676,18 +671,30 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules( std::string arCreateVar = "CMAKE_"; arCreateVar += linkLanguage; arCreateVar += "_ARCHIVE_CREATE"; + + arCreateVar = this->GeneratorTarget->GetFeatureSpecificLinkRuleVariable( + arCreateVar, this->ConfigName); + if (const char* rule = this->Makefile->GetDefinition(arCreateVar)) { cmSystemTools::ExpandListArgument(rule, archiveCreateCommands); } std::string arAppendVar = "CMAKE_"; arAppendVar += linkLanguage; arAppendVar += "_ARCHIVE_APPEND"; + + arAppendVar = this->GeneratorTarget->GetFeatureSpecificLinkRuleVariable( + arAppendVar, this->ConfigName); + if (const char* rule = this->Makefile->GetDefinition(arAppendVar)) { cmSystemTools::ExpandListArgument(rule, archiveAppendCommands); } std::string arFinishVar = "CMAKE_"; arFinishVar += linkLanguage; arFinishVar += "_ARCHIVE_FINISH"; + + arFinishVar = this->GeneratorTarget->GetFeatureSpecificLinkRuleVariable( + arFinishVar, this->ConfigName); + if (const char* rule = this->Makefile->GetDefinition(arFinishVar)) { cmSystemTools::ExpandListArgument(rule, archiveFinishCommands); } diff --git a/Source/cmNinjaNormalTargetGenerator.cxx b/Source/cmNinjaNormalTargetGenerator.cxx index 560eb4f..aaeb659 100644 --- a/Source/cmNinjaNormalTargetGenerator.cxx +++ b/Source/cmNinjaNormalTargetGenerator.cxx @@ -516,6 +516,10 @@ std::vector<std::string> cmNinjaNormalTargetGenerator::ComputeLinkCmd() std::string linkCmdVar = "CMAKE_"; linkCmdVar += this->TargetLinkLanguage; linkCmdVar += "_ARCHIVE_CREATE"; + + linkCmdVar = this->GeneratorTarget->GetFeatureSpecificLinkRuleVariable( + linkCmdVar, this->GetConfigName()); + const char* linkCmd = mf->GetRequiredDefinition(linkCmdVar); cmSystemTools::ExpandListArgument(linkCmd, linkCmds); } @@ -523,6 +527,10 @@ std::vector<std::string> cmNinjaNormalTargetGenerator::ComputeLinkCmd() std::string linkCmdVar = "CMAKE_"; linkCmdVar += this->TargetLinkLanguage; linkCmdVar += "_ARCHIVE_FINISH"; + + linkCmdVar = this->GeneratorTarget->GetFeatureSpecificLinkRuleVariable( + linkCmdVar, this->GetConfigName()); + const char* linkCmd = mf->GetRequiredDefinition(linkCmdVar); cmSystemTools::ExpandListArgument(linkCmd, linkCmds); } diff --git a/Source/cmPolicies.h b/Source/cmPolicies.h index ecf06b3..72dcc4f 100644 --- a/Source/cmPolicies.h +++ b/Source/cmPolicies.h @@ -203,6 +203,9 @@ class cmMakefile; 3, 8, 0, cmPolicies::WARN) \ SELECT(POLICY, CMP0068, \ "RPATH settings on macOS do not affect install_name.", 3, 9, 0, \ + cmPolicies::WARN) \ + SELECT(POLICY, CMP0069, \ + "INTERPROCEDURAL_OPTIMIZATION is enforced when enabled.", 3, 9, 0, \ cmPolicies::WARN) #define CM_SELECT_ID(F, A1, A2, A3, A4, A5, A6) F(A1) @@ -225,7 +228,8 @@ class cmMakefile; F(CMP0060) \ F(CMP0063) \ F(CMP0065) \ - F(CMP0068) + F(CMP0068) \ + F(CMP0069) /** \class cmPolicies * \brief Handles changes in CMake behavior and policies diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index 9c9296e..a9ccc68 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -2239,6 +2239,9 @@ bool cmVisualStudio10TargetGenerator::ComputeClOptions( linkLanguage, configName.c_str()); } + // Check IPO related warning/error. + this->GeneratorTarget->IsIPOEnabled(configName); + // Get preprocessor definitions for this directory. std::string defineFlags = this->GeneratorTarget->Target->GetMakefile()->GetDefineFlags(); |