Chromium Docs - CLion Dev (original) (raw)
CLion is an IDE
Prerequisite: Checking out and building the chromium code base
Setting up CLion
- Install CLion
- Googlers only: See go/intellij-getting-started for installation and license authentication instructions
- Run CLion
- Increase CLion's memory allocation
This step will help performance with large projects- Option 1
- At the startup dialog, in the bottom left corner, click on the Cog icon and then click on
Edit Custom VM Options
: - In the textbox, you will see different flags. Add or replace the following flags (to learn more: Advanced configuration | IntelliJ IDEA):
-Xss2m
-Xms1g
-Xmx31g
... - Close the
Edit Custom VM Options
dialog. - Again, at the startup dialogue, in the bottom left corner, click on the Cog icon and then click on
Edit Custom Properties
: - Add or replace the following flags (to learn more: Platform Properties | IntelliJ IDEA):
idea.max.intellisense.filesize=12500
- At the startup dialog, in the bottom left corner, click on the Cog icon and then click on
- Option 2; 2017 and prior versions may not include the options to setup your
VM Options
andProperties
in theconfigure
menu. Instead:Create New Project
Help
>Edit Custom VM Options
Help
>Edit Custom Properties
- Option 1
Creating a new CLion project
- Import project
- At the startup dialog, select
Import Project
and select yourchromium
directory; this should be the parent directory tosrc
. Selectingsrc
instead would result in some CLion IDE files appearing in your repository.
- At the startup dialog, select
Building, Running, and Debugging within CLion
Configure CLion to use ninja for building (see Linux Build Instructions)
Custom Build Targets
A custom Build Target allows CLion to compile Chromium similarly to running ninja in the command line.
Add a Custom Build Target
The first step is to add Ninja (specifically autoninja) as an external tool that will be used to create the build targets.
- Go to
Settings
- Then, to
Build, Execution, Deployment > Custom Build Targets
- Click on the
+
sign to add a new build target. - Fill the Name:
Default
- Next to
Build
, click on the three dots (...
) - Click on
+
to add an External Tool - Fill the form:
- Name:
autoninja - Default
- Program:
<absolute path to depot_tools/autoninja>
- Arguments:
-C out/Default chrome
- Working Directory:
<absolute path to chromium/src>
- Name:
- Click
Ok
to close the dialog.
Run/Debug configuration
The build target configured in the previous section was necessary to configure the Run/Debug configuration.
- Click on the
Run
menu and then onEdit Configurations
. - Click on the
+
sign then onCustom Build Application
- Fill the form:
- Name:
Default
- Target: Select the
Default
build target that was created previously. - Executable: Click the three dots (
...
) and selectsrc/out/Default/chrome
- Name:
- Click
Ok
to close the dialog.
Configure ~/.gdbinit
Before being able to debug, you need to configure ~/.gdbinit
. Open it with a text editor and enter:
source
Set the local gdb executable
There have been some reports of slowness while debugging using CLion. It seems that using that CLion's bundled gdb executable is the culprit. To use the local one:
- Open
Settings
- Search for
Toolchains
- Next to
Debugger
, select/usr/bin/gdb
Run Chrome!
You can now run chrome directly from CLion. You can also debug and add a breakpoint. Try it!
Run
> Run
(shift+f10
) or Run
> Debug
(shift+f9
) (screenshot)
Autocompletion
Approach 1: Using CMakeLists
Note: It's possible that when you open the project, CLion created one for you.
- Create or Modify the
chromium/CMakeLists.txt
file- Open
chromium/CMakeLists.txt
- Add or Replace the content with:
cmake_minimum_required(VERSION 3.10)
project(chromium)
set(CMAKE_CXX_STANDARD 14)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/out/Default/gen)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/third_party/protobuf/src)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/third_party/googletest/src/googletest/include)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/third_party/googletest/src/googlemock/include)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/third_party/abseil-cpp)
The following file used is irrelevant, it's only to improve CLion
performance. Leaving at least 1 file is required in order for CLion
to provide code completion, navigation, etc.
add_executable(chromium src/components/omnibox/browser/document_provider.cc)
- Open
Approach 2: Compilation database
Since Chromium does not use CMake to build, to “benefit from the advanced IDE features that CLion provides”, a Compilation database must be created to expose to CLion how Chromium is built.
In the Chromium code source, there’s a python script src/tools/clang/scripts/generate_compdb.py
that will generate the Compilation Database.
Note: The two approaches are not currently compatible and switching between one and the other is cumbersome. To go from approach 1 to 2, the CMakeWorkspace
line from .idea/misc.xml
must be removed first.
- Run from your
chromium
folder:
python3 src/tools/clang/scripts/generate_compdb.py -p src/out/Default -o ./compile_commands.json --target_os=linux
This generates the compilation database atchromium/compile_commands.json
. - In CLion, select the
compile_commands.json
file in the project navigator, right-click on it, then click onLoad Compilation Database Project
.
Note: This step will produce a few hundred errors but it doesn‘t cause any issues. It’s simply because some files are not compiled. To remove some errors, these flags can be added insrc/out/Default/args.gn
:
enable_nocompile_tests=true - CLion will start processing the files and will start indexing the symbols. This step can take a few hours. To expedite this process, see the section Exclude irrelevant folders from indexing to speed up CLion below.
Optional Steps
Create terminal cli or desktop entry
To make it easier to startup CLion or open individual files:
- Open the actions menu (
ctrl+shift+a
) - Type
create desktop entry
and pressenter
- Open the actions menu and enter
create command-line launcher
Exclude irrelevant folders from indexing to speed up CLion
Exclude folders that are irrelevant to your work from the indexing. Exclude at first the following folders and manually include the ones relevant to you. Open chromium/.idea/misc.xml
and under <project>
add or edit the following XML component:
Note: This step can be done from the UI in the Project view by selecting all the folders to exclude, right-clicking on them, selecting Mark Directory As
and then selecting Excluded
.
Mark directories as Library Files
To speed up CLion, optionally mark directories such as src/third_party
as Library Files
- Open the
Project
navigation (alt+1
) - Select and right-click the directories >
Mark directory as
>Library Files
- See
https://blog.jetbrains.com/clion/2015/12/mark-dir-as/
for more details