101 lines
2.5 KiB
CMake
101 lines
2.5 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
|
|
src/tcp_server.cc
|
|
src/SystemMonitor.cc
|
|
src/mqtt_client.cpp
|
|
src/mqtt_router.cpp
|
|
)
|
|
|
|
target_link_libraries(edge_proxy_lib PRIVATE
|
|
spdlog::spdlog
|
|
Boost::system
|
|
Boost::thread
|
|
PahoMqttCpp::paho-mqttpp3
|
|
pthread
|
|
nlohmann_json
|
|
)
|
|
|
|
# =================================================================
|
|
# 主应用目标
|
|
# =================================================================
|
|
# add_executable(edge_proxy
|
|
# src/main.cpp
|
|
# )
|
|
|
|
|
|
# target_link_libraries(edge_proxy PRIVATE
|
|
# edge_proxy_lib
|
|
# )
|
|
|
|
# =================================================================
|
|
# 测试目标
|
|
# =================================================================
|
|
add_executable(test
|
|
src/test.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
|
|
)
|
|
|
|
# 将其链接到我们的核心逻辑库 edge_proxy_lib
|
|
# 注意:我们不需要再单独链接 spdlog, boost, paho 等库了,
|
|
# 因为 edge_proxy_lib 已经包含了所有这些依赖。
|
|
# 这正是我们之前重构为“库模式”带来的巨大好处!
|
|
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)
|
|
|