CMake和clang_complete [英] CMake and clang_complete

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

问题描述

我想设置我的CMakeLists.txt文件,以便它可以生成vim插件clang_complete所需的.clang_complete文件。

I'm wanting to setup my CMakeLists.txt file so that it can generate the .clang_complete file required by the vim plugin clang_complete.

通常,您会这样做通过将参数传递给编译器提供的python脚本以及用于编译的所有参数来实现。请注意,我省略了cc_args.py的实际目录以节省空间。

Ordinarily, you would do this by passing a parameter to the python script it supplies with the compiler and all of the parameters for compilation. Note that I am omitting the actual directory cc_args.py is in to save on space.

cc_args.py gcc test.c -o test -I~/IncludeDirs/

您也可以在制作阶段执行此操作...

You can also do this during the make phase...

make CC='cc_args.py gcc' CXX='cc_args.py g++'

但是,我不确定如何(如果可能)在CMakeLists.txt文件中进行设置。每次我要设置clang_complete时都必须键入此命令确实很烦人。之所以要这样做,是因为我有多个项目,这些项目使用自定义脚本来构建CMakeLists.txt文件,因此必须为每个脚本编写一个脚本或手动放置一个通用脚本是我的步骤想要避免。

However, I am unsure of how to (if it is possible to) set this up within a CMakeLists.txt file. It's really annoying to have to type this in every time I want to setup clang_complete. The reason why I want to do it this way, is because I have multiple projects that I use a custom script to build the CMakeLists.txt file, so having to write a script for each one or manually place a generic one is a step I'd like to avoid.

到目前为止,我已经尝试了一些错误的解决方法。

I've tried a couple of things that have so far have come up with errors.

我尝试将CMAKE_CC_COMPILER和CMAKE_CXX_COMPILER设置为与第一个类似的行,即 cc_args.py g ++。这里出现的错误表明它找不到编译器(这是可以理解的)。

I've tried setting CMAKE_CC_COMPILER and CMAKE_CXX_COMPILER to lines similar to the first i.e. "cc_args.py g++". The errors that come up here say that It can't find the compiler (which is understandable).

我接下来尝试的是将Compiler变量设置为cc_args .py并为实际的编译器添加一个标志:可以说,这失败了。 CMake说它不能编译测试程序(考虑到脚本不是编译器,并且测试不使用我设置的标志,对此我并不感到惊讶)。

The next thing I tried was setting the Compiler variables just to the cc_args.py and adding a flag for the actual compiler: suffice to say, that failed horribly. CMake said that it couldn't compile a test program (considering the script isn't a compiler, and the tests don't use the flags I set, I'm not surprised at this).

因此,无需编写任何其他需要四处走动的外部脚本,是否有人能想到可以做到这一点的方法?

So without writing any other external scripts that require moving around, is there anyone that can think of a way that can do this?

推荐答案

我知道您说过无需编写任何其他外部脚本,但似乎您只需要一个衬套即可。

I know you said "without writing any other external scripts," but it seems like you just need a one-liner:

exec cc_args.py g++

然后将该文件设置为CMAKE_CXX_COMPILER。如果不想分发它,甚至可以在构建时使用CMake的 file()函数编写单行代码。

And then set that file as your CMAKE_CXX_COMPILER. You could even use CMake's file() function to write the one-liner at build time if you don't want to have to distribute it.

这篇关于CMake和clang_complete的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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