Movatterモバイル変換


[0]ホーム

URL:


project logoChromium Docs

CLion Dev

CLion is an IDE

Prerequisite:Checking out and building the chromium code base

Contents

Setting up CLion

  1. Install CLion

  2. Run CLion

  3. Increase CLion's memory allocation

    This step will help performance with large projects

    1. Option 1
      1. At the startup dialog, in the bottom left corner, click on the Cog icon and then click onEdit Custom VM Options:
      2. In the textbox, you will see different flags. Add or replace the following flags (to learn more:Advanced configuration | IntelliJ IDEA):
        -Xss2m-Xms1g-Xmx31g...
      3. Close theEdit Custom VM Options dialog.
      4. Again, at the startup dialogue, in the bottom left corner, click on the Cog icon and then click onEdit Custom Properties:
      5. Add or replace the following flags (to learn more:Platform Properties | IntelliJ IDEA):
        idea.max.intellisense.filesize=12500
    2. Option 2; 2017 and prior versions may not include the options to setup yourVM Options andProperties in theconfigure menu. Instead:
      1. Create New Project
      2. Help >Edit Custom VM Options
      3. Help >Edit Custom Properties

Creating a new CLion project

  1. Import project
    • At the startup dialog, selectImport 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.

Building, Running, and Debugging within CLion

Configure CLion to use ninja for building (seeLinux 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.

  1. Go toSettings
  2. Then, toBuild, Execution, Deployment > Custom Build Targets
  3. Click on the+ sign to add a new build target.
  4. Fill the Name:Default
  5. Next toBuild, click on the three dots (...)
  6. Click on+ to add an External Tool
  7. Fill the form:
    1. Name:autoninja - Default
    2. Program:<absolute path to depot_tools/autoninja>
    3. Arguments:-C out/Default chrome
    4. Working Directory:<absolute path to chromium/src>
  8. ClickOk to close the dialog.

Run/Debug configuration

The build target configured in the previous section was necessary to configure the Run/Debug configuration.

  1. Click on theRun menu and then onEdit Configurations.
  2. Click on the+ sign then onCustom Build Application
  3. Fill the form:
    1. Name:Default
    2. Target: Select theDefault build target that was created previously.
    3. Executable: Click the three dots (...) and selectsrc/out/Default/chrome
  4. ClickOk 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 <path to chromium>/src/tools/gdb/gdbinit

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:

  1. OpenSettings
  2. Search forToolchains
  3. Next toDebugger, 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) orRun >Debug (shift+f9) (screenshot)debugging screenshot

Autocompletion

Approach 1: Using CMakeLists

Note: It's possible that when you open the project, CLion created one for you.

  1. Create or Modify thechromium/CMakeLists.txt file
    1. Openchromium/CMakeLists.txt
    2. 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)

Approach 2: Compilation database

Since Chromium does not use CMake to build, to “benefit from the advanced IDE features that CLion provides”, aCompilation database must be created to expose to CLion how Chromium is built.

In the Chromium code source, there’s a python scriptsrc/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, theCMakeWorkspace line from.idea/misc.xml must be removed first.

  1. Run from yourchromium 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.

  2. In CLion, select thecompile_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
  3. 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 sectionExclude 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:

  1. Open the actions menu (ctrl+shift+a)
  2. Typecreate desktop entry and pressenter
  3. Open the actions menu and entercreate 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. Openchromium/.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, selectingMark Directory As and then selectingExcluded.

<component name="CidrRootsConfiguration">    <excludeRoots>      <file path="$PROJECT_DIR$/src/android_webview" />      <file path="$PROJECT_DIR$/src/apps" />      <file path="$PROJECT_DIR$/src/ash" />      <file path="$PROJECT_DIR$/src/build" />      <file path="$PROJECT_DIR$/src/build_overrides" />      <file path="$PROJECT_DIR$/src/buildtools" />      <file path="$PROJECT_DIR$/src/cc" />      <file path="$PROJECT_DIR$/src/chromecast" />      <file path="$PROJECT_DIR$/src/chromeos" />      <file path="$PROJECT_DIR$/src/codelabs" />      <file path="$PROJECT_DIR$/src/content" />      <file path="$PROJECT_DIR$/src/courgette" />      <file path="$PROJECT_DIR$/src/crypto" />      <file path="$PROJECT_DIR$/src/dbus" />      <file path="$PROJECT_DIR$/src/device" />      <file path="$PROJECT_DIR$/src/docs" />      <file path="$PROJECT_DIR$/src/extensions" />      <file path="$PROJECT_DIR$/src/fuchsia_web" />      <file path="$PROJECT_DIR$/src/gin" />      <file path="$PROJECT_DIR$/src/google_apis" />      <file path="$PROJECT_DIR$/src/google_update" />      <file path="$PROJECT_DIR$/src/gpu" />      <file path="$PROJECT_DIR$/src/headless" />      <file path="$PROJECT_DIR$/src/infra" />      <file path="$PROJECT_DIR$/src/ios" />      <file path="$PROJECT_DIR$/src/ipc" />      <file path="$PROJECT_DIR$/src/media" />      <file path="$PROJECT_DIR$/src/mojo" />      <file path="$PROJECT_DIR$/src/native_client" />      <file path="$PROJECT_DIR$/src/native_client_sdk" />      <file path="$PROJECT_DIR$/src/net" />      <file path="$PROJECT_DIR$/src/out" />      <file path="$PROJECT_DIR$/src/pdf" />      <file path="$PROJECT_DIR$/src/ppapi" />      <file path="$PROJECT_DIR$/src/printing" />      <file path="$PROJECT_DIR$/src/remoting" />      <file path="$PROJECT_DIR$/src/rlz" />      <file path="$PROJECT_DIR$/src/sandbox" />      <file path="$PROJECT_DIR$/src/services" />      <file path="$PROJECT_DIR$/src/skia" />      <file path="$PROJECT_DIR$/src/sql" />      <file path="$PROJECT_DIR$/src/storage" />      <file path="$PROJECT_DIR$/src/styleguide" />      <file path="$PROJECT_DIR$/src/testing" />      <file path="$PROJECT_DIR$/src/third_party" />      <file path="$PROJECT_DIR$/src/tools" />      <file path="$PROJECT_DIR$/src/ui" />      <file path="$PROJECT_DIR$/src/url" />      <file path="$PROJECT_DIR$/src/v8" />      <file path="$PROJECT_DIR$/src/venv" />      <file path="$PROJECT_DIR$/src/weblayer" />    </excludeRoots>  </component>

Mark directories asLibrary Files

To speed up CLion, optionally mark directories such assrc/third_party asLibrary Files

  1. Open theProject navigation (alt+1)
  2. Select and right-click the directories >Mark directory as >Library Files
  3. Seehttps://blog.jetbrains.com/clion/2015/12/mark-dir-as/ for more details

[8]ページ先頭

©2009-2025 Movatter.jp