Skip to contentSkip to conversation

cmake.bbclass: optionally support qemu

PATCH New Adrian Freihofer 1 participant 2 messages Nov 27, 2023

lore
Share & tools
lore
#0 lore raw

v2 cover cmake.bbclass: optionally support qemu

Changes in comparison to v1:

Improve the implementation according to Richard's suggestions. José's comments have also been taken into account.
https://lists.openembedded.org/g/openembedded-core/topic/89289917

- The idea is now to inherit the cmake-qemu.bbclass only where it really makes sense. This differs from the Meson implementation. But the limitations of this approach can be taken into account for each recipe individually.
- Drop the CMAKE_EXEWRAPPER_ENABLED variable again.
- Improve the comment

Adrian Freihofer (1):
cmake-qemu.bbclass: support qemu for cmake

 meta/classes-recipe/cmake-qemu.bbclass | 32 ++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)
 create mode 100644 meta/classes-recipe/cmake-qemu.bbclass
Signature · 1 line
2.41.0
#1 lore raw

PATCH v2 1/1 cmake-qemu.bbclass: support qemu for cmake

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]

---
 meta/classes-recipe/cmake-qemu.bbclass | 32 ++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)
 create mode 100644 meta/classes-recipe/cmake-qemu.bbclass
meta/classes-recipe/cmake-qemu.bbclass new file +32 -0
new file mode 100644
index 0000000000..482ad91895
@@ -0,0 +1,32 @@
+#
+# 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 part of the main cmake class by default.
+#
+# One use case is the execution of cross-compiled unit tests with CTest
+# on the build machine. If CMAKE_EXEWRAPPER_ENABLED is configured,
+#   cmake --build --target test
+# works transparently with qemu-user. If the cmake project is developed
+# with this use case in mind this works very nicely also out of an IDE
+# configured to use cmake-native for cross compiling.
+
+inherit qemu cmake
+
+DEPENDS:append:class-target = "${@' qemu-native' if bb.utils.contains('MACHINE_FEATURES', 'qemu-usermode', True, False, d) else ''}"
+
+cmake_do_generate_toolchain_file:append:class-target() {
+    if [ "${@bb.utils.contains('MACHINE_FEATURES', 'qemu-usermode', 'True', 'False', d)}" ]; 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
+}
Signature · 1 line
2.41.0