manukh | 080b47e | 2019-12-19 22:06:19 | [diff] [blame] | 1 | # CLion Dev |
| 2 | |
| 3 | CLion is an IDE |
| 4 | |
| 5 | Prerequisite: |
| 6 | [Checking out and building the chromium code base](README.md#Checking-Out-and-Building) |
| 7 | |
| 8 | [TOC] |
| 9 | |
| 10 | ## Setting up CLion |
| 11 | 1. Install CLion |
| 12 | - Googlers only: See |
| 13 | [go/intellij-getting-started](https://goto.google.com/intellij-getting-started) |
| 14 | for installation and license authentication instructions |
| 15 | |
| 16 | 1. Run CLion |
| 17 | 1. Increase CLion's memory allocation |
| 18 | |
| 19 | This step will help performance with large projects |
| 20 | 1. Option 1 |
| 21 | 1. At the startup dialogue, in the bottom right corner, click |
| 22 | `Configure` |
| 23 | 1. Setup `Edit Custom VM Options`: |
| 24 | ``` |
| 25 | -Xss2m |
| 26 | -Xms1g |
manuk hovanesian | b2953e4 | 2021-03-20 00:14:04 | [diff] [blame] | 27 | -Xmx15g |
manukh | 080b47e | 2019-12-19 22:06:19 | [diff] [blame] | 28 | ... |
| 29 | ``` |
| 30 | 1. (Optional) Setup `Edit Custom Properties`: |
| 31 | ``` |
| 32 | idea.max.intellisense.filesize=12500 |
| 33 | ``` |
| 34 | 1. Option 2; 2017 and prior versions may not include the options to setup |
| 35 | your `VM Options` and `Properties` in the `configure` menu. Instead: |
| 36 | 1. `Create New Project` |
| 37 | 1. `Help` > `Edit Custom VM Options` |
| 38 | 1. (Optional) `Help` > `Edit Custom Properties` |
| 39 | |
| 40 | ## Chromium in CLion |
| 41 | 1. Import project |
| 42 | - At the startup dialog, select `Import Project` and select your `chromium` |
| 43 | directory; this should be the parent directory to `src`. Selecting `src` |
| 44 | instead would result in some CLion IDE files appearing in your repository. |
| 45 | 1. (Optional) Modify the `CMakeLists.txt` file |
manuk hovanesian | b2953e4 | 2021-03-20 00:14:04 | [diff] [blame] | 46 | 1. Open the `CMakeLists.txt` file. |
manukh | 080b47e | 2019-12-19 22:06:19 | [diff] [blame] | 47 | 1. Replace the `include_directories` with the following. This will help |
| 48 | with navigating between files. |
| 49 | ``` |
| 50 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src) |
manuk hovanesian | b2953e4 | 2021-03-20 00:14:04 | [diff] [blame] | 51 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/out/Default/gen) |
manuk hovanesian | b327955 | 2021-04-29 16:52:25 | [diff] [blame] | 52 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/third_party/protobuf/src) |
manuk hovanesian | b2953e4 | 2021-03-20 00:14:04 | [diff] [blame] | 53 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/third_party/googletest/src/googletest/include) |
manukh | 38a8b74 | 2022-08-03 22:25:52 | [diff] [blame^] | 54 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/third_party/googletest/src/googlemock/include) |
| 55 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/third_party/abseil-cpp) |
manukh | 080b47e | 2019-12-19 22:06:19 | [diff] [blame] | 56 | ``` |
manuk hovanesian | b2953e4 | 2021-03-20 00:14:04 | [diff] [blame] | 57 | 1. (Optional) Replace the `add_executable` files to include a single file; |
| 58 | the file used is irrelevant. Doing this might improve CLion performance. |
| 59 | Leaving at least 1 file is required in order for CLion to provide code |
| 60 | completion, navigation, etc. The file should now look like: |
manukh | 080b47e | 2019-12-19 22:06:19 | [diff] [blame] | 61 | ``` |
| 62 | cmake_minimum_required(VERSION 3.10) |
| 63 | project(chromium) |
| 64 | |
| 65 | set(CMAKE_CXX_STANDARD 14) |
| 66 | |
| 67 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src) |
manuk hovanesian | b2953e4 | 2021-03-20 00:14:04 | [diff] [blame] | 68 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/out/Default/gen) |
manukh | 38a8b74 | 2022-08-03 22:25:52 | [diff] [blame^] | 69 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/third_party/protobuf/src) |
manuk hovanesian | b2953e4 | 2021-03-20 00:14:04 | [diff] [blame] | 70 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/third_party/googletest/src/googletest/include) |
manukh | 38a8b74 | 2022-08-03 22:25:52 | [diff] [blame^] | 71 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/third_party/googletest/src/googlemock/include) |
| 72 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/third_party/abseil-cpp) |
| 73 | |
manukh | 080b47e | 2019-12-19 22:06:19 | [diff] [blame] | 74 | add_executable(chromium src/components/omnibox/browser/document_provider.cc) |
| 75 | ``` |
| 76 | |
| 77 | ## Building, Running, and Debugging within CLion |
| 78 | 1. Edit the `custom build targets` settings |
| 79 | 1. `ctrl+shift+a` > `custom build targets` |
| 80 | 1. Click the `+` button to create a new target. |
| 81 | 1. Click the `...` button next to the `Build` field |
| 82 | 1. Click the `+` button in the new panel |
| 83 | 1. Configure the fields: |
| 84 | ``` |
| 85 | Program: <absolute path to depot_tools/ninja> |
| 86 | Arguments: -C src/out/Default -j 1000 chrome |
| 87 | ``` |
| 88 | 1. (Optional) Repeat for Debug or other build configurations. |
| 89 | 1. Create a run configuration |
| 90 | 1. `Run` > `Edit Configurations` |
| 91 | 1. Click `+` in the top left and select `Custom Build Application` |
| 92 | 1. Set the `Target` field to one of the targets configured in step 1 |
| 93 | 1. Click 'Select other` option for the `Executable` field and select the |
| 94 | chrome build e.g. `out/Default/chrome` |
| 95 | 1. (Optional) Repeat for Debug or other build configurations. The built |
| 96 | targets and executables should match; i.e. don't build `out/Debug `but |
| 97 | execute `out/Default/chrome`. |
| 98 | 1. `Run` > `Run` (`shift+f10`) or `Run` > `Debug` (`shift+f9`) (screenshot) |
| 99 |  |
| 100 | |
| 101 | ## Optional Steps |
| 102 | |
| 103 | ### Create terminal cli or desktop entry |
| 104 | To make it easier to startup CLion or open individual files: |
| 105 | 1. Open the actions menu (`ctrl+shift+a`) |
| 106 | 1. Type `create desktop entry` and press `enter` |
| 107 | 1. Open the actions menu and enter `create command-line launcher` |
| 108 | |
| 109 | ### Mark directories as `Library Files` |
| 110 | To speed up CLion, optionally mark directories such as `src/third_party` as |
| 111 | `Library Files` |
| 112 | 1. Open the `Project` navigation (`alt+1`) |
| 113 | 1. Select and right click the directories > `Mark directory as` > |
| 114 | `Library Files` |
| 115 | 1. See `https://blog.jetbrains.com/clion/2015/12/mark-dir-as/` for more details |