Browse Source

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
Niels Dekker 7 years ago
parent
commit
567fabe88e

+ 6 - 0
Help/release/dev/vs-ipo.rst

@@ -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.

+ 1 - 1
Modules/CheckIPOSupported.cmake

@@ -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()

+ 2 - 0
Source/cmGlobalVisualStudio10Generator.h

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

+ 7 - 2
Source/cmVisualStudio10TargetGenerator.cxx

@@ -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();

+ 1 - 0
Source/cmVisualStudio10TargetGenerator.h

@@ -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;

+ 1 - 1
Tests/RunCMake/CMP0069/RunCMakeTest.cmake

@@ -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()

+ 1 - 1
Tests/RunCMake/CheckIPOSupported/RunCMakeTest.cmake

@@ -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()