gnss-sdr/gnss-sdr — pull request #3 by anthony-arnold (2014-09-23 12:16:45+00:00)
Title: Compiling for ARM

In compiling GNSS-SDR for arm-linux-gnueabihf (essentially trying to get the package running on Raspberry Pi), I came across a couple of incompatibilities. The first was the use of SSE3 in `volk_cw_epl_corr.h`; if `GENERIC_ARCH` was not defined, the code assumes SSE3 is available, which is not necessarily the case.

The second incompatibility occurs when you enable `GENERIC_ARCH` in order to avoid the use of SSE3. This triggers CMake to append the `-mtune=generic` flag, which isn't defined for ARM GCC. The proper flag is `-mtune=generic-arm` (https://gcc.gnu.org/onlinedocs/gcc/ARM-Options.html).

A more robust solution was required in order to overcome this catch-22. So, I've first written a test that checks if you're compiling for ARM. If so, it attempts to make good default decisions about what architecture flags to set. As a bonus, the user may also supply the `ARCH_COMPILER_FLAGS` variable explicitly (which I do for the Pi, because [the optimal flags are pretty specific](http://raspberrypi.stackexchange.com/questions/2046/which-cpu-flags-are-suitable-for-gcc-on-raspberry-pi)).

Additionally, I've included a test for SIMD extensions in the case where the user is _not_ compiling with `GENERIC_ARCH`. For SSE3, it isn't enough just to check for the presence of the `pmmintrin.h` header file; it is often present even on systems where SSE3 is not available. If you include it in a compilation unit and try to compile it on a system that does not have SSE3, you will hit an `#error`. This is what the CMake function in `TestForSSE.cmake` checks for. So, if SSE3 isn't available with your compiler we disable the use of `volk_cw_epl_corr_u`, without having to resort to `GENERIC_ARCH`.

I have tested this setup inside a bootstrapped, chrooted, Debian "jessie" armhf system with GCC 4.9 (see [the bootstrap script](https://github.com/anthony-arnold/gnss-rpi-builder)). The CMake command I use is

cmake -DENABLE_RTLSDR=ON -DARCH_COMPILER_FLAGS="-march=armv6 -mfloat-abi=hard -mfpu=vfp" ../

I'm happy to report that GNSS-SDR is now running on a Raspberry Pi :)

P.S.

_Also_ included are updated `gfortran` search paths, both for GCC 4.9, and for GNU Linux armhf.