How to extract compilation args for each compilation unit in a vcxproj?

筅森魡賤 提交于 2019-12-06 02:49:47

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

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.

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.

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

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

You may be interested in reading this compile_commands.json for Windows/MSVC

You can try to parse the CL.command.* files in the intermediate directories.

https://gist.github.com/Trass3r/f3fbe6807d28106e917368c33abf45d4

I know this is really old, but the question is still relevant, so for those still looking for an answer, I managed to finally do this recently using this little VS extension.

Just install it and a new 'Sourcetrail' menu will appear, with a 'Create Compilation Database' entry (I found Intellisense needs to be enabled for it to be clickable). That will let you customize what to include and generate a compile_commands.json that you can use with other clang-based tools, etc.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!