blob: 46a89e2827be418872155aa74ce6f9b9c4fda923 [file] [log] [blame]
Patrick Williamsda295312023-12-05 16:48:56 -06001#
2# Copyright OpenEmbedded Contributors
3#
4# SPDX-License-Identifier: MIT
5#
6# Not all platforms are supported by Qemu. Using qemu-user therefore
7# involves a certain risk, which is also the reason why this feature
Patrick Williams169d7bc2024-01-05 11:33:25 -06008# is not part of the main cmake class by default.
9#
10# One use case is the execution of cross-compiled unit tests with CTest
11# on the build machine. If CMAKE_EXEWRAPPER_ENABLED is configured,
12# cmake --build --target test
13# works transparently with qemu-user. If the cmake project is developed
14# with this use case in mind this works very nicely also out of an IDE
15# configured to use cmake-native for cross compiling.
Patrick Williamsda295312023-12-05 16:48:56 -060016
Patrick Williams169d7bc2024-01-05 11:33:25 -060017inherit qemu cmake
Patrick Williamsda295312023-12-05 16:48:56 -060018
Patrick Williams169d7bc2024-01-05 11:33:25 -060019DEPENDS:append:class-target = "${@' qemu-native' if bb.utils.contains('MACHINE_FEATURES', 'qemu-usermode', True, False, d) else ''}"
Patrick Williamsda295312023-12-05 16:48:56 -060020
21cmake_do_generate_toolchain_file:append:class-target() {
Patrick Williams169d7bc2024-01-05 11:33:25 -060022 if [ "${@bb.utils.contains('MACHINE_FEATURES', 'qemu-usermode', 'True', 'False', d)}" ]; then
23 # Write out a qemu wrapper that will be used as exe_wrapper so that cmake
Patrick Williamsda295312023-12-05 16:48:56 -060024 # can run target helper binaries through that. This also allows to execute ctest.
25 qemu_binary="${@qemu_wrapper_cmdline(d, '${STAGING_DIR_HOST}', ['${STAGING_DIR_HOST}/${libdir}','${STAGING_DIR_HOST}/${base_libdir}'])}"
26 echo "#!/bin/sh" > "${WORKDIR}/cmake-qemuwrapper"
27 echo "$qemu_binary \"\$@\"" >> "${WORKDIR}/cmake-qemuwrapper"
28 chmod +x "${WORKDIR}/cmake-qemuwrapper"
29 echo "set( CMAKE_CROSSCOMPILING_EMULATOR ${WORKDIR}/cmake-qemuwrapper)" \
30 >> ${WORKDIR}/toolchain.cmake
31 fi
32}