building.md: add more building information
[contrib/mraa.git] / docs / building.md
1 Building libmraa                         {#building}
2 ===============
3
4 libmraa uses cmake in order to make compilation relatively painless. Cmake runs
5 build out of tree so the recommended way is to clone from git and make a build/ directory.
6
7 You'll need swig version 3.0.2 and we recommend 3.0.3 to build the javascript
8 modules. If you're version of SWIG is older than this then please see below for
9 disabling SWIGNODE otherwise you will get a weird build failure.
10
11 The basic build steps are as follow, we'll assume you're building from git,
12 note that if you compile with git installed your version of mraa will be tagged
13 -dirty. This simply means git wasn't installed or that you where building form
14 a tarball. You can modify build/src/version.c before running make if this is
15 incorrect. The instructions listed here all assume that build/ is an empty dir
16 that lives inside the cloned repository of mraa.
17
18 ~~~~~~~~~~~~~{.sh}
19 mkdir build
20 cd build
21 cmake ..
22 make
23 ~~~~~~~~~~~~~
24
25 Our cmake configure has a number of options, cmake-gui or ccmake (cmake -i is
26 no longer with us :() can show you all the options. A few of the more common
27 ones are listed below - note that when the option starts with CMAKE_ it's an
28 option that is made available by cmake and will be similar in all cmake
29 projects. You need to add them after `cmake` but before `..`.
30
31 A few recommended options:
32 Changing install path from /usr/local to /usr
33  -DCMAKE_INSTALL_PREFIX:PATH=/usr
34
35 Building debug build - adds -g and disables optimisations - this will force a full rebuild:
36  -DCMAKE_BUILD_TYPE=DEBUG
37
38 Using clang instead of gcc:
39  -DCMAKE_C_COMPILER=/usr/bin/clang -DCMAKE_CXX_COMPILER=/usr/bin/clang
40
41 Building with an older version of swig (swig < 3.0.2) requires the disabling of javascript:
42  -DBUILDSWIGNODE=OFF
43
44 Disabling python module building
45  -DBUILDSWIGPYTHON=OFF
46
47 Building doc, this will require sphinx & doxygen
48  -BUILDDOC=ON
49
50 Using a yocto/oe toolchain
51 --------------------------
52
53 In order to compile with a yocto/oe toolchain use the following toolchain file.
54 This works well on the edison 1.6 SDK. First source the environment file, then
55 use our cmake toolchain file.
56
57 ~~~~~~~~~~~~~{.sh}
58 source /opt/poky-edison/1.6/environment-setup-core2-32-poky-linux
59 mkdir build
60 cmake -DCMAKE_TOOLCHAIN_FILE=../cmake/Toolchains/oe-sdk_cross.cmake ..
61 make
62 ~~~~~~~~~~~~~
63
64 Using coverity
65 --------------
66
67 Static analysis is routinely performed using coverity on libmraa's codebase.
68 This is the procedure to submit a build to coverity. You'll need to install
69 coverity-submit for your OS.
70
71 ~~~~~~~~~~~~~{.sh}
72 mkdir covbuild/ && cd covbuild
73 cmake -DBUILDDOC=OFF -DBUILDSWIG=OFF ..
74 cov-build --dir cov-int make
75 tar caf mraa.tar.bz2 cov-int
76 ~~~~~~~~~~~~~