3

I have irony-mode configured and I'm using it for a C++-project. The code is built using Make. I have a number of different make targets to build the code; test code, release code, unit test code etc. Each make target uses its own set of compilation flags and the unit test code is placed in a subdirectory. All this makes using one single compilation database for irony-mode less than ideal.

For each make target I have defined a corresponding make target that runs the build through Bear to generate a compilation database for the specific make target. Then I try to make irony-mode switch to using this newly generated compilation database by running the function irony-cdb-json-select. It is documented as

Select CDB to use with a prompt.

It is useful when you have several CDBs with the same project
root.

But when I do irony-cdb-menu nothing has changed, the compilation flags that should have been there are not there.

How do I force irony-mode to update the compilation database?

Edited

Using one Make target for release code and another for unit tests means a specific source file can be compiled using two different sets of compile flags. Unit tests makes use of mock objects which means in this context the list of includes (-I) might differ compared to compiling release code. So depending on if I work on release code or unit tests I think I need two different compilation databases.

The file compile_commands.json generated by Bear contains an entry for each source file. Does irony-mode read each entry and use the specific settings for one specific source file? Or does irony-mode read the first entry in compile_commands.json and applies these settings to all source files in the project? I could create one compile_commands.json by appending output from release builds and unit test builds so that the resulting compile_commands.json would have entries with different sets of include flags (-I) without duplicates for the same file of course. Is irony-mode sensitive to this?

Mikael Springer
  • 513
  • 3
  • 13

1 Answers1

1

Why is using a single compilation database less than ideal? This is usually what people do. I agree, multi-databases support is useful to some build systems. I consider mostly for "full stack" build systems that some company and organizations have.

Would the compilation database be too big for all your targets? Taking a huge time to load?

Can't you dispatch the compilation database per directory? So if you have:

  • targetA/src/foo.cpp
  • targetB/src/bar.cpp

You could put the compile_commands.json in targetA/ and targetB/ respectively.

Anyway, your issue seems different here. If you call M-x irony-cdb-autosetup-compile-options RET manually, do you see something in M-x irony-cdb-menu RET?

Can you try on this sample project?

mkdir /tmp/testcdb
cd /tmp/testcdb
cat <<'EOF' > /tmp/testcdb/compile_commands.json
[
{
    "directory": "/tmp/testcdb",
    "command": "clang++ -std=c++11 -c foo.cpp -o foo.o"
    "file": "/tmp/testcdb/foo.cpp",
}
]
EOF
echo 'void f() { auto i = 0; }' > foo.cpp
emacs foo.cpp

Can you show me an extract of your generated compilation database? I just have an idea of what could be the issue, if the Bear version you use is recent, it's possible that it uses a new compilation database format that irony-mode does not support, and that your libclang may not also be lacking support for.

Guillaume Papin
  • 886
  • 6
  • 7