cmake_minimum_required(VERSION 3.20)

project(linuxSmartie
    VERSION 1.0
    LANGUAGES C
)

# Use C23
set(CMAKE_C_STANDARD 23)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS ON)

# Collect sources
file(GLOB SOURCES
    src/*.c
)

# Define executable
add_executable(linuxSmartie ${SOURCES})

# Include directories
target_include_directories(linuxSmartie
    PRIVATE
        ${CMAKE_CURRENT_SOURCE_DIR}/include
)

# Compiler warnings
target_compile_options(linuxSmartie
        PRIVATE
        -O2
        -Wall
        -Wextra
        -Werror
        -Wshadow
        -Wformat=2          # replaces what -Wpedantic caught for printf
        -Wformat-security
        -fdiagnostics-color=always
)

find_package(libwebsockets QUIET)
find_package(ZLIB QUIET)

if(libwebsockets_FOUND)
    target_link_libraries(linuxSmartie PRIVATE websockets)
    target_compile_definitions(linuxSmartie PRIVATE ENABLE_HOME_ASSISTANT)
else()
    message(STATUS "no libwebsockets found, disabling hass")
endif()

if(ZLIB_FOUND)
    target_link_libraries(linuxSmartie PRIVATE ZLIB::ZLIB)
    target_compile_definitions(linuxSmartie PRIVATE ENABLE_ZLIB)
else()
    message(STATUS "no zlib found, disabling saving logs to gz")
endif()
