mardi 2 juin 2015

Configuring CMake to re-compile source when unit testing

I have a project structure defined below with both src and test directories.

├── CMakeLists.txt
├── src
│   ├── CMakeLists.txt
│   ├── table.c
│   └── table.h
├── test
│   ├── CMakeLists.txt
│   └── test_table.c
├── build
    ├── src    [src build]
    └── test   [src + test build with UNIT_TESTING defined]

I'd like to configure cmake so that when the tests (unit testing) directory is built that it also compiles files in the ./src directory with the UNIT_TESTING define set and puts all build artifacts in the ./build/test/ directory.

This is so that I can track memory leaks by using wrapper functions for malloc free etc when UNIT_TESTING and the real memory allocation functions when building normally without unit test.

Does anyone know how to get me started?

Aucun commentaire:

Enregistrer un commentaire