cmake_minimum_required(VERSION 3.16)
project(vehicle_agent_windows CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# ---------------------------------------------------------------------------
# nlohmann/json —— 优先查找系统安装，不存在则 FetchContent 自动下载
# ---------------------------------------------------------------------------
find_package(nlohmann_json 3.9 QUIET)
if(NOT nlohmann_json_FOUND)
    message(STATUS "未找到系统 nlohmann/json，使用 FetchContent 下载")
    include(FetchContent)
    FetchContent_Declare(
        nlohmann_json
        GIT_REPOSITORY https://github.com/nlohmann/json.git
        GIT_TAG        v3.11.3
        GIT_SHALLOW    TRUE
    )
    FetchContent_MakeAvailable(nlohmann_json)
endif()

# ---------------------------------------------------------------------------
# 可执行文件
# ---------------------------------------------------------------------------
add_executable(vehicle_agent_windows
    src/main.cpp
    src/chassis_domain_server.cpp
    src/control_domain_server.cpp
)

target_include_directories(vehicle_agent_windows PRIVATE
    ${CMAKE_CURRENT_SOURCE_DIR}/include
)

target_link_libraries(vehicle_agent_windows PRIVATE nlohmann_json::nlohmann_json)

# Windows 需要链接 Winsock
if(WIN32)
    target_link_libraries(vehicle_agent_windows PRIVATE ws2_32)
endif()

# ---------------------------------------------------------------------------
# 编译选项
# ---------------------------------------------------------------------------
if(MSVC)
    target_compile_options(vehicle_agent_windows PRIVATE /W4 /utf-8)
else()
    target_compile_options(vehicle_agent_windows PRIVATE -Wall -Wextra)
endif()
