cmake_minimum_required(VERSION 3.22.1)
project(pebrel_ghostty LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
get_filename_component(GHOSTTY_ROOT "${CMAKE_CURRENT_LIST_DIR}/../../../build/upstream/${ANDROID_ABI}" ABSOLUTE)
if(NOT EXISTS "${GHOSTTY_ROOT}/lib/libghostty-vt.a")
    message(FATAL_ERROR "Build the pinned terminal core with mobile/tools/build_ghostty.py first")
endif()
add_library(ghostty_vt STATIC IMPORTED)
set_target_properties(ghostty_vt PROPERTIES IMPORTED_LOCATION "${GHOSTTY_ROOT}/lib/libghostty-vt.a")
add_library(pebrel_ghostty SHARED terminal.cpp render.cpp pty.cpp)
target_include_directories(pebrel_ghostty PRIVATE "${GHOSTTY_ROOT}/include")
target_compile_definitions(pebrel_ghostty PRIVATE GHOSTTY_STATIC)
target_compile_options(pebrel_ghostty PRIVATE -Wall -Wextra -Werror -fvisibility=hidden)
target_link_options(pebrel_ghostty PRIVATE -Wl,-z,max-page-size=16384 -Wl,--exclude-libs,ALL)
if(CMAKE_HOST_WIN32 AND CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
    # NDK 的 no-canonical-prefixes 与 Windows 短文件名会丢失 clang++ 的 C++ 驱动身份。
    target_link_options(pebrel_ghostty PRIVATE --driver-mode=g++)
endif()
target_link_libraries(pebrel_ghostty PRIVATE ghostty_vt android log)
