cquery-project / emacs-cquery

Emacs client for cquery, a low-latency language server supporting multi-million line C++ code-bases
116 stars 14 forks source link

Can I point to a compile_commands.json out-of-source? #50

Closed kxygk closed 5 years ago

kxygk commented 5 years ago

So I thought this was more common, but I have everything setup to build out-of-source using CMake. (My source actually lives on a USB drive and I move it from machine to machine)

To make it more concrete:

I have my code in /home/geokon/USB/Projects/someproject So there will be a /home/geokon/USB/Projects/someproject/CMakeLists.txt and some folder with my source files like /home/geokon/USB/Projects/someproject/src

But I'm building somewhere completely else like

/home/geokon/SomeBuildArea and it'll have a /home/geokon/SomeBuildArea/CMakeCache.txt /home/geokon/SomeBuildArea/compile_commands.json and libs, binaries etc.

So can I somehow tell cquery the path to a compile_commands.json for a source tree somewhere completely else? Or do I set the project root to be the build directory and it will magically work with all my source files that aren't actually under the same file root?

I could make some hack to move the compile_commands.json to the source directory.. but I'd like to really avoid doing that.

Thanks! This is a really awesome project. Hope I can get it working for my setup :)

vanjoe commented 5 years ago

As far as I can tell it only looks for a compile_commands.json or a builds/compile_commands.json in a directory that is (grand-)*parent of the file. I also find this a bit annoying because for various reasons I don't always call my build directory "build"

kxygk commented 5 years ago

Hmmm, yeah. I'm trying to see if I can somehow patch it in.

@vanjoe are you looking at this line? https://github.com/cquery-project/emacs-cquery/blob/master/cquery.el#L115

I'm not so hot with ELisp macros... I can't really tell where it goes from here

dscole commented 5 years ago

@geokon-gh I just create a symlink:

ln -s path/to/build/dir/compile_commands.json -rt /path/to/project/root

kxygk commented 5 years ago

@dscole Yeah, that a quick hack that works. Thanks :)

I realize there is no real obvious way to easily automate this (b/c there is no CMake build tool in Emacs as of yet) - but I'd like to be able to just have the ability to redirect the compile_commands.json from within Emacs/Cquery. It'd make the workflow a lot smoother and easier to automate. Having to make a new simlink each time I make a new build directory is less clean (and if you make many build directories it's a bit impractical)

jacobdufault commented 5 years ago

You can use the compilationDatabaseDirectory init option for this.