themusicinnoise-site/blog/posts/0143-cmake-externalproject-module.html

54 lines
2.4 KiB
HTML
Raw Permalink Normal View History

<p>Recently I've started working on a C++ project that uses the CMake build
system.<sup><a href="#r1" >[1]</a></sup> The first thing I was in charge of
doing was fixing the build, as one of the dependencies is the SeetaFace2
project.<sup><a href="#r2" >[2]</a></sup> Originally you had to have the
SeetaFace2 project in a directory adjacent to the SeetaRest project directory,
and you would manually compile SeetaFace2. This, for obvious reasons, is not a
good build setup. So my task was to integrate it directly into the build using
CMake's <code>ExternalProject</code>
module.<sup><a href="#r3" >[3]</a></sup></p>
<p>Generally, for those of us used to the way things work on Linux, generally
speaking you want to work solely with the dependencies you can install from your
distribution's repositories. The problem with this is, save for certain very
popular libraries/tools, there are some inconsistencies as to what packages may
be available in different distributions, what versions they have available, or
even if it's compiled with the flags you need for your project. It's still ideal
to link to something from the repositories, but it's not always possible.</p>
<p>This is where <code>ExternalProject</code> comes in. This allows for
dependencies to be downloaded and compiled with specific options that best suite
the project. It's also done in a rather simple manner. Just by looking at the
<code>SeetaFace2.cmake</code> module for the project, it's fairly easy for
anyone with a basic knowledge of CMake syntax to see how this project is built
and setup.<sup><a href="#r4" >[4]</a></sup> And since you're having to build an
entire other project, it's also helpful that you have the option of choosing
which targets to build (instead of the entire project).</p>
<ol class="refs" >
<li id="r1" >
<a href="https://gitgud.io/bug-zapper-software/seeta_rest"
target="_blank" >
"Seeta Rest" on GitGud
</a>
</li>
<li id="r2" >
<a href="https://github.com/seetafaceengine/SeetaFace2/"
target="_blank" >
"SeetaFace2" on GitHub
</a>
</li>
<li id="r3" >
<a href="https://cmake.org/cmake/help/latest/module/ExternalProject.html"
target="_blank" >
ExternalProject CMake documentation
</a>
</li>
<li id="r4" >
<a href="https://gitgud.io/bug-zapper-software/seeta_rest/-/blob/master/CMake/SeetaFace2.cmake"
target="_blank" >
<code>SeetaFace2.cmake</code> file from Seeta Rest on GitGud.
</a>
</li>
</ol>