IPO: INTERPROCEDURAL_OPTIMIZATION (LTCG) for Visual Studio

Add IPO support for Visual Studio (which is referred to by VS as
"Link Time Code Generation" and "Whole Program Optimization"), for
VS version >= 10.  This allows CMake/VS users to enable IPO by setting
property `INTERPROCEDURAL_OPTIMIZATION`.

Fixes: #16748
This commit is contained in:
Niels Dekker
2018-09-09 23:04:59 +02:00
committed by Brad King
parent ccb6dab9f1
commit 567fabe88e
7 changed files with 19 additions and 5 deletions

View File

@@ -0,0 +1,6 @@
vs-ipo
------
* The :ref:`Visual Studio Generators` for VS 2010 and above learned to
support the :prop_tgt:`INTERPROCEDURAL_OPTIMIZATION` target property
and supporting :module:`CheckIPOSupported` module.

View File

@@ -226,7 +226,7 @@ function(check_ipo_supported)
endif()
endforeach()
if(CMAKE_GENERATOR MATCHES "^Visual Studio ")
if(CMAKE_GENERATOR MATCHES "^Visual Studio 9 ")
_ipo_not_supported("CMake doesn't support IPO for current generator")
return()
endif()

View File

@@ -111,6 +111,8 @@ public:
bool FindMakeProgram(cmMakefile* mf) override;
bool IsIPOSupported() const override { return true; }
static std::string GetInstalledNsightTegraVersion();
cmIDEFlagTable const* GetClFlagTable() const;

View File

@@ -1122,6 +1122,9 @@ void cmVisualStudio10TargetGenerator::WriteMSToolConfigurationValues(
this->GeneratorTarget->GetPropertyAsBool("VS_WINRT_EXTENSIONS")) {
e1.Element("WindowsAppContainer", "true");
}
if (this->IPOEnabledConfigurations.count(config) > 0) {
e1.Element("WholeProgramOptimization", "true");
}
}
void cmVisualStudio10TargetGenerator::WriteMSToolConfigurationValuesManaged(
@@ -2485,8 +2488,10 @@ bool cmVisualStudio10TargetGenerator::ComputeClOptions(
clOptions.AddFlag("CompileAs", "CompileAsCpp");
}
// Check IPO related warning/error.
this->GeneratorTarget->IsIPOEnabled(linkLanguage, configName);
// Put the IPO enabled configurations into a set.
if (this->GeneratorTarget->IsIPOEnabled(linkLanguage, configName)) {
this->IPOEnabledConfigurations.insert(configName);
}
// Get preprocessor definitions for this directory.
std::string defineFlags = this->Makefile->GetDefineFlags();

View File

@@ -204,6 +204,7 @@ private:
bool NsightTegra;
unsigned int NsightTegraVersion[4];
bool TargetCompileAsWinRT;
std::set<std::string> IPOEnabledConfigurations;
cmGlobalVisualStudio10Generator* const GlobalGenerator;
cmLocalVisualStudio10Generator* const LocalGenerator;
std::set<std::string> CSharpCustomCommandNames;

View File

@@ -5,6 +5,6 @@ run_cmake(CMP0069-NEW-cmake)
run_cmake(CMP0069-NEW-compiler)
run_cmake(CMP0069-WARN)
if(RunCMake_GENERATOR MATCHES "^Visual Studio ")
if(RunCMake_GENERATOR MATCHES "^Visual Studio 9 ")
run_cmake(CMP0069-NEW-generator)
endif()

View File

@@ -8,6 +8,6 @@ run_cmake(not-supported-by-compiler)
run_cmake(save-to-result)
run_cmake(cmp0069-is-old)
if(RunCMake_GENERATOR MATCHES "^Visual Studio ")
if(RunCMake_GENERATOR MATCHES "^Visual Studio 9 ")
run_cmake(not-supported-by-generator)
endif()