-
“KatrinBistreck” authored“KatrinBistreck” authored
title: Building C++ Modules
summary: How to build C++ modules of UNICADO.
authors:
- Sebastian Oberschwendtner
date: 2023-09-12
Most modules are written in C++. In the following, it is explained how:
- the current important dependencies have to be installed
- how to configure and build with CMake
For detailed information on CMake, please read the general information.
Install required dependencies {#dependencies}
We do not provide an automatic way to get the required dependencies, since we do not want to force any specific package manager on you. UNICADO has currently these external dependencies for building:
- Eigen3 :octicons-link-external-16:{:target="_blank"}
- Boost :octicons-link-external-16:{:target="_blank"}
- CGAL :octicons-link-external-16:{:target="_blank"}
However, if you followed the instructions in Prerequisites you can install them as follows:
=== "Windows"
``` { .cmd .copy }
C:\dev\vcpkg\vcpkg.exe install eigen3 boost cgal
```
!!! note
This may take some time and you can install one package after the other.
=== "MinGW"
``` { .sh .copy }
pacman -S mingw-w64-ucrt-x86_64-eigen3 mingw-w64-ucrt-x86_64-boost mingw-w64-ucrt-x86_64-cgal
```
=== "Unix"
⇒ Use your the package manager of your distribution to install the packages. :wink:
Configure {#configure}
Before building we need to configure and figure out on which platform you are running your current build.
Naming pattern
We use the following naming pattern to identify the presets:
architecture-platform-configuration
Where architecture can be one of the following:
-
x64
for 64-bit architectures (Currently the only one we support!)
And platform can be one of the following:
-
windows
for Windows -
linux
for Linux -
mingw
for MinGW on Windows ( Deprecated)
The configuration can be one of the following:
-
release
for a release builds -
debug
for a debug builds
Other configurations are possible, but not supported by our presets. You have to specify custom presets by CMakeUserPresets.
!!! note In the following we always assume the Release configuration for building. The Debug configuration works analogously.
Configure in Terminal
The programmers way to configure CMake:
- Open a terminal inside the root directory of the rAircraftDesign repository.
- Configure CMake by explicitly telling it which preset to use:
=== "Windows"
``` { .sh .copy }
cmake -B build -S . --preset x64-windows-release
```
=== "MinGW"
``` { .sh .copy }
cmake -B build -S . --preset x64-mingw-release
```
=== "Linux"
``` { .sh .copy }
cmake -B build -S . --preset x64-linux-release
```
!!! tip
The -B
and -S
are not needed anymore when using the preset. You can however still use them to specify the build directory and the source directory.
:fontawesome-solid-arrow-right: In the following we will omit them.
During this configuration, CMake generates a cache file which remembers some parameters which are re-used when you configure CMake again. This cache files is not automatically deleted/updated, which can lead to some unexpected behavior. When this happens, you can tell CMake explicitly to refresh this cache by:
=== "Windows"
``` { .sh .copy }
cmake --preset x64-windows-release --fresh
```
=== "MinGW"
``` { .sh .copy }
cmake --preset x64-mingw-release --fresh
```
=== "Linux"
``` { .sh .copy }
cmake --preset x64-linux-release --fresh
```
Read more about the configuration and additional possible flags you can set here.
Build {#build}
Build specific target
So to build a specific target you call CMake with the following command, where <target>
is the name of the module you want to compile:
=== "Windows"
```sh
cmake --build --preset x64-windows-release --target <target>
```
=== "MinGW"
```sh
cmake --build --preset x64-mingw-release --target <target>
```
!!! tip
Remember: The build preset should match the one specified when configuring **CMake** :point_up:.
=== "Unix"
```sh
cmake --build --preset x64-linux-release --target <target>
```
!!! tip
Remember: The build preset should match the one specified when configuring **CMake** :point_up:.
Build all target
When you want to compile all the modules ^^at once^^, you can just omit the target option and call CMake with:
=== "Windows"
```sh
cmake --build --preset x64-windows-release
```
=== "MinGW"
```sh
cmake --build --preset x64-mingw-release
```
=== "Unix"
```sh
cmake --build --preset x64-linux-release
```
!!! warning If you do that, you also have to install the python packages first (see Python build).
Other notes
Clean before re-compiling
=== "Windows"
```sh
cmake --build --preset x64-windows-release --target <target> --clean-first
```
=== "MinGW"
```sh
cmake --build --preset x64-mingw-release --target <target> --clean-first
```
=== "Unix"
```sh
cmake --build --preset x64-linux-release --target <target> --clean-first
```
That's all folks. This should compile UNICADO just fine.
Improve Compilation Speed
You can increase the build speed by enabling parallel jobs of the build tool. This is as easy as this:
cmake --build --preset <preset> --target <target> -j <n_jobs>
This builds the project using n_jobs
processes. You can give any number here, but it should correspond to the number of processors available on your machine.