Building C++ Software


In 2002-2003 I published a series of artices in ACCU Overload describing the how to go about writing
extensible software. In C++ (and most other languages) there are two sides to this problem. The first is the logical approach: how does this fit in with the software archiecture? And secondly the physical approach: how to you integrate these items into you build system? In order to do this you need to structure your source code tree and create a suitable build system. Of course even if you aren't designing extensiblesoftware it helps to have a good build system.

This pages pulls together articles on: organising your source tree, make systems, incremental build numbers, etc. I've brought all the articles together on this one page.
  • Organising Source code: This essay discusses directory tree layouts for software development in the context of extendable software. (Overload 52 - December 2002)
  • Layering C++ Source Code: A much underestimated subject in developing software systems, this is a piece on what layering is and how to go about it. Oranizing software is a lot easier if you have your layering sorted out, and a good physical build system can help support layering
  • Layering in Microsft Visual C++
  • Build systems: Following on from Organising source code this essay looks at how we actually build our software, how to get makefiles to work for you and how to generate things like build numbers. (Overload 53 - February 2003)
  • Generating build numbers: This is supplemented by a sidebox describing how to generate incremental build numbers using Python. The Python scripts to do this are here. (Overload 53 - February 2003)

In addition there are two examples:

Although I talk about 'Building software' it seems that the fashionable term is 'Continuous integration.' On the one hand we can just regard this as 'build often, build well', on the other hand it does go beyond building the software.

Code for generating build numbers

Python files for generating build numbers, and a C++ header - in GenBuildNumber.tar file.

There are two files here which can be used to produce incremental build numbers for your application. The two files need to be used together as part of a make system.

As they stand these files are designed for systems written in C++ so you will need to do some work if you work in Java, C# or any other language. The good news is they are simple so should be easily adapted to another language. The C++ generated should work with any modern compile.

The first file, GenVersion.py, is the one that actually does the work. The second file, version.py, is used to keep track of the current version number. You will want to check them both into your source code control system and integrate them with your build system.

You will also need to download Version.hpp

Here's how they work....
  • In your makefile you need to execute GenVersion.py. This takes one parameter exactly, if the parameter is "NOBUMP" the build number will not be incremented - useful for developers working in their sandbox. If the parameter is "BUMP" then build number will be incremented - useful for batch builds.
  • When it runs GenVersion.py includes version.py, this file is just a short Python script which sets several variables, if the version number if not to be bumped that is the end of the story. However if the version number is to be bumped then GenVersion.py will rewrite version.py. If this happens you will want to ensure your source code control system is updated with the new version.py or the change will be lost.
  • There is nothing more than needs to be said about version.py.
  • Next GenVersion.py will write another new file, Version.cpp - this is the implementation file to match Version.hpp.
  • You will need to ensure your make system builds Version.cpp and the object code is included in your project.
  • You can now call the functions defined in Version.hpp to retrieve the build number, copyright statements and such.
  • Version.hpp is not generated because it does not change and - if your following my advice on directory structure - needs to placed in a different directory.