1

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

<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.exeCL.command.*.tlog文件中,但首先,我不想依赖它,因为它可能会发生变化,其次,我很可能需要稍后进行一些转换。我也知道我可以访问单个选项(如%(ClCompile.FloatingPointModel)),但我也不想单独处理每个选项。

有一个更好的方法吗?

4

1 回答 1

1

没有简单的解决方案可以做到这一点。您可以在此处找到起点,在此处找到 另一个示例

于 2016-04-27T13:15:09.887 回答