Question

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.

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++'

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.

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).

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?

Was it helpful?

Solution 2

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++

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.

OTHER TIPS

The solution is to set the CXX environment variable before executing cmake. Something like that:

CXX="$HOME/.vim/bin/cc_args.py clang++" cmake ..
make

See http://www.guyrutenberg.com/2013/01/29/vim-creating-clang_complete-using-cmake/ for more details.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top