Files
MaaAssistantArknights/CMakeLists.txt
Aliothmoon c6f930a60d feat: support native android (#16179)
* feat: add android controller support

* feat: add android compile options and add core static options

* fix: add __ANDROID__ macro for Android platform

* fix: move switch break into macro conditional block

* ci: add Android CMake presets (arm64, x64)

* fix: add missing Android TouchMode handling

* fix: remove unnecessary pre-check in android

* fix: restore unnecessary modifications

* fix: unified use __ANDROID__

* refactor: use interpolate_swipe_with_pause in AndroidController

* feat: add Android crash logcat output and native backtrace

* feat: only copy once from external lib screencap

* feat: add Android JNI AttachThread/DetachThread to working_proc

* fix: break control in switch

* fix: update click interval & swipe interval

* ci: restore Android build job with MaaFramework download

* fix: remove thread attach

* ci: temporarily remove MaaAndroidNativeControlUnit.so

* feat(android-ctrl): SWIPE_WITH_PAUSE 由 InstanceOption DeploymentWithPause 控制

* feat: SWIPE_WITH_PAUSE 默认启用

* feat: add android compile options and add core static options

* feat: use maafw controll unit

* fix: minor adjustments

* refactor: adapt maafw android lib

* fix: remove screencap when connect

* chore: change maafw lib use

* feat: adapt maafw control unit click & click_key

* fix: address critical issues in Android native controller

- Restore InstanceOptionKey::ClientType case in set_instance_option,
  which was accidentally removed and broke client type setting on all platforms
- Enable libMaaAndroidNativeControlUnit.so copy step in CI (was commented out),
  so Android artifacts actually include the required control unit library
- Fail connect() early when screen_resolution is missing or invalid in config,
  preventing silent {0,0} resolution that would break swipe and screencap
- Check touch_down() return value in swipe() and abort on failure

* fix: correct bounds_check off-by-one and extract KEYCODE_ESCAPE constant

- bounds_check used <= which allowed coordinates equal to screen width/height
  (off-screen); use < to match the valid range [0, dimension-1]
- Extract magic number 111 into KEYCODE_ESCAPE constexpr in press_esc()

* fix: avoid heap allocation in noexcept terminate/signal handlers

format_signal_reason was returning std::string and using std::format in
its default branch. Called from noexcept custom_terminate_handler before
the outer try block, any allocation failure would throw std::bad_alloc,
triggering recursive std::terminate and aborting crash reporting.

- Change return type to const char* noexcept, returning string literals
- Replace std::format("Signal {}", sig) with "Unknown Signal" (only the
  four registered signals are ever passed, so this branch is unreachable)
- Change signal_info in custom_terminate_handler from std::string to
  const char*, eliminating all allocations on the pre-try path

* fix: suppress unused-variable warning for signal_reason on non-Android
2026-05-12 22:15:15 +08:00

74 lines
2.3 KiB
CMake

cmake_minimum_required(VERSION 3.28)
project(MAA)
option(BUILD_WPF_GUI "build MaaWpfGui" ${WIN32})
option(BUILD_DEBUG_DEMO "build debug demo" OFF)
option(BUILD_XCFRAMEWORK "build xcframework for macOS app" OFF)
option(BUILD_SMOKE_TEST "build smoke_test" OFF)
option(INSTALL_PYTHON "install python ffi" OFF)
option(INSTALL_RESOURCE "install resource" OFF)
option(INSTALL_FLATTEN "do not use bin lib include directory" ON)
option(WITH_EMULATOR_EXTRAS "build with emulator extras" ${WIN32})
option(WITH_MAC_SCK "build with macOS ScreenCaptureKit" ${APPLE})
option(WITH_HASH_VERSION "generate version from git hash" OFF)
option(BUILD_RESOURCE_UPDATER "build resource updater tool" OFF)
if(INSTALL_FLATTEN)
set(RPATH_LIBRARY_INSTALL_DIR .)
set(MaaCore_install_flatten_args RUNTIME DESTINATION . LIBRARY DESTINATION . PUBLIC_HEADER DESTINATION .)
endif()
include(src/MaaUtils/MaaUtils.cmake)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake/modules")
include(${PROJECT_SOURCE_DIR}/cmake/config.cmake)
include(${PROJECT_SOURCE_DIR}/cmake/utils.cmake)
if(APPLE)
include(${PROJECT_SOURCE_DIR}/cmake/macos.cmake)
endif()
add_library(HeaderOnlyLibraries INTERFACE)
target_include_directories(HeaderOnlyLibraries INTERFACE 3rdparty/include)
add_subdirectory(src/MaaCore)
if(BUILD_WPF_GUI)
add_subdirectory(src/MaaUpdater)
include_external_msproject(MaaWpfGui ${PROJECT_SOURCE_DIR}/src/MaaWpfGui/MaaWpfGui.csproj)
add_dependencies(MaaWpfGui MaaCore)
add_dependencies(MaaWpfGui MAA.Updater)
if(DEFINED ENV{VSCODE_PID})
add_custom_target(run-MaaWpfGui
COMMAND "${CMAKE_BINARY_DIR}/bin/$<CONFIG>/MAA.exe"
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/bin/$<CONFIG>"
)
add_dependencies(run-MaaWpfGui MaaCore MaaWpfGui)
endif()
endif()
if (ANDROID)
add_library(stdc++fs INTERFACE)
add_compile_options(-Wno-unused-parameter)
add_compile_options(-ffunction-sections -fdata-sections)
add_link_options(-Wl,--gc-sections)
endif()
if(INSTALL_PYTHON)
install(DIRECTORY src/Python DESTINATION .)
endif()
if(INSTALL_RESOURCE)
install(DIRECTORY resource DESTINATION .)
endif()
if(BUILD_DEBUG_DEMO OR BUILD_SMOKE_TEST)
add_subdirectory(src/Cpp)
endif()
if(BUILD_RESOURCE_UPDATER)
add_subdirectory(tools/ResourceUpdater)
endif()