120 lines
2.9 KiB
CMake
120 lines
2.9 KiB
CMake
cmake_minimum_required(VERSION 3.16)
|
|
project(EdgeProxy LANGUAGES CXX)
|
|
|
|
set(CMAKE_CXX_STANDARD 17)
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
|
|
# --- 查找并链接 spdlog ---
|
|
find_package(spdlog REQUIRED)
|
|
find_package(Boost REQUIRED COMPONENTS system thread)
|
|
message(STATUS "Found Boost version: ${Boost_VERSION}")
|
|
find_package(PahoMqttCpp REQUIRED)
|
|
|
|
|
|
add_library(nlohmann_json INTERFACE)
|
|
target_include_directories(nlohmann_json INTERFACE
|
|
${CMAKE_CURRENT_SOURCE_DIR}/src/vendor
|
|
)
|
|
|
|
|
|
|
|
|
|
add_library(edge_proxy_lib STATIC
|
|
# Add the refactored network and protocol files
|
|
src/network/tcp_server.cc
|
|
src/protocol/protocol.cc
|
|
src/protocol/protocol_handler.cc
|
|
|
|
# 小工具
|
|
src/utils/mqtt_topic_matcher.cpp
|
|
|
|
# --- MQTT 核心模块 ---
|
|
src/mqtt/mqtt_client.cpp
|
|
src/mqtt/mqtt_router.cpp
|
|
src/mqtt/handler/data_handler.cpp
|
|
src/mqtt/handler/command_handler.cpp
|
|
# --- 协议层 ---
|
|
src/protocol/protocol.cc
|
|
src/protocol/protocol_handler.cc
|
|
|
|
# Existing files
|
|
src/SystemMonitor.cc
|
|
)
|
|
|
|
target_include_directories(edge_proxy_lib PUBLIC
|
|
${CMAKE_CURRENT_SOURCE_DIR}/src
|
|
)
|
|
|
|
target_link_libraries(edge_proxy_lib PRIVATE
|
|
spdlog::spdlog
|
|
Boost::system
|
|
Boost::thread
|
|
PahoMqttCpp::paho-mqttpp3
|
|
pthread
|
|
nlohmann_json
|
|
)
|
|
|
|
# =================================================================
|
|
# Main Application Target (UNCOMMENTED AND ACTIVATED)
|
|
# =================================================================
|
|
add_executable(edge_proxy
|
|
src/main.cpp
|
|
)
|
|
|
|
target_link_libraries(edge_proxy PRIVATE
|
|
edge_proxy_lib
|
|
)
|
|
|
|
# =================#================================================
|
|
# 测试目标
|
|
# =================================================================
|
|
add_executable(test
|
|
src/test.cc
|
|
src/jwst20_sensor.cc
|
|
src/modbus_rtu_client.cc
|
|
# src/test-new.cc
|
|
)
|
|
|
|
target_link_libraries(test PRIVATE
|
|
spdlog::spdlog
|
|
Boost::system
|
|
Boost::thread
|
|
)
|
|
|
|
# =================================================================
|
|
# 独立的 MQTT 功能测试目标
|
|
# =================================================================
|
|
# 创建一个新的可执行文件,名为 mqtt_test_runner
|
|
# add_executable(mqtt_test_runner
|
|
# src/mqtt_test.cpp
|
|
# )
|
|
|
|
# target_link_libraries(mqtt_test_runner PRIVATE
|
|
# edge_proxy_lib
|
|
# )
|
|
|
|
# =================================================================
|
|
# gtest
|
|
# =================================================================
|
|
# enable_testing()
|
|
# include(FetchContent)
|
|
# FetchContent_Declare(
|
|
# googletest
|
|
# URL https://github.com/google/googletest/archive/refs/tags/v1.14.0.zip
|
|
# )
|
|
# FetchContent_MakeAvailable(googletest)
|
|
|
|
# add_executable(run_tests
|
|
# tests/mqtt_integration_test.cpp
|
|
# )
|
|
|
|
# target_link_libraries(run_tests PRIVATE
|
|
# GTest::gtest_main
|
|
# PahoMqttCpp::paho-mqttpp3
|
|
# pthread
|
|
# )
|
|
|
|
# include(GoogleTest)
|
|
# gtest_discover_tests(run_tests)
|
|
|