c++ - Msbuild 和 ClCompile 选项

标签 c++ msbuild cl vcxproj

<分区>

我使用 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)),但我也不想单独处理每个选项。

有更好的方法吗?

最佳答案

没有简单的解决方案可以做到这一点。 你可以找到一个起点 here 另一个例子 here

关于c++ - Msbuild 和 ClCompile 选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36887836/

相关文章:

powershell - 从 PowerShell 运行 MSBuild

msbuild - 有关于 MSBuild 脚本的好的教程吗?

c++ - boost::asio:数据损坏

c++ - 指针和非指针类型的重载 -> 运算符

c# - 使用 C# 进行异地构建

无法从 Windows 批处理脚本构建 C 程序

c - 在 MSVC 2010 命令行中强制进行 32 位编译

c++ - 使用不同工具集的 CL.exe 进行编译

c++ - 在模板参数推导过程中会发生什么?

c++ - 使用 g++ 链接我的程序