# sam — the plan9 sam structural-regexp command language engine.
#
# sam_lib is pure (QString in, edits out) and fully unit tested. It needs
# Qt Core for QString/QRegularExpression and Qt Core's QProcess for the shell
# filter commands (< > | !); no GUI dependency.
find_package(Qt6 ${QT_MIN_VERSION} COMPONENTS Core REQUIRED)

add_library(sam_lib STATIC
    samengine.cpp
    samengine.h
    samregex.cpp
    samregex.h
)
target_link_libraries(sam_lib PUBLIC Qt6::Core)
target_include_directories(sam_lib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

find_package(Qt6 ${QT_MIN_VERSION} COMPONENTS Test)
if(Qt6Test_FOUND)
    add_executable(test_samengine test_samengine.cpp)
    target_link_libraries(test_samengine PRIVATE sam_lib Qt6::Test)
    add_test(NAME samengine COMMAND test_samengine)

    add_executable(test_samregex test_samregex.cpp)
    target_link_libraries(test_samregex PRIVATE sam_lib Qt6::Test)
    add_test(NAME samregex COMMAND test_samregex)
endif()

# --- [deft:nineify] sam — the Kate plugin ----------------------------------
# The sam engine (sam_lib) is pure and always built. The plugin layer (tool
# view + active-document glue) needs KF6::TextEditor; build it only when found.
if(KF6TextEditor_FOUND)
    kcoreaddons_add_plugin(deft_sam
        SOURCES samplugin.cpp samplugin.h sampanel.cpp sampanel.h
        INSTALL_NAMESPACE "kf6/ktexteditor"
    )
    target_link_libraries(deft_sam PRIVATE
        sam_lib
        KF6::TextEditor
        KF6::CoreAddons
        KF6::I18n
        Qt6::Widgets
    )
endif()
