Skip to content

Commit

Permalink
cmake.bbclass: support qemu
Browse files Browse the repository at this point in the history
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.

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.

Signed-off-by: Adrian Freihofer <[email protected]>
  • Loading branch information
afreof authored and deribaucourt committed Sep 27, 2023
1 parent 2a86303 commit 034dc95
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions meta/classes-recipe/cmake.bbclass
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
# SPDX-License-Identifier: MIT
#

inherit qemu

EXEWRAPPER_ENABLED:class-native = "False"
EXEWRAPPER_ENABLED:class-nativesdk = "False"
EXEWRAPPER_ENABLED ?= "${@bb.utils.contains('MACHINE_FEATURES', 'qemu-usermode', 'True', 'False', d)}"
DEPENDS:append = "${@' qemu-native' if d.getVar('EXEWRAPPER_ENABLED') == 'True' else ''}"

# Path to the CMake file to process.
OECMAKE_SOURCEPATH ??= "${S}"

Expand Down Expand Up @@ -156,6 +163,20 @@ EOF

addtask generate_toolchain_file after do_patch before do_configure

cmake_do_generate_toolchain_file:append:class-target() {
if [ "${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
}


CONFIGURE_FILES = "CMakeLists.txt"

do_configure[cleandirs] = "${@d.getVar('B') if d.getVar('S') != d.getVar('B') else ''}"
Expand Down

0 comments on commit 034dc95

Please sign in to comment.