diff options
author | Ruslan Baratov <ruslan_baratov@yahoo.com> | 2017-03-09 13:05:19 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2017-03-30 18:56:46 (GMT) |
commit | 1588a577d16cfb1a689a444b1db1df3ccff2cc3d (patch) | |
tree | 1c4e4a60729202be6992079fc41501d736caefb2 /Source | |
parent | a75757004bda0ff32a152a0d9d6379c02b1338ce (diff) | |
download | CMake-1588a577d16cfb1a689a444b1db1df3ccff2cc3d.zip CMake-1588a577d16cfb1a689a444b1db1df3ccff2cc3d.tar.gz CMake-1588a577d16cfb1a689a444b1db1df3ccff2cc3d.tar.bz2 |
Add policy CMP0069 to enforce INTERPROCEDURAL_OPTIMIZATION
Previously the `INTERPROCEDURAL_OPTIMIZATION` target property was
honored only for the Intel compiler on Linux and otherwise ignored. In
order to add support for more compilers incrementally without changing
behavior in the future, add a new policy whose NEW behavior enforces the
`INTERPROCEDURAL_OPTIMIZATION` property. Add flags for supported
compilers and otherwise produce an error.
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmGeneratorTarget.cxx | 58 | ||||
-rw-r--r-- | Source/cmGeneratorTarget.h | 1 | ||||
-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/cmLocalVisualStudio7Generator.cxx | 3 | ||||
-rw-r--r-- | Source/cmPolicies.h | 6 | ||||
-rw-r--r-- | Source/cmVisualStudio10TargetGenerator.cxx | 3 |
9 files changed, 78 insertions, 2 deletions
diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 2199e4a..bb79050 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) @@ -659,7 +660,62 @@ const char* cmGeneratorTarget::GetFeature(const std::string& feature, bool cmGeneratorTarget::IsIPOEnabled(const std::string& config) const { const char* feature = "INTERPROCEDURAL_OPTIMIZATION"; - return cmSystemTools::IsOn(this->GetFeature(feature, config)); + 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) diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h index 0ec7389..80bccd5 100644 --- a/Source/cmGeneratorTarget.h +++ b/Source/cmGeneratorTarget.h @@ -743,6 +743,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 b3cb41f..6432538 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 77f3408..45993ce 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -1664,6 +1664,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/cmLocalVisualStudio7Generator.cxx b/Source/cmLocalVisualStudio7Generator.cxx index 7c33821..cd5b46b 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/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 84767a8..2ab72dc 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(); |