Msbuild and ClCompile options

Msbuild and ClCompile options

本文关键字:options ClCompile and Msbuild      更新时间:2023-10-16

我用msbuild编译C++代码,并在ClCompile项中指定cl选项。像...

<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" />

以上只是一个例子。 现在我想打印用于cl调用的所有选项。 问题是:我该怎么做? 我第一次尝试使用类似以下内容的内容:

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

可悲的是,这只记录文件名(something.cpp),而不是选项。

请注意,我知道编译器选项由Tracker.exe存储在CL.command.*.tlog文件中,但首先,我不想依赖它,因为它可能会发生变化,其次,我很可能需要在以后进行一些转换。我也知道我可以访问单个选项(如%(ClCompile.FloatingPointModel)),但我也不想单独处理每个选项。

有没有更好的方法可以做到这一点?

没有微不足道的解决方案可以做到这一点。你可以在这里找到一个起点这里还有一个例子