]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core.git/commitdiff
cmake-qemu.bbclass: support qemu for cmake
authorAdrian Freihofer <adrian.freihofer@gmail.com>
Mon, 20 Nov 2023 14:46:27 +0000 (15:46 +0100)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Thu, 30 Nov 2023 08:42:52 +0000 (08:42 +0000)
Define the CMAKE_CROSSCOMPILING_EMULATOR variable similar to what the
meson bbclass does. This allows for example to execute cross compilied
unit tests on the build machine when using an SDK.

CMAKE_CROSSCOMPILING_EMULATOR is a semi colon separated list of
paramters which could directly handle the -L and the -E parameters.
Creating a wrapper script is not absolutely mandatory. But anyway lets
do it similar to what the meson.bbclass does and also disable pseudo.

Further information can be found in the camke documentation in the
CMAKE_CROSSCOMPILING_EMULATOR section.

Keep the code optional, as the core does not need this function and does
not intend to use it in the future.

[YOCTO #15214]

Signed-off-by: Adrian Freihofer <adrian.freihofer@siemens.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
meta/classes-recipe/cmake-qemu.bbclass [new file with mode: 0644]

diff --git a/meta/classes-recipe/cmake-qemu.bbclass b/meta/classes-recipe/cmake-qemu.bbclass
new file mode 100644 (file)
index 0000000..76b748f
--- /dev/null
@@ -0,0 +1,28 @@
+#
+# Copyright OpenEmbedded Contributors
+#
+# SPDX-License-Identifier: MIT
+#
+# Not all platforms are supported by Qemu. Using qemu-user therefore
+# involves a certain risk, which is also the reason why this feature
+# is not activated by default.
+
+inherit qemu
+
+CMAKE_EXEWRAPPER_ENABLED:class-native = "False"
+CMAKE_EXEWRAPPER_ENABLED:class-nativesdk = "False"
+CMAKE_EXEWRAPPER_ENABLED ?= "${@bb.utils.contains('MACHINE_FEATURES', 'qemu-usermode', 'True', 'False', d)}"
+DEPENDS:append = "${@' qemu-native' if d.getVar('CMAKE_EXEWRAPPER_ENABLED') == 'True' else ''}"
+
+cmake_do_generate_toolchain_file:append:class-target() {
+    if [ "${CMAKE_EXEWRAPPER_ENABLED}" = "True" ]; then
+        # Write out a qemu wrapper that will be used as exe_wrapper so that camake
+        # can run target helper binaries through that. This also allows to execute ctest.
+        qemu_binary="${@qemu_wrapper_cmdline(d, '${STAGING_DIR_HOST}', ['${STAGING_DIR_HOST}/${libdir}','${STAGING_DIR_HOST}/${base_libdir}'])}"
+        echo "#!/bin/sh" > "${WORKDIR}/cmake-qemuwrapper"
+        echo "$qemu_binary \"\$@\"" >> "${WORKDIR}/cmake-qemuwrapper"
+        chmod +x "${WORKDIR}/cmake-qemuwrapper"
+        echo "set( CMAKE_CROSSCOMPILING_EMULATOR ${WORKDIR}/cmake-qemuwrapper)" \
+          >> ${WORKDIR}/toolchain.cmake
+    fi
+}