CLion 2018.3 Help

External Tools

In CLion, you can specify third-party standalone applications and run them as External Tools. You can pass contextual information to these tools (like the currently selected file or your project source path), view the output within the IDE, configure the tool's launch as a step of your run/debug configuration, and more.

Tools defined in the External Tools dialog appear as commands in the Tools | External Tools menu and various context menus. Like most other actions, external tools can be assigned keyboard shortcuts for quick access.

Ways to call an external tool:

  • From the list of available tools in Tools | External Tools on the main menu

  • Via a keyboard shortcut assigned to the tool in Settings / Preferences | Keymap

  • As the Before launch step of a run/debug configuration

See the next chapter for an example of how to configure and use an external tool.

Example: ClangFormat as an external tool

ClangFormat is a widely-used code formatter. It supports two ways of providing code style options: you can either define them in a YAML file (named .clang-format or _clang-format) or specify the style options directly as command line parameters.

For code style settings given as a list of command line arguments or in a simple clang-format file, you will most likely be able to replicate the same configuration in CLion's Code Style settings. Otherwise, if your clang-format file can't be easily mapped to CLion's formatter settings, consider configuring ClangFormat as an external tool:

  1. Place your .clang-format file in the project directory.

  2. Navigate to Settings / Preferences | Tools | External Tools and click artwork studio icons common add.

  3. In the dialog that opens, specify the following:
    cl externaltool config
    • Name: clang-format - just for example, let's name the configuration similarly to the executable.

    • Program: clang-format - use the name of your executable.

    • Arguments: -i $FileName$ - settings from the clang-format file will be applied inplace (-i), to the file currently opened in the editor (the $FileName$ macro).

    • Working directory: $FileDir$ - this macro represents the current file directory.

  4. Click Ok to save the configuration.

  5. Now you can go to Tools | External tools | clang-format and run the tool with the above settings. The changes of code formatting will be introduced right away.

Assign a shortcut to the clang-format external tool:

  1. Go to Settings / Preferences | Keymap and find clang-format in the list of External Tools.

  2. Click artwork studio icons avd edit and choose Add Keyboard Shortcut.

  3. Press the keys to be used as shortcuts and click Ok.

Now the assigned shortcut is available, and you can see it next to the tool's name in the Tools | External Tools menu:

cl externaltools menu

Automatically run clang-format before launch:

  1. In the Run | Edit configurations dialog, choose the desired run/debug configuration.

  2. Click artwork studio icons common add in the Before Launch section, and select Run External Tool:

    cl externaltools beforelaunch

  3. Choose clang-format from the list of the available external tools.

As a result, the clang-format external tool will be called every time you choose to run or debug the selected configuration.

Last modified: 7 December 2018

See Also

Reference: