如何使用CMAKE_EXPORT_COMPILE_COMMANDS? [英] How to use CMAKE_EXPORT_COMPILE_COMMANDS?

查看:3806
本文介绍了如何使用CMAKE_EXPORT_COMPILE_COMMANDS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直试图使用 clang-modernize CMAKE_EXPORT_COMPILE_COMMANDS ,如此工具的帮助中推荐的。



使用此选项,cmake会生成一个JSON文件,其中包含包含路径(另请参阅)。



此变量在cmake的命令行中接受,
cmake --help变量CMAKE_EXPORT_COMPILE_COMMANDS 不工作(这与此邮寄名单发布)。



有人知道如何使用它吗? >

我也可以使用cppcheck。



一些更多信息 b
$ b

我在 clang开发人员论坛,此cmake功能不适用于所有生成器。这可能会改变在未来,在同一时间我的问题仍然,我会尝试看看如果我使用其他生成器比Visual Studio发生了什么。

解决方案

自CMake 3.5起, CMAKE_EXPORT_COMPILE_COMMANDS 选项为



这意味着要生成一个JSON编译数据库,

  

cmake -DCMAKE_EXPORT_COMPILE_COMMANDS = 1 / path / to / src

(因为它使用makefile生成器,默认)



否则,您可以明确指定如下的生成器:

  cmake -DCMAKE_EXPORT_COMPILE_COMMANDS = 1 / path / to / src -G Ninja 

或:

  cmake -DCMAKE_EXPORT_COMPILE_COMMANDS = 1 / path / to / src -G'Unix Makefiles'
pre>

或者cmake支持的另一个makefiles变体 - 支持生成的列表包含在 cmake --help



请注意,编译数据库JSON文件是在cmake执行时生成的,而不是在编译时生成。此外,使用最近的clang版本(例如clang > = 3.8 ), clang-modernize $ c> clang-tidy 。


I've been trying to use clang-modernize with CMAKE_EXPORT_COMPILE_COMMANDS as recommended in the help of this tool.

With this option cmake generates a JSON file containing compile info like include paths (see also).

This variable is accepted on the command line of cmake, but cmake --help-variable CMAKE_EXPORT_COMPILE_COMMANDS doesn't work (which is coherent with this mailing list posting).

Has someone any idea on how to use it?

I could also use it with cppcheck.

Some more info

I've discovered on a clang developer forum that this cmake feature is not available on all generators. This might change in the future, in the mean time my question remains and I will try too see what happen if I use other generators than Visual Studio.

解决方案

As of CMake 3.5 the CMAKE_EXPORT_COMPILE_COMMANDS option is supported by the Ninja and Makefiles generators.

That means to generate a JSON compile database one has to select a generator that supports it.

For example on UNIX just:

cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=1 /path/to/src

(as it uses the makefile generator there, by default)

Otherwise you can explicitly specify a generator like this:

cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=1 /path/to/src -G Ninja

Or:

cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=1 /path/to/src -G 'Unix Makefiles'

Or another makefiles variant that your cmake supports - a list of supported generated is included in the output of cmake --help.

Note that the compile database JSON file is generated at cmake execution time - not at compile time. Also, with recent clang versions (e.g. clang >= 3.8), clang-modernize was merged into clang-tidy.

这篇关于如何使用CMAKE_EXPORT_COMPILE_COMMANDS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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