cmake_minimum_required(VERSION 3.16)
project(nostr-id-tui C)

set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS OFF)

find_package(Curses REQUIRED)

option(NOSTR_TUI_FORCE_STATIC "Link nostr-id-tui as fully static binary" OFF)

set(NOSTR_CORE_LIB_DIR "${CMAKE_SOURCE_DIR}/../../includes/nostr_core_lib" CACHE PATH "Path to nostr_core_lib directory")
set(NOSTR_CORE_STATIC_LIB "${NOSTR_CORE_LIB_DIR}/libnostr_core_x64.a" CACHE FILEPATH "Path to libnostr_core static archive")

if(NOT EXISTS "${NOSTR_CORE_STATIC_LIB}")
    message(FATAL_ERROR "Missing ${NOSTR_CORE_STATIC_LIB}. Build it first with: cd includes/nostr_core_lib && ./build.sh x64")
endif()

add_executable(nostr-id-tui
    src/main.c
    src/services_conf.c
    src/systemd_client.c
)

target_include_directories(nostr-id-tui PRIVATE
    include
    ${NOSTR_CORE_LIB_DIR}
    ${NOSTR_CORE_LIB_DIR}/nostr_core
)

target_compile_options(nostr-id-tui PRIVATE -Wall -Wextra -Wpedantic)

target_link_libraries(nostr-id-tui PRIVATE
    ${NOSTR_CORE_STATIC_LIB}
    ${CURSES_LIBRARIES}
    secp256k1
    ssl
    crypto
    curl
    z
    pthread
    m
    dl
)

if(NOSTR_TUI_FORCE_STATIC)
    target_link_options(nostr-id-tui PRIVATE -static)
endif()
