C++ is “no batteries included” language, so build-systems, libraries and frameworks do not receive much attention while being critical to real-life projects.

Let’s say you just finished writing a brand new C++ library:

/*----------------- /include/fractal/fractal.h -----------------------*/
#ifndef FRACTAL_H
#define FRACTAL_H

#ifdef __cplusplus
extern "C" {
#endif

/* 
* Return the escape time in iterations of point (x,y) from the mandlebrot set
* \param[in] x                  X coordinate of the starting point
* \param[in] y                  Y coordinate of the starting point
* \param[in] max_iterations     Maximum number of iterations to perform
* \return                       Number of iterations until the point escapes
                                from the local neighborhood of zero
*/
int fractal_mandelbrot(double x, double y, int max_iterations);

#ifdef __cplusplus
}
#endif

#endif /* FRACTAL_H */
/*--------------------- /src/fractal.cpp -----------------------------*/
#include <fractal/fractal.h>

#include <complex>

int fractal_mandelbrot(double x, double y, int max_iterations)
{
    using namespace std;

    complex<double> point(x, y);
    complex<double> z(0, 0);

    int iteration = 0;
    while (abs (z) < 2 && iteration <= max_iterations) 
    {
        z = z * z + point;
        iteration++;
    }
    return iteration;
}

Now its time for different type of questions:

  • Where to manage the code?
  • How to make sure it compiles on different platforms and tool-chains?
  • How to test that it works?
  • How people are supposed to use the library?
  • Where to host the documentation and how to keep it up-to-date?
  • How to package the library for different platforms and usages?
  • How to make the library accessible from other languages?

In this series we will look at different free technologies you could use to effectively address some of these questions.

Full source code is available here

Let’s start with building the code for various platforms using CMake.