Custom build targets and applications
Custom build targets are independent of any particular build system or project model: CLion uses external tools of your choice for building the sources and cleaning build artifacts.
Custom targets are especially useful for compilation database projects. Although compile_commands.json itself lacks the information required for building and therefore running applications, custom targets and custom run/debug configurations help bypass this limitation.
In the following example, we will add a target to a compilation database project, get build results, and then create a custom configuration to run the executable right from CLion.
Create a custom build target
Let's open a compilation database project. Click compile_commands.json, and choose Open as Project., point CLion to
Go to Custom Build Application editor.and click to add a new target. This dialog is also accessible from the
Specify the following settings:
Toolchain selected here will provide the environment and the debugger for the custom run/debug configuration that we will create later.
Note that compilation database projects with custom build targets use two separate toolchains:
for resolving your project files.
The target's toolchain, which defines the environment and the debugger for custom run/debug configurations.
Build and Clean
Set up the tools for building and cleaning your project: select from the list of the available tools or click and use the and buttons to edit or add new tools.
In our example, the Build tool (named build_with_make) calls make, and the Clean tool (clean_with_make) calls
After saving the target, we can start using the Build Project and Rebuild Project actions. Note that in case of several custom targets, these actions are associated with the first target from the list.
If we select Build Project, CLion runs the build_with_make tool that calls
makefor the project sources:
Create a custom run/debug configuration
Now that we have a build target, we can create a configuration to run and debug the executable.
Go to Custom Build Application from the list of the configuration templates., click and choose
Select the newly created custom target in the Target field. To add or edit the targets without leaving the configuration editor, click Configure Custom Build Targets.
Specify the application binary in the Executable field. Note that you can use remote executables here as well.
For our example, we also add a program argument func.cpp:
After saving the configuration, we can see new build actions available in the Build menu:
Let's run our example and view the program results: