1

I compile C++ code with msbuild and I specify cl options inside ClCompile item. Something like...

<ItemGroup>
    <ClCompile Include="something.cpp">
        <FloatingPointModel>Precise</FloatingPointModel>
        <WarningLevel>Level2</WarningLevel>
    </ClCompile>
</ItemGroup>

<Import Project="$(VCTargetsPath)\Microsoft.Cpp.default.props" />
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Targets" />

The above is just an example. Now I want to print all options used for cl invocation. The question is: How do I do that? My first attempt was to use something like the following:

<Target Name="WriteToFile" AfterTargets="ClCompile" >
    <WriteLinesToFile File="$(OutDir)\log.txt" Lines="@(ClCompile)" Overwrite="true" />
</Target>

Sadly, this logs only filename (something.cpp) and not the options.

Note that I'm aware that the compiler options are stored by Tracker.exe in CL.command.*.tlog file, but first, I don't want to rely on that as it's subject to change and second, I will most likely need to do some transformations later on. I also know that I could access individual options (like %(ClCompile.FloatingPointModel)), but I don't want handle each option separately either.

Is there a better way to do this?

Miroslav Franc
  • 1,282
  • 12
  • 13

1 Answers1

1

There is no trivial solutions to do that. You could find a starting point here and another example here

Edgar Rokjān
  • 17,245
  • 4
  • 40
  • 67
Troopers
  • 5,127
  • 1
  • 37
  • 64