cmake_minimum_required(VERSION 3.22)
project(logbookd C)

set(CMAKE_C_STANDARD 17)

find_package(PkgConfig REQUIRED)

add_executable(logbookd main.c bytemess.h shared.h shared.c parser.c parser.h)
add_executable(logread logread.c bytemess.h shared.h shared.c)

find_package(SQLite3)
if (SQLITE3_FOUND)
    include_directories(${SQLITE3_INCLUDE_DIRS})
    target_link_libraries(logbookd sqlite3 uuid systemd)
endif (SQLITE3_FOUND)

add_compile_definitions(WITH_SOCKET_ACTIVATION)
add_compile_definitions(WITH_FD_ACTIVATION)
add_compile_definitions(LOGREAD_SOCKET="/tmp/test/socket/logread")

pkg_check_modules(THEFT libtheft)
include_directories(${THEFT_INCLUDE_DIRS})

enable_testing()
add_executable(test_parser test_parser.c greatest.h parser.c parser.h)

if (THEFT_FOUND)
    add_executable(test_fuzz test_fuzz.c greatest.h parser.c parser.h)
    target_link_libraries(test_fuzz theft)
endif ()