cmake_minimum_required(VERSION 3.20)
project(comm_core)

add_library(comm_core SHARED)

target_sources(comm_core
    PRIVATE
        src/controller.cpp
        src/codec.cpp
)

target_include_directories(comm_core
    PUBLIC
        ${CMAKE_CURRENT_SOURCE_DIR}/include
)

target_compile_options(comm_core
    PRIVATE
        -Wall -Wextra -Wpedantic
)

# ─── HC900 Gateway ───

set(GRPC_DIR /tmp/grpc_local)
set(ABSL_DIR /tmp/absl_local)
set(PROTO_GEN_DIR ${CMAKE_CURRENT_SOURCE_DIR}/gen)

add_executable(hc900_gateway)

target_sources(hc900_gateway
    PRIVATE
        src/gateway.cpp
        src/modbus_tcp.cpp
        ${PROTO_GEN_DIR}/modbus_gateway.pb.cc
        ${PROTO_GEN_DIR}/modbus_gateway.grpc.pb.cc
)

target_include_directories(hc900_gateway
    PRIVATE
        ${CMAKE_CURRENT_SOURCE_DIR}/include
        ${PROTO_GEN_DIR}
        ${GRPC_DIR}/usr/include
        ${ABSL_DIR}/usr/include
)

target_link_directories(hc900_gateway
    PRIVATE
        ${GRPC_DIR}/usr/lib/aarch64-linux-gnu
        ${ABSL_DIR}/usr/lib/aarch64-linux-gnu
        /usr/lib/aarch64-linux-gnu
        /lib/aarch64-linux-gnu
)

target_link_libraries(hc900_gateway
    PRIVATE
        comm_core
        grpc++
        grpc
        gpr
        upb
        address_sorting
        protobuf
        absl_synchronization
        absl_status
        absl_cord
        absl_cord_internal
        absl_cordz_info
        absl_cordz_handle
        absl_cordz_functions
        absl_cordz_sample_token
        absl_hashtablez_sampler
        absl_exponential_biased
        absl_raw_hash_set
        absl_hash
        absl_city
        absl_low_level_hash
        absl_int128
        absl_raw_logging_internal
        absl_log_severity
        absl_spinlock_wait
        absl_malloc_internal
        absl_throw_delegate
        absl_time
        absl_time_zone
        absl_strings
        absl_strings_internal
        absl_base
        pthread
        rt
        dl
)

target_compile_options(hc900_gateway
    PRIVATE
        -Wall -Wextra -Wpedantic
)
