Skip to main content
Version: 0.0.0

Multiple targets

For a lot of projects you will have more than one target. Maybe a main application, some libraries and some test executables. Let's have a look at different scenarios of multiple targets in a single project.

Multiple self-developed targets​

In this first example we have a library and an executable both in the same project. We want to link the library and the exectuable. This is our folder structure.

my_project
β”œβ”€β”€ shared_headers
| └── header1.hpp
β”œβ”€β”€ my_executable
| β”œβ”€β”€ include
| | β”œβ”€β”€ header1.hpp
| | └── header2.hpp
| └── src
| β”œβ”€β”€ src1.cpp
| └── src2.hpp
β”œβ”€β”€ my_lib
| β”œβ”€β”€ include
| | └── header3.hpp
| └── src
| └── src3.hpp
└── clang-build.toml

The following toml file will create and link the targets:

[additional_includes]
directory = "shared_headers"
target_type = "header only"

[my_library]
directory = "my_lib"
target_type = "shared library"
dependencies = ["shared_headers"]

[app]
directory = "my_executable"
dependencies = ["my_lib", "shared_headers"]

As you can see we defined the shared headers as another target. Because there is no "additional_includes" in clang-build currently, this has the advantage, that we do not have to list the default folders as include folders, too.

Note, the public header files of dependencies are automatically available for include, no extra configuration required!

External GitHub target​

Maybe you have a dependency on an external library on GitHub like Eigen. In this case we can use clang-build's feature to automatically download the library for you. If this is your folder structure:

my_project
β”œβ”€β”€ include
| β”œβ”€β”€ cool_features.hpp
| └── math_lib.hpp
β”œβ”€β”€ src
| β”œβ”€β”€ cool_features.cpp
| └── my_app.cpp
└── clang-build.toml

and this is your toml file:

[myexe]
dependencies = ["Eigen"]

[Eigen]
target_type = "header only"
url = "https://gitlab.com/libeigen/eigen.git"
[Eigen.flags]
compile = ["-Wno-deprecated-declarations"]
compileRelease = ["-DEIGEN_NO_DEBUG"]

Then you already have your project support Eigen. As soon as you run clang-build, it will download (or use the cached version if you rebuild) Eigen and make it available for including its headers.