2

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?

cppBeginner
  • 1,114
  • 9
  • 27
  • Works fine for me. Did you actually apply this sheet to project configuration? – user7860670 May 28 '19 at 08:04
  • @VTT I imported via Property Manager i.e. ` ... ` in `.vcxproj`. I will verify it again. Thank. – cppBeginner May 28 '19 at 08:08
  • @VTT I tried to set it in property sheet, but the whole program optimization setting in "project property page" (the popup that can be chosen when right click on a project in "Solution Explorer") still appear as "no". ... The performance of the final exe is also same as "no". .... Are you using VS2017 or different version? – cppBeginner May 28 '19 at 08:26
  • I'm using VS2017 15.9.12 – user7860670 May 28 '19 at 08:30
  • @VTT Thank, that tells me something .... interesting. – cppBeginner May 28 '19 at 08:31
  • Note the Condition you used for the ImportGroup. Only active for the Debug configuration, not for Release. Delete that Condition. Best to use the "visual" in Visual Studio, View > Other Windows > Property Manager. – Hans Passant May 28 '19 at 10:27
  • @cppBeginner Did you get it working? I'm trying the same thing, but without the condition, because we already have a dedicated propsheet for release builds. But for some reason the option doesn't show up in the projects which inherit this propsheet. I tried adding `Label="Configuration"` to the PropertyGroup, because that's how it shows up in a vcxproj file, but that didn't help either. – Simpleton Nov 17 '20 at 10:05
  • @Simpleton :: If my memory is still correct, I couldn't find the answer. However, after I measure the performance, the flag result ranged from very little positive to minor negative (-20% to +5%). Thus, I have stopped using the flag altogether. – cppBeginner Nov 17 '20 at 10:26
  • 1
    I tried to use the Property Manager to create a new propsheet containing the option, but it doesn't turn up there either. I guess that's because it's a meta setting. So I ended up using the actual settings instead, see below. I didn't do a performance test, sizewise it has only minor effects for me, but it tripled the build time. `true UseLinkTimeCodeGeneration` – Simpleton Nov 17 '20 at 11:16

1 Answers1

0

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 ]
Flo
  • 16
  • 3