blob: c21ed0079ee542edad3e06a7b4c2302f3aff2de5 [file] [log] [blame]
cmake_policy(SET CMP0048 NEW)
project(Android-Emulator)
cmake_minimum_required(VERSION 3.12)
# Set this policy to allow gfxstream to modify the passed in targets like
# ${GFXSTREAM_HOST_COMMON_LIB}.
cmake_policy(SET CMP0079 NEW)
# Let's setup a compiler cache.
if(NOT WINDOWS_MSVC_X86_64 AND OPTION_CCACHE)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${OPTION_CCACHE}")
message(STATUS "Using ${OPTION_CCACHE} as a compiler cache.")
endif()
if(NOT Python_EXECUTABLE)
find_package(Python3 COMPONENTS Interpreter)
if(NOT Python3_FOUND)
message(FATAL_ERROR "A python interpreter is required. ")
endif()
set(Python_EXECUTABLE ${Python3_EXECUTABLE})
endif()
message(STATUS "Using Python: ${Python_EXECUTABLE}")
if(NOT DEFINED ANDROID_TARGET_TAG)
message(
WARNING
"You need to invoke the cmake generator with a proper toolchain from android/build/cmake, "
"It is best to invoke: android/scripts/rebuild. "
"Using the system toolchain might have unintended consequences, and you will need all required "
"packages to build qemu (https://wiki.qemu.org/Hosts/Linux,https://wiki.qemu.org/Hosts/Mac)."
)
list(APPEND CMAKE_MODULE_PATH
"${CMAKE_CURRENT_LIST_DIR}/android/build/cmake/")
include(toolchain)
_get_host_tag(TAG)
toolchain_configure_tags(${TAG})
endif()
if(ANDROID_TARGET_TAG STREQUAL "darwin-aarch64")
set(BUILDING_FOR_AARCH64 TRUE)
elseif(LINUX_AARCH64)
set(BUILDING_FOR_AARCH64 TRUE)
else()
set(BUILDING_FOR_AARCH64 FALSE)
endif()
if(BUILDING_FOR_AARCH64)
message(STATUS "Building for aarch64!")
endif()
message(
STATUS
"Configured host ${ANDROID_HOST_TAG} to target: ${ANDROID_TARGET_TAG}, target os: ${ANDROID_TARGET_OS}/${ANDROID_TARGET_OS_FLAVOR}"
)
include(android)
include(prebuilts)
include(qemu2-src-gen)
set(OPTION_BAZEL TRUE CACHE BOOL "Enable bazel compilation (Linux only).")
set(OPTION_CRASHUPLOAD "NONE" CACHE STRING "Destination of crash reports.")
set(OPTION_TRACE
"nop"
CACHE
STRING
"The qemu tracing backend to use. Should be one of: [nop, dtrace, ftrace, log, simple, syslog, ust]"
)
set(OPTION_SDK_TOOLS_REVISION "" CACHE STRING
"The tools revision to use, if any")
set(OPTION_SDK_TOOLS_BUILD_NUMBER ""
CACHE STRING "The sdk buildnumber to use, if any.")
set(OPTION_ASAN "" CACHE STRING "The list of build sanitizers to user")
set(OPTION_COVERAGE_IN_DEBUG FALSE
CACHE BOOL "Code coverage in debug builds.")
set(OPTION_ASAN_IN_DEBUG TRUE
CACHE BOOL "Asan for debug builds.")
set(OPTION_TIME_INFO FALSE
CACHE BOOL "Collect compile time statistics.")
set(OPTION_CLANG_TIDY
""
CACHE
STRING
"List of targets for which you wish to run clang-tidy for code analysis.")
set(OPTION_CLANG_TIDY_FIX FALSE
CACHE BOOL "Auto fix issues clang-tidy encounters.")
set(OPTION_CLANG_THREAD_SAFETY_CHECKS FALSE
CACHE BOOL "Compile-time thread safety checks (-Wthread-safety).")
set(QTWEBENGINE FALSE CACHE BOOL "The webengine (chromium) that provides the location UI.")
if(LINUX_X86_64)
set(WEBRTC TRUE
CACHE BOOL "Build with WEBRTC support.")
else()
set(WEBRTC
FALSE
CACHE
BOOL
"Build with WEBRTC support."
)
endif()
set(ANDROIDSTUDIO FALSE
CACHE BOOL
"Android Studio Java bridge (Deprecated).")
set(OPTION_MINBUILD
FALSE
CACHE
BOOL
"Minimum set of components to support 64-bit guets only."
)
set(OPTION_TCMALLOC
TRUE
CACHE
BOOL
"Use TCMalloc on supported platforms (currently, linux)."
)
set(OPTION_GFXSTREAM_BACKEND
FALSE
CACHE
BOOL
"Build the gfxstream backend (plus everything else).")
set(OPTION_TEST_LOGS "${CMAKE_BINARY_DIR}/testlogs" CACHE
STRING "Directory where all the unit test xml files will be stored.")
set(GFXSTREAM
FALSE
CACHE
BOOL
"Build gfxstream, crosvm, and its accompanying libraries/tests."
)
set(OPTIONS_BUILD_PACKET_GEN
FALSE
CACHE
BOOL
"Generate the bluetooth packet generator .yy and .ll files (posix only)."
)
set(OPTION_AEMU_LIBS_ONLY FALSE
CACHE BOOL "Build only AEMU libraries and their tests.")
set(GFXSTREAM_ONLY FALSE CACHE BOOL "Build only gfxstream.")
set(OPTION_ENABLE_SYSTEM_RUST
FALSE
CACHE
BOOL
"Use the system rust compiler, only needed on Mac M1 or Windows."
)
if (FEATURE_NETSIM_FROM_SOURCE)
set(OPTION_RUST TRUE CACHE BOOL "Enable all rust dependencies.")
endif()
if(OPTION_RUST)
if (DARWIN_AARCH64 AND NOT Rust_COMPILER)
message(STATUS "On Apple sillicon attempting to use platform toolchain if available.")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/android/build/cmake/corrosion/cmake/")
find_package(Rust REQUIRED)
if (TARGET Rust::Rustc)
set(OPTION_ENABLE_SYSTEM_RUST TRUE)
else()
message(STATUS "Unable to derive local toolchain, using cross compilation.")
message(STATUS "If you are a developer you can install rust with `curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh`")
endif()
endif()
if(Rust_COMPILER OR OPTION_ENABLE_SYSTEM_RUST)
if(OPTION_ENABLE_SYSTEM_RUST)
message(STATUS "Attempting to use the system rust compiler")
use_system_rust_toolchain()
endif()
enable_vendorized_crates("${ANDROID_QEMU2_TOP_DIR}/android/third_party/rust/crates")
add_subdirectory(android/build/cmake/corrosion)
ensure_rust_version_is_compliant()
endif()
else()
message(WARNING "Disabling RUST, you might have reduced functionality.")
endif()
if(GFXSTREAM_ONLY)
set(GFXSTREAM TRUE)
endif()
if(LINUX_AARCH64)
set(QTWEBENGINE FALSE)
set(GFXSTREAM TRUE)
endif()
if(DARWIN_AARCH64)
set(OPTION_TCMALLOC FALSE)
endif()
if(WINDOWS_MSVC_X86_64 OR DARWIN_AARCH64 OR DARWIN_X86_64)
if (NOT GFXSTREAM)
message(WARNING "--gfxstream option is now a requirement on Mac/Windows. Force-enabling gfxstream.")
set(GFXSTREAM TRUE)
endif()
endif()
if(GFXSTREAM)
set(OPTION_GFXSTREAM_BACKEND TRUE)
set(OPTION_TCMALLOC FALSE)
set(ANDROIDSTUDIO FALSE)
endif()
string(STRIP "${OPTION_SDK_TOOLS_BUILD_NUMBER}" OPTION_SDK_TOOLS_BUILD_NUMBER)
string(STRIP "${OPTION_SDK_TOOLS_REVISION}" OPTION_SDK_TOOLS_REVISION)
set_property(CACHE OPTION_CRASHUPLOAD PROPERTY STRINGS NONE STAGING PROD)
set(DBG_INFO ${CMAKE_BINARY_DIR}/build/debug_info)
# Symbol extraction is not supported when cross compiling.
set(ANDROID_SYMBOL_DIR ${CMAKE_BINARY_DIR}/build/symbols)
if(NOT OPTION_CRASHUPLOAD STREQUAL "NONE")
if(WIN32)
file(STRINGS "$ENV{USERPROFILE}/.emulator_symbol_server_key"
BREAKPAD_API_KEY)
else()
file(STRINGS "$ENV{HOME}/.emulator_symbol_server_key" BREAKPAD_API_KEY)
endif()
message(STATUS "Uploading symbols to ${BREAKPAD_API_URL}")
endif()
set(FEATURE_NETSIM_FROM_SOURCE FALSE CACHE BOOL "Build the netsim network simulator from source. **DEPRECATED**")
# Make sure targets have complete control of include order.
set(CMAKE_INCLUDE_CURRENT_DIR OFF)
# Build protobuf as a shared library.
set(protobuf_BUILD_SHARED_LIBS TRUE)
# Enable C++17 in C++ (Note, cmake does not set the proper flags when using
# CXX_STANDARD) with our custom clang.
if(WINDOWS_MSVC_X86_64)
add_cxx_flag("-std:c++17")
else()
add_cxx_flag("-std=c++17")
endif()
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Gather compile time statistics
if(OPTION_TIME_INFO)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CMAKE_COMMAND} -E time")
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK "${CMAKE_COMMAND} -E time")
endif()
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(ANDROID_EMULATOR_BUILD ON)
# Let's bin place everything in the root, with the shared libs in the right
# place
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib64)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/archives)
set(CMAKE_PDB_OUTPUT_DIRECTORY ${DBG_INFO})
# Feeling courageous? Set this to $ANDROID_SDK_ROOT
if(DARWIN_X86_64 OR DARWIN_AARCH64)
set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/distribution/emulator)
set(CMAKE_INSTALL_CODESIGN ${CMAKE_BINARY_DIR}/distribution/_codesign)
else()
set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/distribution/emulator)
endif()
# Pthreads from the prebuilts please!
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
prebuilt(Threads)
if(DARWIN_X86_64 OR DARWIN_AARCH64)
install(FILES ${ANDROID_QEMU2_TOP_DIR}/entitlements.plist
DESTINATION ${CMAKE_INSTALL_CODESIGN} RENAME entitlements.xml)
install(FILES ${ANDROID_QEMU2_TOP_DIR}/filelist
DESTINATION ${CMAKE_INSTALL_CODESIGN})
endif()
# Create the needed qemu2 sources, with the desired backend.
generate_qemu2_sources(TRACE_BACKEND ${OPTION_TRACE} DEST
${CMAKE_CURRENT_BINARY_DIR}/generated-sources)
string(TOUPPER "${OPTION_TRACE}" TRACE_CONFIG)
set(TRACE_CONFIG "CONFIG_TRACE_${TRACE_CONFIG}")
if(LINUX_AARCH64)
file(
COPY ${ANDROID_QEMU2_TOP_DIR}/android/scripts/unix/linux-aarch64-fixgcc.sh
DESTINATION ${CMAKE_INSTALL_PREFIX})
file(
COPY ${ANDROID_QEMU2_TOP_DIR}/../../prebuilts/android-emulator-build/qemu-android-deps/linux-aarch64/lib/glibc-2.29.tgz
DESTINATION ${CMAKE_INSTALL_PREFIX}/lib64)
file(
COPY ${ANDROID_QEMU2_TOP_DIR}/../../prebuilts/android-emulator-build/qemu-android-deps/linux-aarch64/lib/patchelf.tgz
DESTINATION ${CMAKE_INSTALL_PREFIX})
endif()
# Configure OS depdendency licensenses
if(LINUX_AARCH64)
message("Cross build aarch64 libstdc++")
android_license(
TARGET "RUNTIME_OS_DEPENDENCIES"
LIBNAME "libstdc++"
URL "https://packages.debian.org/sid/crossbuild-essential-arm64"
SPDX "LLVM-exception"
LICENSE
"https://android.googlesource.com/toolchain/clang/+/refs/heads/master/LICENSE.TXT"
LOCAL "${ANDROID_QEMU2_TOP_DIR}/LICENSES/LICENSE.LLVM")
elseif(LINUX_X86_64)
android_license(
TARGET "RUNTIME_OS_DEPENDENCIES"
LIBNAME "libc++"
URL "https://android.googlesource.com/toolchain/clang/+/refs/heads/master/"
SPDX "LLVM-exception"
LICENSE
"https://android.googlesource.com/toolchain/clang/+/refs/heads/master/LICENSE.TXT"
LOCAL "${ANDROID_QEMU2_TOP_DIR}/LICENSES/LICENSE.LLVM")
else()
android_license(TARGET "RUNTIME_OS_DEPENDENCIES" LIBNAME None SPDX None
LICENSE None LOCAL None)
endif()
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
add_definitions("-DANDROID_DEBUG")
if(NOT WINDOWS_MSVC_X86_64)
add_c_flag("-O0 -g3")
else()
add_c_flag("-Zi -Od")
endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND NOT CROSSCOMPILE)
if(NOT OPTION_ASAN AND OPTION_ASAN_IN_DEBUG)
set(OPTION_ASAN address)
endif()
if(OPTION_ASAN STREQUAL "thread" AND OPTION_COVERAGE_IN_DEBUG)
message(FATAL_ERROR "You cannot run tsan with code coverage enabled.")
endif()
if(NOT WINDOWS_MSVC_X86_64 AND OPTION_COVERAGE_IN_DEBUG)
message("Enabling code coverage")
# Build an instrumented version of the code that generates coverage
# mapping to enable code coverage analysis
set(ANDROID_CODE_COVERAGE TRUE)
add_c_flag("-fcoverage-mapping")
add_c_flag("-fprofile-instr-generate")
add_c_flag("-fprofile-arcs")
add_c_flag("-ftest-coverage")
add_c_flag("--coverage")
endif()
endif()
else()
set(CMAKE_INSTALL_DO_STRIP TRUE)
add_definitions("-DNDEBUG=1")
if(WINDOWS_MSVC_X86_64)
# clang-cl takes msvc based parameters, so -O3 is a nop
add_c_flag("-O2")
else()
add_c_flag("-O3 -g3")
endif()
endif()
# Target specific configurations that we do not want to do in the
# toolchain.cmake Toolchain variables seem to be overwritten pending your cmake
# version.
if(LINUX_X86_64)
add_c_flag("-Werror")
add_c_flag("-Wno-deprecated-declarations") # Protobuf generates deprecation
# warnings for deprecated enums
# And the asm type if we are compiling with yasm
set(ANDROID_NASM_TYPE elf64)
# This should make sure we have sufficient information left to properly print
# std::string etc. see b/156534499 for details.
add_c_flag("-fno-limit-debug-info")
elseif(LINUX_AARCH64)
set(ANDROID_NASM_TYPE elf64)
add_c_flag("-fpermissive")
elseif(WINDOWS_MSVC_X86_64)
# And the asm type if we are compiling with yasm
set(ANDROID_NASM_TYPE win64)
set(CMAKE_SHARED_LIBRARY_PREFIX "lib")
elseif(DARWIN_X86_64 OR DARWIN_AARCH64)
# And the asm type if we are compiling with yasm
set(ANDROID_NASM_TYPE macho64)
# Always consider the source to be darwin.
add_definitions(-D_DARWIN_C_SOURCE=1)
add_c_flag("-Wno-everything")
else()
message(FATAL_ERROR "Unknown target!")
endif()
# Note that clang in windows act as a drop in replacement for cl
if(NOT WINDOWS_MSVC_X86_64 AND CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
add_definitions("-D__STDC_CONSTANT_MACROS" "-D_LIBCPP_VERSION=__GLIBCPP__")
# If macro expansion goes wrong, we like to see why
add_c_flag("-fmacro-backtrace-limit=0")
# Let's not trip over warnings & errors that do not exist on every platform
# clang-cl != clang-lin != clang-darwin
add_c_flag("-Wno-unknown-warning-option")
add_c_flag("-Wno-unknown-argument")
# grpc does some magic.
add_c_flag("-Wno-non-c-typedef-for-linkage")
endif()
if(DARWIN_X86_64)
add_c_flag("-Werror")
endif()
if(WINDOWS_MSVC_X86_64)
add_c_flag("-MD")
# b/141774858 to track turning them back on again.
add_c_flag("-Wno-everything")
add_definitions("-D_NO_EXCEPTIONS")
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
# Disable security checks, "we know what we are doing"
add_c_flag("-GS-")
add_c_flag("-GR")
endif()
add_c_flag("-w")
endif()
# Copy the source properties and add the build number to it, this will enable
# external tools to easily operate on version id.
set(SOURCE_PROP_DEST ${CMAKE_BINARY_DIR}/source.properties)
file(COPY ${ANDROID_QEMU2_TOP_DIR}/source.properties
DESTINATION ${CMAKE_BINARY_DIR})
file(APPEND ${SOURCE_PROP_DEST} "Pkg.BuildId=${OPTION_SDK_TOOLS_BUILD_NUMBER}")
install(FILES ${SOURCE_PROP_DEST} DESTINATION . RENAME source.properties)
if(OPTION_CLANG_TIDY)
set(DO_FIX "")
if(OPTION_CLANG_TIDY_FIX)
set(DO_FIX "--fix")
endif()
# Workaround to ignore generated code.
file(WRITE "${PROJECT_BINARY_DIR}/.clang-tidy"
"Checks: '-*,android-cloexec-accept'")
set(DO_CLANG_TIDY "${CLANG_TIDY_EXE}" "${DO_FIX}")
endif()
if(OPTION_CLANG_THREAD_SAFETY_CHECKS)
set(ENABLE_CLANG_THREAD_SAFETY_CHECKS ON)
add_definitions("-D_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS")
endif()
if(NOT WINDOWS_MSVC_X86_64)
add_c_flag("-g")
endif()
# Compiling with -fno-exceptions disables exceptions support and uses the
# variant of C++ libraries without exceptions. Use of try, catch, or throw
# results in an error message. Linking objects that have been compiled with
# -fno- exceptions automatically selects the libraries without exceptions. You
# can use the linker option --no_exceptions to diagnose whether the objects
# being linked contain exceptions. If an exception propagates into a function
# that has been compiled without exceptions support, then the program
# terminates.
if(NOT WINDOWS_MSVC_X86_64)
add_cxx_flag("-fno-exceptions")
endif()
add_cxx_flag("-Wno-invalid-offsetof")
add_cxx_flag("-Wno-implicit-int-float-conversion")
# Ensure that <inttypes.h> always defines all interesting macros.
add_definitions("-D__STDC_LIMIT_MACROS=1" "-D__STDC_FORMAT_MACROS=1")
# (From https://stackoverflow.com/questions/5582211/what-does-define-gnu-source-
# imply) with GNU_SOURCE, you will get:
#
# * access to lots of nonstandard GNU/Linux extension functions
# * access to traditional functions which were omitted from the POSIX standard
# (often for good reason, such as being replaced with better alternatives, or
# being tied to particular legacy implementations)
# * access to low-level functions that cannot be portable, but that you
# sometimes need for implementing system utilities like mount, ifconfig, etc.
# broken behavior for lots of POSIX-specified functions, where the GNU folks
# disagreed with the standards committee on how the functions should behave
# and decided to do their own thing. As long as you're aware of these things,
# it should not be a problem to define _GNU_SOURCE, but you should avoid
# defining it and instead define _POSIX_C_SOURCE=200809L or _XOPEN_SOURCE=700
# when possible to ensure that your programs are portable.
add_definitions("-D_GNU_SOURCE=1")
# Enable large-file support (i.e. make off_t a 64-bit value).
add_definitions("-D_FILE_OFFSET_BITS=64" "-D_LARGEFILE_SOURCE")
if(OPTION_ASAN AND (LINUX_X86_64 OR DARWIN))
message(STATUS "Enabling ASAN with: ${OPTION_ASAN}")
add_c_flag("-fsanitize=${OPTION_ASAN}")
add_c_flag("-g3")
add_c_flag("-fno-omit-frame-pointer")
if(OPTION_ASAN STREQUAL "address")
# Adds fiber annotations to qemu (coroutine-ucontext.c)
add_definitions("-DCONFIG_ASAN_IFACE_FIBER")
add_c_flag("-mllvm -asan-use-private-alias=1")
endif()
if(OPTION_ASAN STREQUAL "memory")
add_c_flag("-fsanitize-recover=memory")
endif()
if(OPTION_ASAN STREQUAL "undefined")
add_c_flag("-fno-sanitize=vptr,function,alignment")
endif()
endif()
# Toolchain file can get loaded multiple times, resulting in this variable being
# overwritten on native windows.
if(MSVC AND WINDOWS_MSVC_X86_64)
set(CMAKE_SHARED_LIBRARY_PREFIX "lib")
endif()
# We now have configured our base compiler.
# Unit tests please!
enable_testing()
# TODO(jansene): Make these prebuilts. Files on which the emulator (and some
# unit tests dependes). If a target takes a prebuilt_dependency on these, then
# they will be binplaced in ${EXECUTABLE_DIRECTORY}/lib/...
set(EMULATOR_FEATURE_DEPENDENCIES
"${ANDROID_QEMU2_TOP_DIR}/android/data/advancedFeatures.ini>lib/advancedFeatures.ini"
"${ANDROID_QEMU2_TOP_DIR}/android/data/emu-original-feature-flags.protobuf>lib/emu-original-feature-flags.protobuf"
"${ANDROID_QEMU2_TOP_DIR}/android/data/hostapd.conf>lib/hostapd.conf")
if(BUILDING_FOR_AARCH64)
set(ANDROID_TARGET_ARCH "aarch64")
else()
set(ANDROID_TARGET_ARCH "x86_64")
endif()
set(SWIFTSHADER_DEPENDENCIES
"${ANDROID_QEMU2_TOP_DIR}/../../prebuilts/android-emulator-build/common/swiftshader/${ANDROID_TARGET_OS_FLAVOR}-${ANDROID_TARGET_ARCH}/lib/libEGL${CMAKE_SHARED_LIBRARY_SUFFIX}>lib64/gles_swiftshader/libEGL${CMAKE_SHARED_LIBRARY_SUFFIX}"
"${ANDROID_QEMU2_TOP_DIR}/../../prebuilts/android-emulator-build/common/swiftshader/${ANDROID_TARGET_OS_FLAVOR}-${ANDROID_TARGET_ARCH}/lib/libGLES_CM${CMAKE_SHARED_LIBRARY_SUFFIX}>lib64/gles_swiftshader/libGLES_CM${CMAKE_SHARED_LIBRARY_SUFFIX}"
"${ANDROID_QEMU2_TOP_DIR}/../../prebuilts/android-emulator-build/common/swiftshader/${ANDROID_TARGET_OS_FLAVOR}-${ANDROID_TARGET_ARCH}/lib/libGLESv2${CMAKE_SHARED_LIBRARY_SUFFIX}>lib64/gles_swiftshader/libGLESv2${CMAKE_SHARED_LIBRARY_SUFFIX}"
)
android_license(
TARGET SWIFTSHADER_DEPENDENCIES
LIBNAME swiftshader
EXECUTABLES
"gles_swiftshader/libEGL${CMAKE_SHARED_LIBRARY_SUFFIX}"
"gles_swiftshader/libGLES_CM${CMAKE_SHARED_LIBRARY_SUFFIX}"
"gles_swiftshader/libGLESv2${CMAKE_SHARED_LIBRARY_SUFFIX}"
URL "https://android.googlesource.com/platform/external/swiftshader/+/refs/heads/emu-master-dev"
SPDX "Apache-2.0"
LICENSE
"https://android.googlesource.com/platform/external/swiftshader/+/refs/heads/emu-master-dev/LICENSE.txt"
LOCAL "${ANDROID_QEMU2_TOP_DIR}/LICENSES/LICENSE.APACHE2")
if(NOT LINUX_AARCH64)
# Angle shader translator (and possibly also vk renderer) dependencies
set(ANGLE_DEPENDENCIES
"${ANDROID_QEMU2_TOP_DIR}/../../prebuilts/android-emulator-build/common/ANGLE/${ANDROID_TARGET_OS_FLAVOR}-${ANDROID_TARGET_ARCH}/lib/libshadertranslator${CMAKE_SHARED_LIBRARY_SUFFIX}>lib64/libshadertranslator${CMAKE_SHARED_LIBRARY_SUFFIX}"
)
android_license(
TARGET ANGLE_DEPENDENCIES
LIBNAME angle
EXECUTABLES "libshadertranslator${CMAKE_SHARED_LIBRARY_SUFFIX}"
URL "https://chromium.googlesource.com/angle/angle"
SPDX "BSD-3-Clause"
LICENSE "https://chromium.googlesource.com/angle/angle/LICENSE"
LOCAL "${ANDROID_QEMU2_TOP_DIR}/LICENSES/LICENSE.ANGLE")
endif()
if(WINDOWS_MSVC_X86_64)
set(ANGLE_RENDERER_DEPENDENCIES
"${ANDROID_QEMU2_TOP_DIR}/../../prebuilts/android-emulator-build/common/ANGLE/${ANDROID_TARGET_OS_FLAVOR}-${ANDROID_TARGET_ARCH}/lib/libEGL${CMAKE_SHARED_LIBRARY_SUFFIX}>lib64/gles_angle/libEGL${CMAKE_SHARED_LIBRARY_SUFFIX}"
"${ANDROID_QEMU2_TOP_DIR}/../../prebuilts/android-emulator-build/common/ANGLE/${ANDROID_TARGET_OS_FLAVOR}-${ANDROID_TARGET_ARCH}/lib/libGLESv2${CMAKE_SHARED_LIBRARY_SUFFIX}>lib64/gles_angle/libGLESv2${CMAKE_SHARED_LIBRARY_SUFFIX}"
"${ANDROID_QEMU2_TOP_DIR}/../../prebuilts/android-emulator-build/common/ANGLE/windows-x86_64/lib/d3dcompiler_47${CMAKE_SHARED_LIBRARY_SUFFIX}>lib64/gles_angle/d3dcompiler_47${CMAKE_SHARED_LIBRARY_SUFFIX}"
"${ANDROID_QEMU2_TOP_DIR}/../../prebuilts/android-emulator-build/common/ANGLE/windows-x86_64/lib/vk_swiftshader${CMAKE_SHARED_LIBRARY_SUFFIX}>lib64/gles_angle/vk_swiftshader${CMAKE_SHARED_LIBRARY_SUFFIX}"
"${ANDROID_QEMU2_TOP_DIR}/../../prebuilts/android-emulator-build/common/ANGLE/windows-x86_64/lib/vk_swiftshader_icd.json>lib64/gles_angle/vk_swiftshader_icd.json"
"${ANDROID_QEMU2_TOP_DIR}/../../prebuilts/android-emulator-build/common/ANGLE/windows-x86_64/lib/vulkan-1${CMAKE_SHARED_LIBRARY_SUFFIX}>lib64/gles_angle/vulkan-1${CMAKE_SHARED_LIBRARY_SUFFIX}"
)
# Angle executables licensing information.
android_license(
TARGET ANGLE_RENDERER_DEPENDENCIES
LIBNAME angle-renderer
EXECUTABLES
"gles_angle/libEGL${CMAKE_SHARED_LIBRARY_SUFFIX}"
"gles_angle/libGLESv2${CMAKE_SHARED_LIBRARY_SUFFIX}"
"gles_angle/d3dcompiler_47${CMAKE_SHARED_LIBRARY_SUFFIX}"
"gles_angle/vk_swiftshader${CMAKE_SHARED_LIBRARY_SUFFIX}"
"gles_angle/vulkan-1${CMAKE_SHARED_LIBRARY_SUFFIX}"
URL "https://chromium.googlesource.com/angle/angle"
SPDX "BSD-3-Clause"
LICENSE "https://chromium.googlesource.com/angle/angle/LICENSE"
LOCAL "${ANDROID_QEMU2_TOP_DIR}/LICENSES/LICENSE.ANGLE")
endif()
# On Linux, it loads libvulkan.so.
if(LINUX_X86_64)
set(ANGLE_RENDERER_DEPENDENCIES
"${ANDROID_QEMU2_TOP_DIR}/../../prebuilts/android-emulator-build/common/ANGLE/${ANDROID_TARGET_OS_FLAVOR}-${ANDROID_TARGET_ARCH}/lib/libEGL${CMAKE_SHARED_LIBRARY_SUFFIX}>lib64/gles_angle/libEGL${CMAKE_SHARED_LIBRARY_SUFFIX}"
"${ANDROID_QEMU2_TOP_DIR}/../../prebuilts/android-emulator-build/common/ANGLE/${ANDROID_TARGET_OS_FLAVOR}-${ANDROID_TARGET_ARCH}/lib/libGLESv2${CMAKE_SHARED_LIBRARY_SUFFIX}>lib64/gles_angle/libGLESv2${CMAKE_SHARED_LIBRARY_SUFFIX}"
"${ANDROID_QEMU2_TOP_DIR}/../../prebuilts/android-emulator-build/common/ANGLE/${ANDROID_TARGET_OS_FLAVOR}-${ANDROID_TARGET_ARCH}/lib/libvk_swiftshader${CMAKE_SHARED_LIBRARY_SUFFIX}>lib64/gles_angle/libvk_swiftshader${CMAKE_SHARED_LIBRARY_SUFFIX}"
"${ANDROID_QEMU2_TOP_DIR}/../../prebuilts/android-emulator-build/common/ANGLE/${ANDROID_TARGET_OS_FLAVOR}-${ANDROID_TARGET_ARCH}/lib/vk_swiftshader_icd.json>lib64/gles_angle/vk_swiftshader_icd.json"
"${ANDROID_QEMU2_TOP_DIR}/../../prebuilts/android-emulator-build/common/vulkan/${ANDROID_TARGET_OS_FLAVOR}-${ANDROID_TARGET_ARCH}/libvulkan${CMAKE_SHARED_LIBRARY_SUFFIX}>lib64/gles_angle/libvulkan${CMAKE_SHARED_LIBRARY_SUFFIX}"
"${ANDROID_QEMU2_TOP_DIR}/../../prebuilts/android-emulator-build/common/vulkan/${ANDROID_TARGET_OS_FLAVOR}-${ANDROID_TARGET_ARCH}/libvulkan${CMAKE_SHARED_LIBRARY_SUFFIX}>lib64/gles_angle/libvulkan.so.1"
)
# Angle executables licensing information.
android_license(
TARGET ANGLE_RENDERER_DEPENDENCIES
LIBNAME angle-renderer
EXECUTABLES
"gles_angle/libEGL${CMAKE_SHARED_LIBRARY_SUFFIX}"
"gles_angle/libGLESv2${CMAKE_SHARED_LIBRARY_SUFFIX}"
URL "https://chromium.googlesource.com/angle/angle"
SPDX "BSD-3-Clause"
LICENSE "https://chromium.googlesource.com/angle/angle/LICENSE"
LOCAL "${ANDROID_QEMU2_TOP_DIR}/LICENSES/LICENSE.ANGLE")
endif()
if(DARWIN_X86_64 OR DARWIN_AARCH64)
# On Mac, ANGLE directly read the ICD file and find the Vulkan library (libvk_swiftshader).
set(ANGLE_RENDERER_DEPENDENCIES
"${ANDROID_QEMU2_TOP_DIR}/../../prebuilts/android-emulator-build/common/ANGLE/${ANDROID_TARGET_OS_FLAVOR}-${ANDROID_TARGET_ARCH}/lib/libEGL${CMAKE_SHARED_LIBRARY_SUFFIX}>lib64/gles_angle/libEGL${CMAKE_SHARED_LIBRARY_SUFFIX}"
"${ANDROID_QEMU2_TOP_DIR}/../../prebuilts/android-emulator-build/common/ANGLE/${ANDROID_TARGET_OS_FLAVOR}-${ANDROID_TARGET_ARCH}/lib/libGLESv2${CMAKE_SHARED_LIBRARY_SUFFIX}>lib64/gles_angle/libGLESv2${CMAKE_SHARED_LIBRARY_SUFFIX}"
"${ANDROID_QEMU2_TOP_DIR}/../../prebuilts/android-emulator-build/common/ANGLE/${ANDROID_TARGET_OS_FLAVOR}-${ANDROID_TARGET_ARCH}/lib/libvk_swiftshader${CMAKE_SHARED_LIBRARY_SUFFIX}>lib64/gles_angle/libvk_swiftshader${CMAKE_SHARED_LIBRARY_SUFFIX}"
"${ANDROID_QEMU2_TOP_DIR}/../../prebuilts/android-emulator-build/common/ANGLE/${ANDROID_TARGET_OS_FLAVOR}-${ANDROID_TARGET_ARCH}/lib/libswiftshader_libEGL${CMAKE_SHARED_LIBRARY_SUFFIX}>lib64/gles_angle/libswiftshader_libEGL${CMAKE_SHARED_LIBRARY_SUFFIX}"
"${ANDROID_QEMU2_TOP_DIR}/../../prebuilts/android-emulator-build/common/ANGLE/${ANDROID_TARGET_OS_FLAVOR}-${ANDROID_TARGET_ARCH}/lib/libswiftshader_libGLESv2${CMAKE_SHARED_LIBRARY_SUFFIX}>lib64/gles_angle/libswiftshader_libGLESv2${CMAKE_SHARED_LIBRARY_SUFFIX}"
"${ANDROID_QEMU2_TOP_DIR}/../../prebuilts/android-emulator-build/common/ANGLE/${ANDROID_TARGET_OS_FLAVOR}-${ANDROID_TARGET_ARCH}/lib/vk_swiftshader_icd.json>lib64/gles_angle/vk_swiftshader_icd.json"
)
# Angle executables licensing information.
android_license(
TARGET ANGLE_RENDERER_DEPENDENCIES
LIBNAME angle-renderer
EXECUTABLES "gles_angle/libEGL${CMAKE_SHARED_LIBRARY_SUFFIX}"
"gles_angle/libGLESv2${CMAKE_SHARED_LIBRARY_SUFFIX}"
URL "https://chromium.googlesource.com/angle/angle"
SPDX "BSD-3-Clause"
LICENSE "https://chromium.googlesource.com/angle/angle/LICENSE"
LOCAL "${ANDROID_QEMU2_TOP_DIR}/LICENSES/LICENSE.ANGLE")
endif()
prebuilt(PIXMAN)
prebuilt(VIRGLRENDERER)
if(NOT DARWIN_AARCH64)
prebuilt(TCMALLOC)
endif()
# Make sure the standard set of windows libraries are available as targets
if(WINDOWS)
include(emu-windows-libs)
endif()
# Get the versions from git if possible, by default we point to the latest qemu
# merge commit (v2.12.0) if we are unable to fetch it.
set(ANDROID_QEMU_VERSION "v2.12.0-19097-g85fa07f04ef")
get_git_version(ANDROID_QEMU_VERSION)
# Generate the qemu-version header.
configure_file(qemu-version.h.in qemu-version.h @ONLY)
# We need the auto generated header for some components, so let's set the
# ANDROID_HW_CONFIG_H variable to point to the generated header. Those that need
# it can add it to their sources list, and it will be there.
set(HW_PROPERTIES_INI
${ANDROID_QEMU2_TOP_DIR}/android/emu/avd/src/android/avd/hardware-properties.ini
)
android_generate_hw_config()
# Lets set up a qemu dependency that we all can rely on
android_add_interface(
TARGET android-qemu-deps
LICENSE "GPL-2.0-only"
LIBNAME
qemu
URL
"https://android.googlesource.com/platform/external/qemu/+/refs/heads/emu-master-dev"
REPO "${ANDROID_QEMU2_TOP_DIR}"
NOTICE "REPO/LICENSE")
# This defines all the include directories needed to compile the libqemu
# libraries. There should be no need to make additions here.
if(BUILDING_FOR_AARCH64)
set(TCG_ARCH_DIR "tcg/aarch64")
else()
set(TCG_ARCH_DIR "tcg/i386")
endif()
target_include_directories(
android-qemu-deps
INTERFACE
tcg
${TCG_ARCH_DIR}
accel/tcg
include
disas/libvixl
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_BINARY_DIR}
${ANDROID_AUTOGEN}
../../prebuilts/android-emulator-build/qemu-android-deps/${ANDROID_TARGET_TAG}/include
android-qemu2-glue/config/${ANDROID_TARGET_TAG}/)
# These are the rules that every qemu component needs, regardless of the
# platform you are compiling on. Please document any flags you set as not
# everyone is a compiler expert!
target_compile_definitions(
android-qemu-deps
INTERFACE # Enable faster migration code when saving RAM to a snapshot
"-DCONFIG_MIGRATION_RAM_SINGLE_ITERATION" "${TRACE_CONFIG}")
target_compile_definitions(android-qemu-deps INTERFACE # Enable VIRGL
"-DCONFIG_VIRGL")
if (OPTION_GFXSTREAM_BACKEND)
target_compile_definitions(android-qemu-deps INTERFACE # Enable gfxstream stream renderer
"-DCONFIG_STREAM_RENDERER")
endif()
target_compile_options(
android-qemu-deps
INTERFACE "-Werror=implicit-function-declaration" "-Wno-unused-function"
"-Wno-address-of-packed-member" "-Wno-shift-negative-value")
if(NOT WINDOWS_MSVC_X86_64)
target_compile_options(
android-qemu-deps
INTERFACE # Do not allow the compiler to assume the strictest aliasing rules
# applicable to the language being compiled. For C (and C++), this
# activates optimizations based on the type of expressions. In
# particular, an object of one type is assumed never to reside at
# the same address as an object of a different type, unless the
# types are almost the same. Supposedly this can introduce weird
# failures esp. on older gcc versions (MINGW) (See
# http://thiemonagel.de/2010/01/no-strict-aliasing/)
"-fno-strict-aliasing"
# This option instructs the compiler to assume that signed
# arithmetic overflow of addition, subtraction and multiplication
# wraps around using twos-complement representation. This flag
# enables some optimizations and disables others. The options
# -ftrapv and -fwrapv override each other, so using -ftrapv
# -fwrapv on the command-line results in -fwrapv being effective.
# Qemu is using this, so we use it as well. "-fwrapv" The -fno-
# common option specifies that the compiler should instead place
# uninitialized global variables in the data section of the object
# file. This inhibits the merging of tentative definitions by the
# linker so you get a multiple- definition error if the same
# variable is defined in more than one compilation unit. Compiling
# with -fno- common is useful on targets for which it provides
# better performance, or if you wish to verify that the program
# will work on other systems that always treat uninitialized
# variable definitions this way. Remove this and you'll get all
# sorts of fun linker issues.
"-fno-common")
endif()
# Make sure we make our dependent libraries available.
target_link_libraries(android-qemu-deps INTERFACE glib2 PIXMAN::PIXMAN
zlib android-emu-tracing)
target_link_libraries(android-qemu-deps INTERFACE virglrenderer-headers qemu-host-common-headers)
if(LINUX_AARCH64)
message(STATUS "Suprressing all warnings as gcc has too many too count.")
add_c_flag("-w")
endif()
# Now we add the normal android libs, so we can use them
add_subdirectory(android)
add_subdirectory(android-qemu2-glue)
set(ANDROID_QEMU_ARM_DEVICES
"hw/pci/goldfish_address_space.c;hw/virtio/virtio-vsock.c")
set(ANDROID_QEMU_COMMON_DEVICES "${ANDROID_QEMU_ARM_DEVICES};hw/i386/pc_piix.c")
# Darwin definitions
set(ANDROID_QEMU_i386_DEVICES_darwin-x86_64
"hw/i386/acpi-build.c;${ANDROID_QEMU_COMMON_DEVICES}")
set(ANDROID_QEMU_arm_DEVICES_darwin-x86_64
"accel/stubs/hax-stub.c;${ANDROID_QEMU_ARM_DEVICES}")
# TODO: unstub the hvf for darwin on arm
set(ANDROID_QEMU_arm_DEVICES_darwin-aarch64
"accel/stubs/hax-stub.c;${ANDROID_QEMU_ARM_DEVICES}")
target_compile_definitions(android-qemu-deps INTERFACE "-DANDROID_IO")
android_target_compile_options(
android-qemu-deps
darwin-x86_64
INTERFACE
# Emit extra code to check for buffer overflows, such as stack smashing
# attacks. This is done by adding a guard variable to functions with
# vulnerable objects. This includes functions that call alloca, and functions
# with buffers larger than 8 bytes. The guards are initialized when a function
# is entered and then checked when the function exits. If a guard check fails,
# an error message is printed and the program exits. Like -fstack-protector
# but includes additional functions to be protected — those that have local
# array definitions, or have references to local frame addresses.
"-fstack-protector-strong"
"-Wno-address-of-packed-member"
"-Wno-format-security"
"-Wno-initializer-overrides"
"-Wno-tautological-compare"
"-Wno-tautological-pointer-compare"
"-Wno-unused-variable"
"-Wno-return-type"
"-Wno-shift-negative-value"
# There are a series of out of bounds issues in hvf.
"-Wno-array-bounds"
"-Wno-format"
"-Wno-implicit-int-float-conversion"
"-Wno-reorder-init-list")
android_target_compile_definitions(android-qemu-deps darwin-x86_64 INTERFACE
"-D_DARWIN_C_SOURCE=1")
android_target_link_libraries(android-qemu-deps darwin-x86_64 INTERFACE
"-framework IOKit" "-framework CoreFoundation")
android_target_link_libraries(android-qemu-deps darwin-aarch64 INTERFACE
"-framework IOKit" "-framework CoreFoundation" "-framework vmnet")
# Windows x86 definitions
set(ANDROID_QEMU_arm_DEVICES_windows_msvc-x86_64
"accel/stubs/hax-stub.c;${ANDROID_QEMU_ARM_DEVICES}")
set(ANDROID_QEMU_i386_DEVICES_windows_msvc-x86_64
"hw/i386/acpi-build.c;${ANDROID_QEMU_COMMON_DEVICES}")
android_target_compile_options(
android-qemu-deps
windows_msvc-x86_64
INTERFACE
"-Wno-sometimes-uninitialized"
"-Wno-return-type"
"-Wno-initializer-overrides"
"-Wno-int-to-void-pointer-cast"
"-Wno-incompatible-pointer-types"
"-Wno-unused-variable"
"-Wno-microsoft-include"
"-Wno-address-of-packed-member"
"-Wno-address-of"
"-Wno-gnu-variable-sized-type-not-at-end"
# "-mms-bitfields" # We are using clang-cl so this is not needed
"-mcx16"
"-Wno-implicit-int-float-conversion"
"-Wno-reorder-init-list")
android_target_compile_definitions(
android-qemu-deps
windows
INTERFACE
"-DWIN32_LEAN_AND_MEAN"
"-DWINVER=0x601"
"-D_WIN32_WINNT=0x601"
"-D__USE_MINGW_ANSI_STDIO=1")
# Linux settings
set(ANDROID_QEMU_i386_DEVICES_linux-x86_64
"accel/stubs/hax-stub.c;hw/i386/acpi-build.c;${ANDROID_QEMU_COMMON_DEVICES}"
)
set(ANDROID_QEMU_arm_DEVICES_linux-x86_64
"accel/stubs/hax-stub.c;${ANDROID_QEMU_ARM_DEVICES}")
set(ANDROID_QEMU_i386_DEVICES_linux-aarch64
"accel/stubs/hax-stub.c;hw/i386/acpi-build.c;${ANDROID_QEMU_COMMON_DEVICES}"
)
set(ANDROID_QEMU_arm_DEVICES_linux-aarch64
"accel/stubs/hax-stub.c;${ANDROID_QEMU_ARM_DEVICES}")
android_target_include_directories(android-qemu-deps linux-x86_64 INTERFACE
linux-headers)
android_target_include_directories(android-qemu-deps linux-aarch64 INTERFACE
linux-headers)
target_include_directories(android-qemu-deps INTERFACE ${ANDROID_AUTOGEN})
android_target_compile_options(
android-qemu-deps
linux-x86_64
INTERFACE
# Emit extra code to check for buffer overflows, such as stack smashing
# attacks. This is done by adding a guard variable to functions with
# vulnerable objects. This includes functions that call alloca, and functions
# with buffers larger than 8 bytes. The guards are initialized when a function
# is entered and then checked when the function exits. If a guard check fails,
# an error message is printed and the program exits. Like -fstack-protector
# but includes additional functions to be protected — those that have local
# array definitions, or have references to local frame addresses.
"-fstack-protector-strong"
"-Wno-address-of-packed-member"
"-Wno-format-security"
"-Wno-initializer-overrides"
"-Wno-tautological-compare"
"-Wno-tautological-pointer-compare"
"-Wno-unused-variable"
"-Wno-implicit-int-float-conversion"
"-Wno-gnu-variable-sized-type-not-at-end"
"-Wno-reorder-init-list")
android_target_link_libraries(android-qemu-deps linux-x86_64 INTERFACE
"${TCMALLOC_LIBRARIES} -lutil")
android_target_link_libraries(android-qemu-deps linux-aarch64 INTERFACE
"${TCMALLOC_LIBRARIES} -lutil")
android_target_link_libraries(android-qemu-deps darwin-x86_64 INTERFACE
"-framework CoreAudio" "-framework AudioToolbox")
android_target_link_libraries(android-qemu-deps darwin-aarch64 INTERFACE
"-framework CoreAudio" "-framework AudioToolbox")
android_target_link_libraries(android-qemu-deps windows_msvc-x86_64 INTERFACE
android-emu-base)
if(LINUX_AARCH64)
set(ASM_DIR_TARGET "${ANDROID_QEMU2_TOP_DIR}/linux-headers/asm-arm64")
else()
set(ASM_DIR_TARGET "${ANDROID_QEMU2_TOP_DIR}/linux-headers/asm-x86")
endif()
set(NEED_RELINK_ASM FALSE)
if(EXISTS ${ANDROID_AUTOGEN}/asm)
# check the link is correct
if(LINUX_AARCH64)
if(EXISTS ${ANDROID_AUTOGEN}/asm/unistd_x32.h)
set(NEED_RELINK_ASM TRUE)
endif()
else()
if(NOT EXISTS ${ANDROID_AUTOGEN}/asm/unistd_x32.h)
set(NEED_RELINK_ASM TRUE)
endif()
endif()
else()
set(NEED_RELINK_ASM TRUE)
endif()
if(NEED_RELINK_ASM)
message("create_symlink ${ASM_DIR_TARGET} ${ANDROID_AUTOGEN}/asm")
execute_process(
COMMAND ${CMAKE_COMMAND} -E create_symlink "${ASM_DIR_TARGET}"
"${ANDROID_AUTOGEN}/asm" WORKING_DIRECTORY ${ANDROID_QEMU2_TOP_DIR})
endif()
include(cmake-main.${ANDROID_TARGET_TAG}.inc)
android_add_library(
TARGET libqemu2-util
LICENSE "GPL-2.0-only"
LIBNAME
qemu
URL
"https://android.googlesource.com/platform/external/qemu/+/refs/heads/emu-master-dev"
REPO "${ANDROID_QEMU2_TOP_DIR}"
NOTICE "REPO/LICENSE"
SRC # cmake-format: sortable
${libqemuutil_generated_sources} ${libqemuutil_sources})
target_link_libraries(libqemu2-util PRIVATE android-qemu-deps fdt)
android_target_link_libraries(libqemu2-util windows
PRIVATE psapi::psapi winmm::winmm dxguid::dxguid)
target_compile_definitions(libqemu2-util PRIVATE "-DPOISON_CONFIG_ANDROID")
# Once we have a newer version of cmake we can generate the object library in a
# platform independent way b/121393952
android_add_library(
TARGET qemu2-common
LICENSE "GPL-2.0-only"
LIBNAME
qemu
URL
"https://android.googlesource.com/platform/external/qemu/+/refs/heads/emu-master-dev"
REPO "${ANDROID_QEMU2_TOP_DIR}"
NOTICE "REPO/LICENSE"
SRC # cmake-format: sortable
${qemu2-shared_generated_sources} ${qemu2-shared_sources})
target_compile_definitions(qemu2-common PRIVATE "-DPOISON_CONFIG_ANDROID")
target_compile_options(qemu2-common PRIVATE "-Wno-string-plus-int"
"-Wno-return-type")
target_link_libraries(qemu2-common PUBLIC android-qemu-deps emulator-libusb
libqemu2-util)
if(NOT OPTION_AEMU_LIBS_ONLY)
# Not allowed to have libraries without source files.
android_add_library(
TARGET headless-paaudio
LICENSE "GPL-2.0-only"
LIBNAME
qemu
URL
"https://android.googlesource.com/platform/external/qemu/+/refs/heads/emu-master-dev"
REPO "${ANDROID_QEMU2_TOP_DIR}"
NOTICE "REPO/LICENSE"
SRC # cmake-format: sortable
audio/paaudio-headless-impl-placeholder.c
LINUX audio/paaudio-headless-impl.c)
if(LINUX_AARCH64)
target_include_directories(
headless-paaudio
PUBLIC
${ANDROID_QEMU2_TOP_DIR}/../../prebuilts/android-emulator-build/qemu-android-deps/linux-aarch64/include
)
endif()
android_add_interface(
TARGET android-qemu-deps-headful
LICENSE "GPL-2.0-only"
LIBNAME
qemu
URL
"https://android.googlesource.com/platform/external/qemu/+/refs/heads/emu-master-dev"
REPO "${ANDROID_QEMU2_TOP_DIR}"
NOTICE "REPO/LICENSE")
android_target_link_libraries(android-qemu-deps-headful linux-x86_64
INTERFACE "-lpulse")
android_add_interface(
TARGET android-qemu-deps-headless
LICENSE "GPL-2.0-only"
LIBNAME
qemu
URL
"https://android.googlesource.com/platform/external/qemu/+/refs/heads/emu-master-dev"
REPO "${ANDROID_QEMU2_TOP_DIR}"
NOTICE "REPO/LICENSE")
android_target_link_libraries(android-qemu-deps-headless linux-x86_64
INTERFACE headless-paaudio)
android_target_link_libraries(android-qemu-deps-headless linux-aarch64
INTERFACE headless-paaudio)
android_add_library(
TARGET libqemustub
LICENSE "GPL-2.0-only"
LIBNAME
qemu
URL
"https://android.googlesource.com/platform/external/qemu/+/refs/heads/emu-master-dev"
REPO "${ANDROID_QEMU2_TOP_DIR}"
NOTICE "REPO/LICENSE"
SRC # cmake-format: sortable
${libqemustub_sources} ${libqemuutil_generated_sources})
target_link_libraries(libqemustub PRIVATE android-qemu-deps)
target_compile_definitions(libqemustub PRIVATE "-DLIBQEMUSTUB")
# Qemu-img
android_add_executable(
TARGET qemu-img INSTALL .
LICENSE GPL-2.0-only
LIBNAME
qemu
URL
"https://android.googlesource.com/platform/external/qemu/+/refs/heads/emu-master-dev"
REPO "${ANDROID_QEMU2_TOP_DIR}"
NOTICE "REPO/LICENSE"
SRC # cmake-format: sortable
${qemu-img_sources} block/qcow2-bitmap.c
LINUX scsi/pr-manager.c)
target_link_libraries(qemu-img PRIVATE libqemu2-util libqemustub
android-qemu-deps android-emu)
# Create the qemu targets.
if(NOT BUILDING_FOR_AARCH64)
android_add_qemu_executable(
x86_64 "${ANDROID_QEMU_i386_DEVICES_${ANDROID_TARGET_TAG}}")
android_add_qemu_headless_executable(
x86_64 "${ANDROID_QEMU_i386_DEVICES_${ANDROID_TARGET_TAG}}")
endif()
android_add_qemu_executable(
aarch64 "${ANDROID_QEMU_arm_DEVICES_${ANDROID_TARGET_TAG}}")
android_add_qemu_headless_executable(
aarch64 "${ANDROID_QEMU_arm_DEVICES_${ANDROID_TARGET_TAG}}")
if(NOT OPTION_MINBUILD)
if(NOT BUILDING_FOR_AARCH64)
android_add_qemu_executable(
i386 "${ANDROID_QEMU_i386_DEVICES_${ANDROID_TARGET_TAG}}")
android_add_qemu_headless_executable(
i386 "${ANDROID_QEMU_i386_DEVICES_${ANDROID_TARGET_TAG}}")
endif()
android_add_qemu_executable(
armel "${ANDROID_QEMU_arm_DEVICES_${ANDROID_TARGET_TAG}}")
android_add_qemu_headless_executable(
armel "${ANDROID_QEMU_arm_DEVICES_${ANDROID_TARGET_TAG}}")
endif()
# The tests currently work on linux x86 only.
if(LINUX_X86_64)
include(qemu-test.cmake)
endif()
endif()
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/target.tag "${ANDROID_TARGET_TAG}")
# Construct licenses for all targets, this should always be the last thing we
# do.
finalize_all_licenses()