enable/disable "Whole program optimization" (/GL) in property sheet (.props)

1.6k Views Asked by At

In project property > C/C++ > Optimization > Whole Program Optimization, I can set /GL.

Can I enable/disable the /GL in a shared property-sheet (.props file) and make many projects bases from it?

I have tried :-

<PropertyGroup>
 <WholeProgramOptimization 
    Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
      true
 </WholeProgramOptimization>

However, it looks like there is no effect.
Do I really have to edit the property of each project manually?

I am using VS2017 Version 15.3.0.

Related: Visual Studio property sheets: Why is Character Set missing?

1

There are 1 best solutions below

0
Flo On

To do this setting using your own property sheet, this one must be included by the projects (.vcxproj) before the Microsoft.Cpp.Default.props.

Otherwise, the properties at the project level will looks good, but not the one used for the CL tasks of the .c(pp).

For example, assuming the following D:\shared\my-customization.props sheet:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ImportGroup Label="PropertySheets" />
  <PropertyGroup Label="UserMacros">
    <MY_CUSTOMIZATION_PREAMBLE>1</MY_CUSTOMIZATION_PREAMBLE>
  </PropertyGroup>

  <PropertyGroup>
    <WholeProgramOptimization>false</WholeProgramOptimization>
     // some others settings suffers from the same restrictions
    <CharacterSet>Unicode</CharacterSet>
    <PlatformToolset>v142</PlatformToolset>
    <UseDebugLibraries Condition="'$(Configuration)'!='Release'">true</UseDebugLibraries>
    <UseDebugLibraries Condition="'$(Configuration)'=='Release'">false</UseDebugLibraries>

    <_PropertySheetDisplayName>MyCustomization preamble</_PropertySheetDisplayName>
  </PropertyGroup>
</Project>

To share them on your several projects, it must be included on theirs .vcxproj like this:

[...]
  <PropertyGroup Label="Globals">
    [...]
  </PropertyGroup>
  <Import Project="D:\my-customization.props" Condition="'$(MY_CUSTOMIZATION_PREAMBLE)' == ''" />
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
     [...]
  </PropertyGroup>
  [...]
  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    [ usual location to import the property sheet ]