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.