C++ – Best practice of c/C++ dependency management on build servers

buildscdependency-management

I develop largely in java which has maven or ant/ivy. Is there a recommended way to manage build dependencies for c++ projects? I'm setting up the build on our build server right now but the thing that comes to mind is that if the dependency libraries change how do I track that so old builds are not affected but new ones can use newer versions of a library?

One simple thought is that I move all the third party libraries into my repository and then reference them with:

#include "sqlite3.h"
#include "mosquitto.h"

Instead of

#include <sqlite3.h>
#include <mosquitto.h>

Can someone recommend how to best do this in production?

Best Answer

Moving third party build dependencies into your repository is perfectly fine, and even has some advantages (eg. no version mismatches, tracked upgrades). But doing so should not touch your code.

C/C++ use an include path to determine where to find libraries that are included like so

#include <...>

Depending on your toolchain and build system, you'll have to follow different steps to configure this. Regardless, the best thing would be to create a "third_party" folder with subfolders containing each dependency. Then add each of those folders to your include path such that your existing include directives work.

In CMake, you should use the target_include_directories to accomplish this. In a plain Makefile with GCC or clang, you would add the -I flag for each folder.

Related Topic