An example of setting the canonical "Money" project from CPPUNIT, using CMake
CMake C++ Shell
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


CPPUNIT / Money / CMake example


Sometimes I have to use C++.
I like unit tests.
I don't like Makefiles.

CMake makes it almost *feasible* to write "something that will compile to make files".

CMake cannot find if CPPUNIT is installed by default.

This project is my lame attempt to fix all this.

I took the example from the CPPUNIT cookbook (

I loosely based the CMake stuffon the "GNU_Style" CMake example (

The FindCPPUNIT stuff was found in the cmake groups, in a post by Anton Deguet, and adapted (


You should do "out-of-source" build (look in the CMake FAQ : There is an "" script to set up an out-of-source build.


 cd code # DON'T
 cmake . # DO
 make    # THIS

THIS IS BAD. This will cripple your codebase with cmake-generated files, makefiles, and stuff. This is useless, ugly, and Cmake make out-of-source build very nice.

If you ever do this, there is a "" script to restore some sanity.

How to do an out-of-source build ?

 mkdir build
 cd build
 cmake ../code

NO, it will not mean more code. NO, it won't make anything longer, or take more disk space. It will just make sure your 'code' folder is not polluted with generated Makefiles. Which is good.
This way, you only have to tell git to ignore "build" alltogether, and you're done.


Nice tasks are :

 make tests

  Compile whatever you need, build a 'run_tests' program in the "build/bin" folder, and run it. It uses the good old text-base test runner. This is what you should be running all dong long.

 make run_tests

  Compile whatever you need, and run the test runner *only when something had to be rebuilt*

I separated test code from source code. Actually, there is a different library for the tests.

In the real world, you will have to edit some of the CMakeLists.txt files to add your own source (I still have to find how you can tell CMake to "use all the fracking cpp files in the current folder, dude")


This code is released under the "Do What The Fuck You Want Public License" (see COPYING.txt)

Copyleft 2009 Pierre-Henri Trivier