runtime/qemu/CMakeLists.txt

74 lines
2.1 KiB
CMake
Raw Normal View History

2024-06-04 17:50:17 -04:00
project(qemu)
2024-06-04 18:26:45 -04: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 17:50:17 -04:00
# Archive
2025-01-04 05:34:24 -05:00
set(QEMU_ARCHIVE "qemu-9.2.0.tar.xz")
set(QEMU_HASH "f859f0bc65e1f533d040bbe8c92bcfecee5af2c921a6687c652fb44d089bd894")
2024-06-04 17:50:17 -04:00
2024-11-10 05:26:16 -05:00
# Library
set(QEMU_LIBRARY "/lib/libqemu-arm.so")
2024-06-04 17:50:17 -04:00
2025-01-04 05:34:24 -05:00
# Patches
set(PATCHES "${CMAKE_CURRENT_SOURCE_DIR}/patches")
set(PATCH_CMD "patch" "-p1" "<")
# PkgConfig
2024-06-04 17:50:17 -04:00
set(PKGCONFIG_ENV "")
if(DEFINED ENV{PKG_CONFIG_LIBDIR})
set(PKGCONFIG_ENV "PKG_CONFIG_LIBDIR=$ENV{PKG_CONFIG_LIBDIR}")
endif()
2025-01-04 05:34:24 -05:00
# Build
include(ExternalProject)
2024-06-04 17:50:17 -04:00
ExternalProject_Add(qemu
2025-01-04 05:34:24 -05:00
URL "${CMAKE_CURRENT_SOURCE_DIR}/${QEMU_ARCHIVE}"
URL_HASH "SHA256=${QEMU_HASH}"
2024-06-04 17:50:17 -04:00
# Configure Build
CONFIGURE_COMMAND
"${CMAKE_COMMAND}" "-E" "env"
${PKGCONFIG_ENV}
"<SOURCE_DIR>/configure"
2024-11-10 05:26:16 -05:00
"--prefix=<INSTALL_DIR>"
2025-01-04 05:34:24 -05:00
# Cross-Compile
2024-06-04 17:50:17 -04:00
"--cross-prefix="
"--cc=${CMAKE_C_COMPILER}"
"--cxx=${CMAKE_CXX_COMPILER}"
2025-01-04 05:34:24 -05:00
# Optimize
2024-06-04 17:50:17 -04:00
"--disable-debug-info"
2024-11-10 05:26:16 -05:00
"--enable-strip"
"--enable-pie"
2025-01-04 05:34:24 -05:00
# Minimal Build
2024-06-04 17:50:17 -04:00
"--target-list=arm-linux-user"
"--without-default-features"
USES_TERMINAL_CONFIGURE TRUE
# Build Command
2025-01-04 05:34:24 -05:00
BUILD_COMMAND "ninja" "install"
2024-11-10 19:05:25 -05:00
BUILD_BYPRODUCTS "<INSTALL_DIR>${QEMU_LIBRARY}"
2024-06-04 17:50:17 -04:00
USES_TERMINAL_BUILD TRUE
# Patch Command
2025-01-04 05:34:24 -05:00
PATCH_COMMAND ${PATCH_CMD} "${PATCHES}/build-as-shared-library.patch"
COMMAND ${PATCH_CMD} "${PATCHES}/flatpak-support.patch"
COMMAND ${PATCH_CMD} "${PATCHES}/trampoline-syscall.patch"
2024-11-15 13:59:58 -05:00
# Disable Install Command
2024-11-10 19:05:25 -05:00
INSTALL_COMMAND ""
2024-06-04 17:50:17 -04:00
)
2024-11-10 05:26:16 -05:00
# Get Full Library Path
ExternalProject_Get_Property(qemu INSTALL_DIR)
string(PREPEND QEMU_LIBRARY "${INSTALL_DIR}")
# Link
target_link_libraries(runtime "${QEMU_LIBRARY}")
target_compile_definitions(trampoline-headers INTERFACE MCPI_HAS_QEMU)
2024-06-04 17:50:17 -04:00
# Install
2024-11-10 05:26:16 -05:00
if(DEFINED MCPI_LIB_DIR)
install(PROGRAMS "${QEMU_LIBRARY}" DESTINATION "${MCPI_LIB_DIR}")
2024-06-04 17:50:17 -04:00
# License
2024-11-10 05:26:16 -05:00
ExternalProject_Get_Property(qemu SOURCE_DIR)
2024-11-19 22:46:56 -05:00
install(FILES "${SOURCE_DIR}/COPYING" DESTINATION "${MCPI_LEGAL_DIR}/QEMU")
2024-11-10 05:26:16 -05:00
endif()