2024-06-04 21:50:17 +00:00
|
|
|
project(qemu)
|
|
|
|
|
2024-06-04 22:26:45 +00:00
|
|
|
# Avoid Warning About DOWNLOAD_EXTRACT_TIMESTAMP
|
|
|
|
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.24.0)
|
|
|
|
cmake_policy(SET CMP0135 NEW)
|
|
|
|
endif()
|
|
|
|
|
2024-06-04 21:50:17 +00:00
|
|
|
# Archive
|
2024-06-08 09:28:22 +00:00
|
|
|
if(NOT DEFINED RUNTIME_QEMU_ARCHIVE)
|
2024-06-04 21:50:17 +00:00
|
|
|
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" "<SOURCE_DIR>/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
|
2024-06-08 09:28:22 +00:00
|
|
|
URL "${RUNTIME_QEMU_ARCHIVE}"
|
2024-06-04 21:50:17 +00:00
|
|
|
# Configure Build
|
|
|
|
CONFIGURE_COMMAND
|
|
|
|
"${CMAKE_COMMAND}" "-E" "env"
|
|
|
|
${PKGCONFIG_ENV}
|
|
|
|
"CFLAGS=${EXTRA_C_FLAGS}"
|
|
|
|
"CXXFLAGS=${EXTRA_C_FLAGS}"
|
|
|
|
"<SOURCE_DIR>/configure"
|
|
|
|
"--prefix=${CMAKE_INSTALL_PREFIX}"
|
|
|
|
"--cross-prefix="
|
|
|
|
"--cc=${CMAKE_C_COMPILER}"
|
|
|
|
"--cxx=${CMAKE_CXX_COMPILER}"
|
2024-06-08 09:28:22 +00:00
|
|
|
"--extra-ldflags=-ldl -Wl,-rpath=${RUNTIME_RPATH} -Wl,${RUNTIME_EXTRA_LINK_FLAG}"
|
2024-06-04 21:50:17 +00:00
|
|
|
"--disable-debug-info"
|
|
|
|
"--target-list=arm-linux-user"
|
|
|
|
"--without-default-features"
|
|
|
|
USES_TERMINAL_CONFIGURE TRUE
|
|
|
|
# Build Command
|
|
|
|
BUILD_COMMAND "ninja" "qemu-arm"
|
|
|
|
BUILD_BYPRODUCTS "<BINARY_DIR>/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
|
2024-06-08 09:28:22 +00:00
|
|
|
function(install_runtime bin_dir legal_dir)
|
2024-06-04 21:50:17 +00:00
|
|
|
ExternalProject_Get_property(qemu BINARY_DIR)
|
2024-06-08 09:28:22 +00:00
|
|
|
install(PROGRAMS "${BINARY_DIR}/qemu-arm" DESTINATION "${bin_dir}" RENAME "runtime")
|
2024-06-04 21:50:17 +00:00
|
|
|
# License
|
|
|
|
ExternalProject_Get_property(qemu SOURCE_DIR)
|
|
|
|
install(FILES "${SOURCE_DIR}/COPYING" DESTINATION "${legal_dir}/qemu")
|
|
|
|
endfunction()
|