1# How to build from source
2
3## Requirements
4
5### Common requirements
6
7In order to build cmocka, you need to install several components:
8
9- A C compiler
10- [CMake](http://www.cmake.org) >= 3.5.0.
11
12Note that these version numbers are version we know works correctly. If you
13build and run cmocka successfully with an older version, please let us know.
14
15## Building
16First, you need to configure the compilation, using CMake. Go inside the
17`build` dir. Create it if it doesn't exist.
18
19GNU/Linux, MacOS X, MSYS/MinGW:
20
21    cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Debug ..
22    make
23
24On Windows you should choose a makefile gernerator with -G, for example:
25
26   cmake -G "Visual Studio 12 2013" -DCMAKE_BUILD_TYPE=Debug /path/to/source
27
28You can also use the CMake GUI which is shipped with CMake. It will list all
29available generators for MSVC on Windows. We only support Visual Studio 2013
30or newer which supports C99.
31
32### CMake standard options
33Here is a list of the most interesting options provided out of the box by
34CMake.
35
36- CMAKE_BUILD_TYPE:     The type of build (can be Debug Release MinSizeRel
37                        RelWithDebInfo)
38- CMAKE_INSTALL_PREFIX: The prefix to use when running make install (Default
39                        to /usr/local on GNU/Linux and MacOS X)
40- CMAKE_C_COMPILER:     The path to the C compiler
41- CMAKE_CXX_COMPILER:   The path to the C++ compiler
42
43### CMake options defined for cmocka
44
45Options are defined in the following files:
46
47- DefineOptions.cmake
48
49They can be changed with the -D option:
50
51`cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Debug -DUNIT_TESTING=ON ..`
52
53### Browsing/editing CMake options
54
55In addition to passing options on the command line, you can browse and edit
56CMake options using `cmakesetup` (Windows), `cmake-gui` or `ccmake` (GNU/Linux
57and MacOS X).
58
59- Go to the build dir
60- On Windows: run `cmakesetup`
61- On GNU/Linux and MacOS X: run `ccmake ..`
62
63## Installing
64
65If you want to install cmocka after compilation run:
66
67    make install
68
69## Running
70
71The cmocka library can be found in the `build/src` directory.
72You can run the binaries in `build/examples/*` which is a
73are example tests.
74
75## Testing
76
77As mention above you can turn on the unit tests and make it possible to easily
78execute them:
79
80`cmake -DCMAKE_BUILD_TYPE=Debug -DUNIT_TESTING=ON ..`
81
82After that you can simply call `make test` in the build directory or if you
83want more output simply call `ctest -V`.
84
85If you want to enable the generation of coverage files you can do this by
86using the following options:
87
88`cmake -DCMAKE_BUILD_TYPE=Profiling -DUNIT_TESTING=ON ..`
89
90After building it you will see that you have several coverage options in
91
92`make help`
93
94You should have `make ExperimentalCoverage` and running it will create
95coverage files. The result is stored in Testing directory.
96
97## About this document
98
99This document is written using [Markdown][] syntax, making it possible to
100provide usable information in both plain text and HTML format. Whenever
101modifying this document please use [Markdown][] syntax.
102
103[markdown]: http://www.daringfireball.net/projects/markdown
104