1Building UPM {#building} 2============ 3 4UPM uses cmake in order to make compilation relatively painless. Cmake runs 5build out of tree so the recommended way is to clone from git and make a build/ 6directory. 7 8This project depends on libmraa, so that needs to be installed first. Use the 9following environment variables to configure the paths: 10 11 PKG_CONFIG_PATH=$PKG_CONFIG_PATH:.../mraa/build/lib/pkgconfig 12 CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH:.../mraa/build/include 13 LIBRARY_PATH=$LIBRARY_PATH:.../mraa/build/lib 14 15UPM will attempt to build all directories inside src/ and they must contain 16individual CMakeLists.txt files. 17 18~~~~~~~~~~~~~{.sh} 19mkdir build 20cd build 21cmake .. 22make 23make install 24~~~~~~~~~~~~~ 25 26The last command will create the include/ and lib/ directories with a copy of 27the headers and library objects respectively in your build location. Note that 28doing an out-of-source build may cause issues when rebuilding later on. 29 30Our cmake configure has a number of options, *cmake-gui* or *ccmake* can show 31you all the options. The interesting ones are detailed below: 32 33Changing install path from /usr/local to /usr 34~~~~~~~~~~~~~ 35-DCMAKE_INSTALL_PREFIX:PATH=/usr 36~~~~~~~~~~~~~ 37Building debug build: 38~~~~~~~~~~~~~ 39-DCMAKE_BUILD_TYPE=DEBUG 40~~~~~~~~~~~~~ 41Using clang instead of gcc: 42~~~~~~~~~~~~~ 43-DCMAKE_C_COMPILER=/usr/bin/clang -DCMAKE_CXX_COMPILER=/usr/bin/clang++ 44~~~~~~~~~~~~~ 45Cross-compiling on a different system: 46~~~~~~~~~~~~~ 47-DCMAKE_CXX_FLAGS:STRING=-m32 -march=i586 48-DCMAKE_C_FLAGS:STRING=-m32 -march=i586 49~~~~~~~~~~~~~ 50Building with an older version of swig (swig 2.0+) requires the disabling of javascript: 51~~~~~~~~~~~~~ 52-DBUILDSWIGNODE=OFF 53~~~~~~~~~~~~~ 54Disabling python module building 55~~~~~~~~~~~~~ 56-DBUILDSWIGPYTHON=OFF 57~~~~~~~~~~~~~ 58Setting the python library to use: 59~~~~~~~~~~~~~ 60-DPYTHON_LIBRARY:FILEPATH=/usr/lib/libpython2.7.so.1.0 61~~~~~~~~~~~~~ 62Building doxygen doc 63~~~~~~~~~~~~~ 64-DBUILDDOC=ON 65~~~~~~~~~~~~~ 66Build C++ example binaries 67~~~~~~~~~~~~~ 68-DBUILDEXAMPLES=ON 69~~~~~~~~~~~~~ 70 71If you intend to turn on all the options and build everything at once (C++, 72Node, Python and Documentation) you will have to edit the src/doxy2swig.py file 73and change the line endings from Windows style to Linux format. This has to be 74repeated every time to sync with the master branch since our Github repository 75stores files using CR LF line breaks. 76 77You can also generate the include and lib directories containing all the sensor 78headers and library files respectively with *make install*. Further, you may 79choose to generate these only for a specific sensor you modified, and this can 80be achieved by building from the individual makefile of the sensor. Assuming 81you're in the build directory, to make the lcd module you would: 82 83~~~~~~~~~~~~~ 84cd src/lcd 85make install 86~~~~~~~~~~~~~ 87 88Often developers are only interested in building one module or even just the 89python/node module to do some quick testing using scripting. In order to do 90this you need to use the target name for the python or node module you want to 91rebuild. For example the lcd module target name is i2clcd. Therefore the python 92module target name will be prefixed by _pyupm_. Just do the following to build 93only that module. Modules not using the UPM cmake macros may have different 94naming. 95 96~~~~~~~~~~~~~ 97make _pyupm_i2clcd 98~~~~~~~~~~~~~ 99 100Sometimes you want to build a small C++ example against an installed library. 101This is fairly easy if installed system-wide. Just link against the correct 102library (in this case libupm-i2clcd) and then add /usr/include/upm to the 103loader path: 104 105~~~~~~~~~~~~ 106g++ test.cxx -lupm-i2clcd -I/usr/include/upm 107~~~~~~~~~~~~ 108 109You can also use pkg-config to return the information to you, which is 110considered the correct way if including UPM in a build system like cmake or 111autotools on linux. 112 113~~~~~~~~~~~ 114pkg-config --cflags --libs upm-i2clcd 115~~~~~~~~~~~ 116