A new CLion 2018.2 EAP (build 182.2757.13) is now available! Download it from our site, use ToolBox App or get a patch-update in the IDE in case you are using the previous EAP build. No license is required and the build is free to use, but it will expire within 30 days of the build date.
Open project from compilation database
In brief, the Compilation database format is now supported in CLion as a project model. You cannot build or run for now, but code insight does work for such projects.
What’s happening with CLion lately?
For many release cycles, CLion was a CMake-only IDE, meaning it did not support any non-CMake-based projects. But recently, we’ve started decoupling CMake from CLion. Beginning with CLion 2018.1, you can open any file or folder in CLion, even if no proper CMake model is provided. However, code insight in these cases is limited as the IDE doesn’t know enough about the project.
For Rust, we supported the Cargo build system via the Rust plugin in CLion. CLion 2018.2 EAP introduces support for Gradle C++ projects.
Slowly but surely we’re supporting more build systems in CLion!
What is a compilation database?
It’s a set of all compile options used to build the files in a project. A sample file looks like this:
"command": "/usr/local/bin/g++-7 -I/Users/me/prj/Calendar/calendars -g -std=c++11 -o calendar_run.dir/main.cpp.o -c /Users/me/prj/Calendar/main.cpp",
"command": "/usr/local/bin/g++-7 -I/Users/me/prj/Calendar/calendars -g -std=c++11 -o calendars.dir/calendar_defs.cpp.o -c /Users/me/prj/Calendar/calendars/calendar_defs.cpp",
More detailed information on compilation databases can be found here.
How to get a compilation database json file?
There is a list of build systems, compilers, and specialized tools that support the generation of compilation database files. For example, CMake generates it when
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) is used (for Ninja and Makefiles generators). For Clang v5.0 and later,
-MJ option does the trick. For Ninja v1.2 and later, the option is called
-t compdb. Tools like bear and intercept-build help generate a compilation database json by intercepting calls to the compiler during the build. There is even an extension to Visual Studio that generates the compilation database file from VS solutions. And for make-based build systems compiledb-generator is a tool to generate compilation database.
I’ve got a compilation db json file for my project. What’s next?
Select Open in CLion and point it to your compilation database json file (or the directory containing such a file):
Click ‘Open as a project’ and you are done! The status of all commands in compile_commands.json will be provided for you in CLion:
The directory containing the compilation database json file is treated as the project root by default. You can change the project root later, by going to Tools | Compilation Database and selecting Change Project Root.
Code insight, including code completion, code navigation, refactoring and code analysis, is fully available:
Any known limitations?
The most important point is that due to the lack of the corresponding information in compilation database files, it’s not yet possible to build, run, or debug such projects. We do plan to add the ability to provide building and running commands for such projects.
Our first step will be to add an ability to Compile a single file using the compilation command from the compilation database (CPP-13059).
Other improvements and fixes include:
- WSL support in CLion now works correctly with Ubuntu 18.04 (CPP-12968).
- CLion can now launch Valgrind Memcheck for Gradle Native Application configuration (CPP-13013).
The full release notes are available here.
Your CLion Team
The Drive to Develop