Patrick Williams | da29531 | 2023-12-05 16:48:56 -0600 | [diff] [blame] | 1 | # |
| 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 Williams | 169d7bc | 2024-01-05 11:33:25 -0600 | [diff] [blame] | 8 | # 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 Williams | da29531 | 2023-12-05 16:48:56 -0600 | [diff] [blame] | 16 | |
Patrick Williams | 169d7bc | 2024-01-05 11:33:25 -0600 | [diff] [blame] | 17 | inherit qemu cmake |
Patrick Williams | da29531 | 2023-12-05 16:48:56 -0600 | [diff] [blame] | 18 | |
Patrick Williams | 169d7bc | 2024-01-05 11:33:25 -0600 | [diff] [blame] | 19 | DEPENDS:append:class-target = "${@' qemu-native' if bb.utils.contains('MACHINE_FEATURES', 'qemu-usermode', True, False, d) else ''}" |
Patrick Williams | da29531 | 2023-12-05 16:48:56 -0600 | [diff] [blame] | 20 | |
| 21 | cmake_do_generate_toolchain_file:append:class-target() { |
Patrick Williams | 169d7bc | 2024-01-05 11:33:25 -0600 | [diff] [blame] | 22 | 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 Williams | da29531 | 2023-12-05 16:48:56 -0600 | [diff] [blame] | 24 | # 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 | } |