Page 1 of 1

Differentiate RPi from other SBCs using compiler flags/etc

Posted: Wed Apr 13, 2016 6:43 am
by plusuncold
Hi,

I'm developing a program using Andrew Holme's GPU_FFT (which uses the Pi's GPU to speed up FFT), but it must also run on other OSes. Currently my code looks like this:

Code: Select all

FFT* FFT::getInstance() {
    if (!instance.get()) {
#if defined(__linux__)
        instance.reset(new RPiGPU_FFT);
#else
        instance.reset(new KissFFT);
#endif
    }
    return instance.get();
}
Where it will return a pointer from the FFT class's unique_ptr. On Linux this is an instance of RPiGPU_FFT (which is a wrapper class around GPU_FFT's C code) and on any other OS this is an instance of KissFFT, which is a general FFT library.

The issue is, if I compile this for a Linux computer that is not the Raspberry Pi it will fail to run. Does anyone know a way to differentiate between a RPi machine and a non-RPi machine? I'm using QMake as my make system currently, in conjuction with GCC.

Re: Differentiate RPi from other SBCs using compiler flags/e

Posted: Thu Apr 14, 2016 7:40 am
by jahboater
This file, if it exists, contains a nul terminated string starting with Raspberry Pi.

Code: Select all

/sys/firmware/devicetree/base/model

Re: Differentiate RPi from other SBCs using compiler flags/e

Posted: Mon Apr 18, 2016 11:16 am
by plusuncold
jahboater wrote:This file, if it exists, contains a nul terminated string starting with Raspberry Pi.

Code: Select all

/sys/firmware/devicetree/base/model
That's very helpful! Thanks!