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