CLion 2019.2 Help

External Tools

You can define standalone third-party applications as external tools and run them from CLion. For example, you might want to run a code generator or analyzer, preprocessor or postprocessor, a database utility, and so on.

You can pass contextual information from your project to the external tool as command-line arguments (for example, the currently selected or open file, the project source path, and so on), view the output produced by the tool, configure to launch the tool before a run/debug configuration, and more.

There are different types of external tools that you can use with CLion:

  • Local external tools are applications that run locally on your machine.

  • Remote SSH external tools are executed on a remote server over SSH.

Add a local external tool

  1. In the Settings/Preferences dialog (Ctrl+Alt+S), select Tools | External Tools.

  2. Click the Add button and specify the following settings:

    • Name: The name of the tool that will be displayed in the CLion interface (the Tools menu and context menus).

    • Group: The name of the group to which the tool belongs. You can select an existing group or type the name of a new group.

    • Description: A meaningful description of the tool.

    • Program: The name of the executable file. Specify it with an absolute path if the containing directory is not in your PATH environment variable.

    • Arguments: The arguments passed to the executable file, as you would specify them on the command line.

    • Working directory: The path to the current working directory from which the tool is executed.

  3. Click OK to add the tool and then apply the changes.

Run a local external tool

To run the added tool, do one of the following:

  • From the main menu, select Tools| External Tools and choose from the list of the available tools.

  • In the Settings/Preferences dialog (Ctrl+Alt+S), select Keymap, find the tool under the External Tools node, and assign a shortcut for it. Use the shortcut to run the tool.

  • Set the tool as a Before launch step of a run/debug configuration: go to the Run | Edit Configurations, select the configuration, click the Add button in the Before launch area, and select Run External Tool.

Example: Uncrustify as an external tool

Uncrustify is a popular code formatter that you can configure as an external tool to use in addition or as an alternative to the CLion's built-in formatter or the integrated ClangFormat.

  1. Optionally, place the configuration file in the project directory (otherwise, you will need to provide the full path).

  2. Navigate to Settings / Preferences | Tools | External Tools and click the Add button.

  3. In the dialog that opens, specify the following:

    add external tool

    • Name: uncrustify - just for example, let's name the configuration similarly to the executable.

    • Program: uncrustify - provide the binary name (and include the full path if necessary).

    • Arguments: -c mystyle.cfg -f $FilePath$ -o $FilePath$ - style settings stored in mypath.cfg will be applied to the file currently opened in the editor (the $FileName$ macro), and the result will be written in-place (the -o flag redirects the Uncrustify output).

    • 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 | uncrustify and run the tool with the above settings. The changes of code formatting will be introduced right away.

Assign a shortcut to the Uncrustify external tool:

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

  2. Click the Edit button 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:

external tools menu

Automatically run Uncrustify before launch:

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

  2. Click the Add button in the Before Launch section, and select Run External Tool:

    Before launch

  3. Choose uncrustify from the list of the available external tools.

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

Remote external tools

Add a remote SSH external tool

Remote SSH external tools are configured similarly to local external tools, but also define the remote server on which they are executed and require credentials for connecting to it via SSH.

This example demonstrates how you can add date as a remote SSH external tool that is executed on a remote server and returns the current date and time on it.

  1. In the Settings/Preferences dialog (Ctrl+Alt+S), select Tools | Remote SSH External Tools.

  2. Click the Add button and specify the following settings:

    The Create Tool dialog

    This dialog provides the same set of settings as when you add a local external tool, but selecting the remote server is also suggested. This can be one of your configured deployment servers or WSL. By default, CLion will ask you for the host, port, and relevant SSH credentials every time you run the tool on the deployment server.

  3. Click OK to add the tool and then apply the changes.

Run a remote external tool

To run the added date tool, do one of the following:

  • From the main menu, select Tools| Remote Tools | Date and time.

  • In the Settings/Preferences dialog (Ctrl+Alt+S), select Keymap, find the Date and time action, and assign a shortcut for it. Use the shortcut to run the tool.

  • Set the tool as a Before launch step of a run/debug configuration: go to the Run | Edit Configurations, select the configuration, click the Add button in the Before launch area, and select Run Remote External Tool.

Web browsers

You can use a web browser to open any file from your project but generally it is used to preview the output of an HTML file or run and debug web applications.

Open a file in a web browser

To open a file that is intended to be rendered by a web browser (HTML, XML, JSP, and so on), do one of the following:

  • Press Alt+F2.

  • Right-click a file and select Open in Browser.

  • From the main menu, select View | Open in Browser.

  • Use the browser popup in the top right part of the editor window. Click the browser button to open the web server file URL, or Shift+Click it to open the local file URL.

The Open in Browser action is not available for other file types. However, you can still execute it using Find Action Ctrl+Shift+A.

By default, CLion supports some of the most popular browsers, which are configured automatically, if available:

  • Chrome Chrome browser icon

  • Firefox Firefox browser icon

  • Safari Safari browser icon

  • Opera Opera browser icon

  • Internet Explorer Internet Explorer browser icon

  • Edge Edge browser icon

View and configure the list of browsers

In the Settings/Preferences dialog (Ctrl+Alt+S), select Tools | Web Browsers.

The Web Browsers page in Preferences

If a browser was installed using a standard procedure, the alias in the Path field should point to the right location. If it does not, specify the path to the corresponding executable file.

The order of browsers in the list corresponds to their order in the popup, context menu, and the View menu. If you disable a browser, it will not appear in the popup, context menu, and the View menu.

Add a custom browser

  1. In the Settings/Preferences dialog (Ctrl+Alt+S), select Tools | Web Browsers.

  2. Click the Add button and specify the browser name, family, and location of the executable file or macOS application.

Select a default browser

The Open in Browser item in the View menu and in the context menu of a file lists all available browsers and the default browser, which is also used to render external resources.

  1. In the Settings/Preferences dialog (Ctrl+Alt+S), select Tools | Web Browsers.

  2. From the Default Browser list, choose one of the following:

    • System default: use the default browser for your operating system.

    • First listed: use the first browser in the list.

    • Custom path: use a browser that is not in the list. Specify the location of the executable file.

Use custom profile and settings

You can configure custom profiles for Firefox and Chrome family browsers.

  1. In the Settings/Preferences dialog (Ctrl+Alt+S), select Tools | Web Browsers.

  2. Select the browser in the list and click the Edit button.

    • For Firefox, specify the path to the profiles.ini file and choose the profile to use. For more information, see Firefox browser profile.

    • For Chrome, select Use custom user data directory and specify the location of the user data directory.

      You can also specify additional command-line options to use when running Chrome from CLion. For more information, open chrome://flags in the Chrome address bar.

Last modified: 16 September 2019

See Also

Reference: