project(qemu) # Avoid Warning About DOWNLOAD_EXTRACT_TIMESTAMP if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.24.0) cmake_policy(SET CMP0135 NEW) endif() # Archive if(NOT DEFINED TRAMPOLINE_QEMU_ARCHIVE) message(FATAL_ERROR "Missing QEMU Archive") endif() # Flatpak Support set(QEMU_FLATPAK_PATCH "") if(MCPI_IS_FLATPAK_BUILD) set(QEMU_FLATPAK_PATCH "sed" "-i" "s/libdrm/libdrm-dis/g" "/meson.build") endif() # Build include(ExternalProject) set(PKGCONFIG_ENV "") if(DEFINED ENV{PKG_CONFIG_LIBDIR}) set(PKGCONFIG_ENV "PKG_CONFIG_LIBDIR=$ENV{PKG_CONFIG_LIBDIR}") endif() set(EXTRA_C_FLAGS "-s -I${CMAKE_CURRENT_SOURCE_DIR}/../include") ExternalProject_Add(qemu URL "${TRAMPOLINE_QEMU_ARCHIVE}" # Configure Build CONFIGURE_COMMAND "${CMAKE_COMMAND}" "-E" "env" ${PKGCONFIG_ENV} "CFLAGS=${EXTRA_C_FLAGS}" "CXXFLAGS=${EXTRA_C_FLAGS}" "/configure" "--prefix=${CMAKE_INSTALL_PREFIX}" "--cross-prefix=" "--cc=${CMAKE_C_COMPILER}" "--cxx=${CMAKE_CXX_COMPILER}" "--extra-ldflags=-ldl -Wl,-rpath=$ORIGIN/../lib/native -Wl,--disable-new-dtags" "--disable-debug-info" "--target-list=arm-linux-user" "--without-default-features" USES_TERMINAL_CONFIGURE TRUE # Build Command BUILD_COMMAND "ninja" "qemu-arm" BUILD_BYPRODUCTS "/qemu-arm" USES_TERMINAL_BUILD TRUE # Disable Install/Test Commands INSTALL_COMMAND "" TEST_COMMAND "" # Patch Command PATCH_COMMAND "patch" "-p1" "<" "${CMAKE_CURRENT_SOURCE_DIR}/src/trampoline.patch" COMMAND ${QEMU_FLATPAK_PATCH} ) # Install function(install_trampoline bin_dir legal_dir) ExternalProject_Get_property(qemu BINARY_DIR) install(PROGRAMS "${BINARY_DIR}/qemu-arm" DESTINATION "${bin_dir}" RENAME "trampoline") # License ExternalProject_Get_property(qemu SOURCE_DIR) install(FILES "${SOURCE_DIR}/COPYING" DESTINATION "${legal_dir}/qemu") endfunction()