5

I'm using CMake to genenerate my Makefile's however I cannot generate the .clang_complete using the standard

make CC='~/.vim/bin/cc_args.py gcc' CXX='~/.vim/bin/cc_args.py g++' -B

nothing gets generated...

the tree structure looks like so

Root
 |
 |_core
 |  |_src
 |  |  |_main.cpp
 |  |  |_CMakeLists.txt (1)
 |  |_inc
 |  |_CMakeLists.txt (2)
 |
 |_lib
 |  |_rtaudio
 |
 |_CMakeLists.txt (3)

CMakeLists.txt (1) file:

 include_directories("${Dunkel_SOURCE_DIR}/core/inc")

include_directories("${Dunkel_SOURCE_DIR}/lib/")
link_directories("${Dunkel_SOURCE_DIR}/lib/rtaudio")

add_executable(Dunkel main.cpp)

target_link_libraries(Dunkel rtaudio)

CMakeLists.txt (2) file:

subdirs(src)

CMakeLists.txt (3) file:

CMAKE_MINIMUM_REQUIRED(VERSION 2.8)

PROJECT(Dunkel)
SUBDIRS(core)

set(CMAKE_CXX_FLAGS "-g")

What am I doing wrong here?

Tom
  • 15,798
  • 4
  • 37
  • 48
Pepe
  • 405
  • 5
  • 12
  • Is `make ...` a typo? You need to run `CC=gcc CXX=g++ cmake /path/to/src`. What is in these python scripts `~/.vim/bin/cc_args.py`? – Bort Jan 29 '13 at 09:18
  • 1
    cc_args wraps calls to the compiler pointed to by CC CXX variables. it processes each call and outputs any external depdencies to a config file called .clang_complete so when clang_complete is looking for the source files etc of some external lib it knows where to look. – Pepe Jan 30 '13 at 16:06

4 Answers4

4

Looks like contrary to make cmake doesn't expand tilde, hence it treats is as part of the path. To make it work as expected either use absolute path to the cc_args.py script or do two simple changes in the command:

  1. Replace the tilde with $HOME.
  2. Replace single quotes with double quotes.

After the changes your command should look like this:

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

And it should work.

xaizek
  • 5,098
  • 1
  • 34
  • 60
  • I just tried this on OS X 10.9.5 with cmake 3.0.2 and had to provide the full user path. $HOME is correctly set, but it appears that it is not getting expanded – thisisdog Nov 12 '14 at 01:04
  • @thisisdog, it depends on the shell you use. `CXX=~/...` might work instead, `CXX="$HOME/..."` works fine in bash. – xaizek Nov 12 '14 at 07:27
  • Please see my answer, I tried to follow your advice, but perhaps `CXX` is not the correct variable to use (at least for me), because nothing related to "cc_args" is coming out of cmake... – fferri Oct 06 '17 at 12:33
2

You should run (in your build directory)

CXX='~/.vim/bin/cc_args.py g++' cmake ..

and then run make as usual. Note that this will run the cc_args.py script every time you build the project with make, if you want to disable this, re-run cmake again.

The file .clang_complete will be created in the build directory, move it if needed.

See also Vim: Creating .clang_complete using CMake

Guy
  • 1,984
  • 1
  • 16
  • 19
  • problem is with this approach i get "Could not find compiler set in environment variable CXX: ~/.vim/bin/cc_args.py clang++. – Pepe Jan 30 '13 at 20:08
  • Sounds like your cc_args.py doesn't resides in `~/.vim/bin/cc_args.py` – Guy Jan 30 '13 at 22:17
  • it does... pepe@ppp:~/.vim/bin$ ls -l total 12 -rwxrwxrw- 1 pepe pepe 1816 Jan 26 01:15 cc_args.py – Pepe Jan 30 '13 at 22:33
1

It is important to use $HOME/.vim/bin/cc_args.py and not ~/.vim/bin/cc_args.py, because ~ might not get expanded when quoted.

Also, verify the presence of the python script with:

$ ls -l $HOME/.vim/bin/cc_args.py
-rwxr-xr-x  1 myself  staff  2270 Sep 19 16:11 /home/myself/.vim/bin/cc_args.py

if not found, adjust the python script path as necessary.

Run make clean in the build dir.

As suggested by @xaizek, start with an empty build directory (assuming the build directory is a subdir of the source dir):

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

followed by:

make

at this point, make will be building the project, but calling cc_args.py (which will call g++), instead of directly calling g++.

However this part for me is failing to work, and no .clang_complete file is created in the build directory or anywhere else.

In fact, there is no occurrence of "cc_args" in the generated CMakeCache.txt / Makefile, so I suspect CXX is not the correct variable name to pass to cmake.

When finished, copy .clang_complete to the parent dir.

fferri
  • 18,285
  • 5
  • 46
  • 95
  • Inadequate quirks of cmake are everywhere... See their [docs](https://cmake.org/cmake/help/v3.10/envvar/CXX.html). You need to remove `CMakeCache.txt` yourself if it's left from previous build or `$CXX` won't be respected. I don't see a documented way to specify compiler command with an argument via `-D` parameters.... (this seems to work though `-DCMAKE_CXX_COMPILER=".../cc_args.py" -DCMAKE_CXX_COMPILER_ARG1=g++`). – xaizek Oct 06 '17 at 13:17
0

Here is what worked for me

sudo chmod a+x $HOME/.vim/bin/cc_args.py
CXX="$HOME/.vim/bin/cc_args.py  g++"  sudo cmake ..
sudo make

and then ls -a shows my .clang_complete file but still emtyp though.

Misgevolution
  • 825
  • 10
  • 22