# SPDX-License-Identifier: MIT

cmake_minimum_required(VERSION 3.21)
project(KodoTermVendor LANGUAGES C CXX)

find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)

set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(LIBVTERM_SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/../libvterm")

file(GLOB VTERM_SOURCES CONFIGURE_DEPENDS
    "${LIBVTERM_SOURCE_DIR}/src/*.c"
)

add_library(vterm STATIC ${VTERM_SOURCES})
target_include_directories(vterm PUBLIC
    "${LIBVTERM_SOURCE_DIR}/include"
    "${LIBVTERM_SOURCE_DIR}/src"
)

set(KODOTERM_SOURCES
    src/KodoTerm.cpp
    src/KodoTermConfig.cpp
    src/PtyProcess.cpp
    src/PtyProcess.h
    include/KodoTerm/KodoTerm.hpp
    include/KodoTerm/KodoTermConfig.hpp
    KodoTermThemes.qrc
)

if(UNIX)
    list(APPEND KODOTERM_SOURCES
        src/PtyProcess_unix.cpp
        src/PtyProcess_unix.h
    )
elseif(WIN32)
    list(APPEND KODOTERM_SOURCES
        src/PtyProcess_win.cpp
        src/PtyProcess_win.h
    )
endif()

add_library(KodoTerm ${KODOTERM_SOURCES})
add_library(KodoTerm::KodoTerm ALIAS KodoTerm)

target_compile_features(KodoTerm PUBLIC cxx_std_20)

target_include_directories(KodoTerm PRIVATE src)
target_include_directories(KodoTerm PUBLIC
    $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
    $<INSTALL_INTERFACE:include>
)

target_link_libraries(KodoTerm PUBLIC
    Qt6::Core
    Qt6::Gui
    Qt6::Widgets
    vterm
)
