CLion 2021.3 Help

Makefile projects

You can load Makefile projects in CLion and benefit from all the smart features the IDE provides.

Note that Makefiles support in CLion is in its early stages. Use the tickets linked to CPP-494 to leave your feedback and vote for the desired features. The list of the open-source projects that Makefile support has been tested on is available here.

Open a Makefile project

  1. Select File | Open from the main menu.

  2. Point CLion to a folder that contains the top-level Makefile or to that file directly:

    Opening a Makefile project

  3. In the dialog that opens, click Open as Project.

    Opening a Makefile as a project
  4. You will be prompted to clean the project:

    Load project dialog

    Cleaning is required for the project load as the Make build is incremental and only the updated files are compiled. When run on an uncleaned project, reload will miss all the unchanged files and might perform incorrectly.

    Clear the Clean project checkbox if you prefer to load without cleaning. You will be able to clean and reload your project later (for example, after performing the required bootstrapping).

  5. At this point, CLion starts loading the project, displaying the progress and status in the Build tool window:

    Project loading status in the Build tool window

    Warning messages may appear during the process, but if loading finishes with a green checkmark Successful load indicator next to the project name, this indicates a successful load. Take a look at the Troubleshooting section if your project fails to load correctly.

Load a Makefile for an opened project

You can also open a project as a folder and load the Makefile later. This is helpful, for example, if your project requires some preconfigure step or launching a script to prepare the final Makefile, so you don't have it when opening your project in CLion.

To load the Makefile when ready, open it in the editor and click the Load Makefile project link in the notification:

Load Makefile project notification

Alternatively, use the Load Makefile Project action from the file's context menu in the project tree.

    Configure auto-reload

    By default, CLion doesn't update or reload your project automatically except for the cases of external events like VCS update. You can change this behavior in the Build Tools settings.

    1. Go to Settings / Preferences | Build, Execution, Deployment | Build Tools.

    2. Select one of the auto-reload options:

      Auto-reload settings
      • Any changes - project reload will be triggered on any change in Makefiles.

      • External changes (default) - your project will be reloaded only upon external events like VCS update. In case of other changes (for example, when you add a new file), you will get a notification on the Makefile:

        Makefile reload notification

    Reload manually

    Apart from the automatic options, you can also reload your project manually:

    • Call Reload Makefile Project or Clean and Reload Makefile Project from Tools | Makefile on the main menu.

      Tools | Makefiles menu
    • Alternatively, click the Reload icon or the Clean and reload icon in the Build tool window:

      Project reload icon in the Build tool window

    Adjust the project settings

    Use the Settings / Preferences | Build, Execution, Deployment | Makefile dialog to control your project settings.

    Makefile settings
    • Toolchain

      Here you can select the toolchain to be used for loading your Makefile project.

      Note that NMake is not supported currently, so you can't use the Visual Studio toolchain directly. In order to work with it, you need to build the project separately using GNU Make.

      If the toolchain you selected includes non-default compilers (configured explicitly in the C Compiler and C++ Compiler fields), they will be passed to make as well.

    • Build options

      In this field, you can provide additional make options for the project build. These options don't affect the project reload.

    • Commands

      In this field, you can adjust preconfiguration parameters. See Pre-configuration (GNU Autoconf).

    • Arguments

      These arguments are used by CLion when calling the make command on the step of extracting project information, cleaning the project, or searching for build targets.

    • Build target and Clean target

      These targets are used along the make command to extract the project information. If you leave the Build target field empty, CLion will take the first target specified in the project’s top Makefile.

      Also, the targets specified here are used when you call Build Project or Rebuild Project from the Build actions menu.

    You can quickly access the Makefile settings dialog from the Build tool window. Select Makefile Settings from the context menu or click the Settings icon:

    Accessing Makefile settings from the Build tool window

    Advanced settings

    More settings for Makefile projects are available in Settings / Preferences | Advanced Settings:

    Advanced settings for Makefile projects

    Run targets

    Use the gutter menu to quickly call make for a particular target:

    Gutter menu for running targets

    Upon this action, CLion creates a temporary configuration of the Makefile Target type. You can customize it or create new configurations out of the same template in the Edit Configurations dialog (see below).

    Create a Makefile Target configuration

    • Go to Run | Edit Configurations, click Icons general add, and select Makefile Target from the list of templates:

      Adding a Makefile Target configuration
    • In the settings, you can set up several targets to run, provide additional arguments, and tune other parameters if required. See the reference page for details.

      A Makefile Target configuration

    You can also run targets from the make tool window (View | Tool Windows | make). Double-click a target or select it and then click Icons actions execute:

    Running targets from the make tool window

    Makefile Application configurations

    CLion automatically creates a Makefile Application configuration for each target from the top-level Makefile. Note that targets from sub-directory Makefiles are disregarded.

    When creating configurations, CLion filters out the following targets:

    • The clean target.

    • Targets that correspond to object (.o) files.

    • Targets that end with unknown file extensions (for example, .d).

    You can customize the automatically created configurations or create new ones in the Edit Configurations dialog (see below).

    Create a Makefile Application configuration

    • To add a configuration, go to Run | Edit Configurations, click Icons general add, and select Makefile Application from the list of templates:

      Adding a Makefile Application configuration
    • In the Target field, you can choose one of the detected targets:

      Targets selection for a Makefile Application configuration

    • Another option is to set a custom build target with type Make. Click Icons actions inlay gear next to the Target field, add (Icons general add) a new Make target, and fill in the parameters:

      Custom targets for Makefile Application configurations

    • In the Executable field, provide the full path to the binary.

      To run/debug remotely, provide the path to the binary on your remote machine. The remote path needs to be set manually (if you click Platform impl icons process dots 1, CLion will suggest local paths).

    • Other settings of the Makefile Application template are described on the reference page.

    Troubleshooting

    Make sure that both Makefile and Makefile Language plugins are enabled. Check the Installed tab in Settings / Preferences | Plugins.

    Makefile support plugins

    If your project fails to load correctly, try the following tips:

    • Check Makefile settings:

      1. Make sure to select a proper toolchain. Your project should build successfully in the selected environment.

      2. Arguments and Build target may need adjustments for the case of your project.

    • Call Tools | Makefile | Clean and Reload Makefile Project from the main menu or click the Clean and reload icon in the Build tool window.

    • If your project's Makefiles were generated by Premake, try removing the --no-print-directory arguments from the root Makefile.

    • In case none of the above helps, try cleaning the project cache from /makefiles in the system directory (for example, ~/Library/Caches/JetBrains/CLion2020.2/makefiles/postgrtipes.dc29ef09), then reload the project.

    Current limitations and future plans

    Last modified: 30 November 2021