Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 3552

C/C++ • Cross compile using cmake

$
0
0
Hi Folks,

Long preamble before the question. Necessary I'm afraid.

I really shouldn't have gone down this rabbit hole considering how much I loathe xgcc environments. That said, I needed to in order to build mysql (mariadb) client for an old rpi box which my app 'sdv' needs. That was a world of pain: (mariadb cmake). The core issue is I built multiple xgcc, one for each target rpi OS such that the output would not need any support libraries. Thus "bullseye" gets gcc 10.2.0 built against the glibc for the base version of bulleye, buster gets gcc 8.3.0 against a buster glibc and so forth. I even managed to fudge a gcc 4.9.4 for jessie. There's both arm and aarch64 versions where applicable.

The above were all a side-issue though. The real purpose was the "generic" xgcc. This uses gcc 14.2.0 and targets the oldest viable glibc, thus enabling me to compile modern code for an old target. Everything works fine with "configure" type builds and even with cmake for the 'sdv' app.

The "--with-sysroot for each compiler build is "/usr/local/RPI/[arch]/[os]". eg:

Code:

foo@sdu:~$ lc /usr/local/RPI/*/usr/local/RPI/aarch64-linux-gnu:total 16drwxrwxr-x 11 foo foo 4096 Oct 31 02:00 bookwormdrwxrwxr-x 12 foo foo 4096 Oct 31 02:23 bullseyedrwxrwxr-x 11 foo foo 4096 Oct  6 09:13 busterdrwxrwxr-x 12 foo foo 4096 Oct 31 02:15 generic/usr/local/RPI/arm-linux-gnueabihf:total 24drwxrwxr-x 11 foo foo 4096 Oct  6 08:20 bookwormdrwxrwxr-x 11 foo foo 4096 Oct  6 08:29 bullseyedrwxrwxr-x 11 foo foo 4096 Oct 28 20:05 busterdrwxrwxr-x 12 foo foo 4096 Oct 31 02:01 genericdrwxrwxr-x 12 foo foo 4096 Oct 31 02:08 jessiedrwxrwxr-x 11 foo foo 4096 Oct 28 21:09 latest
..so to be explicit for (eg) 32bit bulleye..

Code:

foo@sdu:~$ /usr/local/RPI/arm-linux-gnueabihf/bullseye/bin/arm-linux-gnueabihf-gcc -vUsing built-in specs.COLLECT_GCC=/usr/local/RPI/arm-linux-gnueabihf/bullseye/bin/arm-linux-gnueabihf-gccCOLLECT_LTO_WRAPPER=/usr/local/RPI/arm-linux-gnueabihf/bullseye/libexec/gcc/arm-linux-gnueabihf/10.2.0/lto-wrapperTarget: arm-linux-gnueabihfConfigured with: ../gcc-10.2.0/configure --prefix=/usr/local/RPI/arm-linux-gnueabihf/bullseye --enable-languages=c,c++ --disable-multilib --target=arm-linux-gnueabihf --with-pkgversion=2024/10/06-07:23 --enable-shared --enable-linker-build-id --without-included-gettext --enable-threads=posix --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-libquadmath --disable-libquadmath-support --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --enable-fix-cortex-a53-843419 --enable-checking=release --with-build-config=bootstrap-lto-lean --enable-link-mutex --with-arch=armv6 --with-fpu=vfp --with-float=hard --with-sysroot=/usr/local/RPI/arm-linux-gnueabihf/bullseye --with-native-system-header-dir=/includeThread model: posixSupported LTO compression algorithms: zlibgcc version 10.2.0 (2024/10/06-07:23)
Note the sysroot.

I cross compile everything into "sysroot"/usr. Good reasons for this. I don't want to corrupt the compiler "/include" and "/lib" with stuff because cross-compiles so often go wrong and I don't want to be blatting & rebuilding the compiler(s) every time some library installs x86 stuff into "/lib".

Turns out cmake is problematic in this. I need to able to say..

Code:

CMAKE_SYSROOT="/usr/local/RPI/arm-linux-gnueabihf/bullseye , /usr/local/RPI/arm-linux-gnueabihf/bullseye/usr"
..but obviously that doesn't make sense.

Google is becoming increasingly useless. I've tried so many cmake variables from google.

I'd expect cmake to be looking down "sysroot"/usr/[include|lib]" by default as well as "sysroot/[include|lib]" but it doesn't. Finally, my question..

How to get cmake to do that?

Statistics: Posted by swampdog — Sun Nov 03, 2024 4:36 am



Viewing all articles
Browse latest Browse all 3552

Trending Articles