cmake-qemu.bbclass 1.5 KB

1234567891011121314151617181920212223242526272829303132
  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
  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.
  16. inherit qemu cmake
  17. DEPENDS:append:class-target = "${@' qemu-native' if bb.utils.contains('MACHINE_FEATURES', 'qemu-usermode', True, False, d) else ''}"
  18. cmake_do_generate_toolchain_file:append:class-target() {
  19. if ${@bb.utils.contains('MACHINE_FEATURES', 'qemu-usermode', 'true', 'false', d)}; then
  20. # Write out a qemu wrapper that will be used as exe_wrapper so that cmake
  21. # can run target helper binaries through that. This also allows to execute ctest.
  22. qemu_binary="${@qemu_wrapper_cmdline(d, '${STAGING_DIR_HOST}', ['${STAGING_DIR_HOST}/${libdir}','${STAGING_DIR_HOST}/${base_libdir}'])}"
  23. echo "#!/bin/sh" > "${WORKDIR}/cmake-qemuwrapper"
  24. echo "$qemu_binary \"\$@\"" >> "${WORKDIR}/cmake-qemuwrapper"
  25. chmod +x "${WORKDIR}/cmake-qemuwrapper"
  26. echo "set( CMAKE_CROSSCOMPILING_EMULATOR ${WORKDIR}/cmake-qemuwrapper)" \
  27. >> ${WORKDIR}/toolchain.cmake
  28. fi
  29. }