Meson: Docs: Meson & CLion

Created on 2 Jan 2020  路  6Comments  路  Source: mesonbuild/meson

Some links I found that can help anyone working with Meson & CLion:

Compilation Database

Custom Build Targets and Applications

CLion 2018.2 EAP: open project from Compilation Database

CLion 2018.2.3: better compilation database integration

Feel free to add this information to the docs. Note that I don't have any experience working with CLion.

Most helpful comment

This tip works great.

Drawback: The compile_commands.json resides in the build directory and opening this files as project, creates all CLion specific files (.idea/) in the same directory. So if you cleanup your build directory, the CLion files are deleted too!
Any suggestions how to handle this? Generate the compile_commands.json in an other directory? How?

There is a ticket to handle this: https://youtrack.jetbrains.com/issue/CPP-13699

Workaround: Before opening the compile_commands.json as project, create a symlink in the project root directory, e. g. ln -s build/compile_commands.json .
When creating the _External Tool_ for the _Custom Build Target_, enter $ProjectFileDir$ as _Working Directory_ (The symbolic link is resolved by CLion therefore $ProjectFileDir$/build points to the wrong location).

All 6 comments

I actually find this useful for developing a custom backend for CLine in Meson-UI, thanks.

This tip works great.

Drawback: The compile_commands.json resides in the build directory and opening this files as project, creates all CLion specific files (.idea/) in the same directory. So if you cleanup your build directory, the CLion files are deleted too!
Any suggestions how to handle this? Generate the compile_commands.json in an other directory? How?

I don't know, but you can ask JetBrains/their community:

https://www.jetbrains.com/help/clion/getting-help.html

This tip works great.

Drawback: The compile_commands.json resides in the build directory and opening this files as project, creates all CLion specific files (.idea/) in the same directory. So if you cleanup your build directory, the CLion files are deleted too!
Any suggestions how to handle this? Generate the compile_commands.json in an other directory? How?

There is a ticket to handle this: https://youtrack.jetbrains.com/issue/CPP-13699

Workaround: Before opening the compile_commands.json as project, create a symlink in the project root directory, e. g. ln -s build/compile_commands.json .
When creating the _External Tool_ for the _Custom Build Target_, enter $ProjectFileDir$ as _Working Directory_ (The symbolic link is resolved by CLion therefore $ProjectFileDir$/build points to the wrong location).

It's useful to know that meson already generates compile_commands.json into the build directory, but this is currently not obvious from the docs: https://github.com/mesonbuild/meson/issues/3545#issuecomment-588367563

This means you do not have to generate it manually as shown on https://web.archive.org/save/https://wanzenbug.xyz/clion-meson-compiledb/

ln -s build/compile_commands.json .

Note for others: If you switch to that approach, best clean out related .idea/ folders first, otherwise opening that symlink will continue to open the your build directory as the project root.

Was this page helpful?
0 / 5 - 0 ratings