title: WholeProgramOptimization in CMake
body: <p><strong>What can I do to enable <code>WholeProgramOptimization</code> from CMake ?</strong></p>
  
  <p>Here is what I tried:</p>
  
  <ul>
  <li>I have CMake 3.10.2 installed</li>
  <li>I have Visual Studio 2017 15.5.4 installed</li>
  <li>I created a directory C:\Wpo</li>
  <li>I created an empty directory C:\Wpo\Build</li>
  <li>I created a C:\Wpo\Wpo.cpp file containing <code>int main(){return 0;}</code></li>
  <li><p>I created a C:\Wpo\CMakeLists.txt file containing the following:</p>
  
  <pre><code>CMAKE_MINIMUM_REQUIRED (VERSION 3.10)
  PROJECT(Wpo)
  ADD_EXECUTABLE(Wpo "../Wpo.cpp")
  TARGET_COMPILE_OPTIONS(Wpo PRIVATE "$&lt;$&lt;CONFIG:Release&gt;:/GL&gt;")
  SET_TARGET_PROPERTIES(Wpo PROPERTIES LINK_FLAGS_RELEASE "/LTCG")
  </code></pre></li>
  <li><p>I openned a command line and created my Visual Studio solution:</p>
  
  <pre><code>cd C:\Wpo\Build
  cmake ..
  </code></pre></li>
  </ul>
  
  <p>But when I open my solution in Visual Studio, Whole program Optimization is not set. Interestingly enough, there is a <code>WholeProgramOptimization</code> in the vcxproj file:</p>
  
  <pre><code>      &lt;ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"&gt;
          &lt;ClCompile&gt;
            &lt;AdditionalIncludeDirectories&gt;%(AdditionalIncludeDirectories)&lt;/AdditionalIncludeDirectories&gt;
            &lt;AssemblerListingLocation&gt;Release/&lt;/AssemblerListingLocation&gt;
            &lt;CompileAs&gt;CompileAsCpp&lt;/CompileAs&gt;
            &lt;ExceptionHandling&gt;Sync&lt;/ExceptionHandling&gt;
            &lt;InlineFunctionExpansion&gt;AnySuitable&lt;/InlineFunctionExpansion&gt;
            &lt;Optimization&gt;MaxSpeed&lt;/Optimization&gt;
            &lt;PrecompiledHeader&gt;NotUsing&lt;/PrecompiledHeader&gt;
            &lt;RuntimeLibrary&gt;MultiThreadedDLL&lt;/RuntimeLibrary&gt;
            &lt;RuntimeTypeInfo&gt;true&lt;/RuntimeTypeInfo&gt;
            &lt;WarningLevel&gt;Level3&lt;/WarningLevel&gt;
  
            &lt;WholeProgramOptimization&gt;true&lt;/WholeProgramOptimization&gt;
  
            &lt;PreprocessorDefinitions&gt;WIN32;_WINDOWS;NDEBUG;CMAKE_INTDIR="Release";%(PreprocessorDefinitions)&lt;/PreprocessorDefinitions&gt;
            &lt;ObjectFileName&gt;$(IntDir)&lt;/ObjectFileName&gt;
            &lt;DebugInformationFormat&gt;&lt;/DebugInformationFormat&gt;
          &lt;/ClCompile&gt;
        &lt;/ItemDefinitionGroup&gt;
  </code></pre>
  
  <p>If I manually select Whole Program Optimizations from the Properties of the Project, an entry is added in another part of the vcxproj file:</p>
  
  <pre><code>      &lt;PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"&gt;
          &lt;ConfigurationType&gt;Application&lt;/ConfigurationType&gt;
          &lt;CharacterSet&gt;MultiByte&lt;/CharacterSet&gt;
          &lt;PlatformToolset&gt;v141&lt;/PlatformToolset&gt;
  
          &lt;WholeProgramOptimization&gt;true&lt;/WholeProgramOptimization&gt;
  
        &lt;/PropertyGroup&gt;
  </code></pre>
  
  <ul>
  <li><strong>Is it a bug from CMake ?</strong> It looks like it is adding this <code>WholeProgramOptimization</code> section in the wrong place.</li>
  <li><strong>Is it a bug from Visual Studio ?</strong> It could be a regression too.</li>
  <li>Am I employing a deprecated way of doing this ? This happens a lot with CMake ;-)</li>
  </ul>
  
  <p>Any help would be greatly appreciated.</p>