如何提取vcxproj中每个编译单元的编译参数? [英] How to extract compilation args for each compilation unit in a vcxproj?

查看:445
本文介绍了如何提取vcxproj中每个编译单元的编译参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图获取每个编译单元的编译参数,以便我可以创建 compilation_commands .json 为我的vcxproj可以使用clang的libTooling。

I'm trying to get the compilation args for each compilation unit so I can create the "compilation_commands.json" for my vcxproj that can be used with clang's libTooling.

libTooling教程使用 CompilationDatabase 为项目中的所有cpp文件提供编译arg。本教程显示,CMake可以为基于CMake的项目生成compilation_commands.json。

The libTooling tutorial suggests using a CompilationDatabase to provide the compilation args for all the cpp files in a project. The tutorial shows that CMake can generate the compilation_commands.json for CMake based projects.

由于clang可以通过 clang.exe --driver-mode = cl clang-cl.exe 我的想法是如果我可以得到每个cpp文件在我的VS2012项目的编译args我可以创建一个vcxproj的compilation_commands.json。

Since clang can be put into "MSVC mode" via clang.exe --driver-mode=cl or clang-cl.exe my thought was if I could get the compilation args for each cpp file in my VS2012 project I can create the compilation_commands.json for a vcxproj.

但是,我在VS2012 SDK中找不到API,因为它遇到了一个vcxproj并检索每个编译单元的编译arg。有人能指点我正确的API?

However I'm having trouble finding APIs in the VS2012 SDK that walks a vcxproj and retrieves the compilation args for each compilation unit. Can someone point me towards the right APIs?

推荐答案

这是一个DIY工作。 VS IDE项目具有每个.cpp文件的属性。通过选择.cpp,然后右键 - >属性 - >配置属性 - > C / C ++ - >命令行,您有编译该特定文件所需的选项。 64美元的问题是如何为项目/解决方案中的每一个吉利做。答案不是微不足道,但它是可行的。至少我在VS 2010上做了,我很确定它可以在VS 2012/3上工作

It is a DIY job. The VS IDE projects have properties for each .cpp file. By selecting a .cpp, then right click -> Properties -> Config properties -> C/C++ -> Command Line you have the options required to compile that specific file. The 64 dollar question is how to do it for every gile in the project / solution. The answer is not trivial, but it is doable. At least I did it on VS 2010 and I'm pretty sure it works on VS 2012/3

秘密在于什么叫VCEngine。它是一个评估项目中所有属性或文件的工具。所以真正的问题是如何评估每个文件的属性命令行。您需要遍历所有.cpp文件,并为命令行属性调用VCProject的Evaluate方法。

The secret lies with what is called VCEngine. It is a tool that evaluates all the properties or the files in the project. So the real problem is how to evaluate the property "Command Line" for each file. You need to iterate through all the .cpp files and call VCProject's Evaluate method for the "Command Line" property.

我认为你可以做的最简单的方法是为VS IDE编写一个插件,从而访问VCEngine实例。有很多例子如何做到这一点。请注意,VCEngine是版本相关的。

The simplest way I think you can do it is to write a plugin for the VS IDE and thus gain access to the VCEngine instance. There are plenty of examples of how to do that. Be aware that the VCEngine is version dependent.

无论如何,对于具有成千上万个.cpp文件的项目/解决方案,您需要自动创建编译数据库。

Anywhay, for projects/solutions with thousands of .cpp files, you need to automate the compilation database creation.

当我有时间,我会把解决方案在github

When I'll have time I will put the solution on github

这篇关于如何提取vcxproj中每个编译单元的编译参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆