2016-04-27 411 views
0

我使用msbuild编译C++代码,并在ClCompile项目中指定cl选项。像...Msbuild和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.exe存储在CL.command.*.tlog文件,但首先,我不希望依赖于因为它是随时更改,第二,我将最有可能需要做一些稍后转换。我也知道我可以访问单个选项(如%(ClCompile.FloatingPointModel)),但我不想单独处理每个选项。

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

回答

1

有没有微不足道的解决方案来做到这一点。 你可以找到一个起点here 和另一个例子here