From 81fcd1f438f48fd5bb099be06e14decb0b94d8f9 Mon Sep 17 00:00:00 2001 From: Tian jianyong <11429339@qq.com> Date: Thu, 6 Feb 2025 11:17:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9CMakeLists.txt=E8=A7=A3?= =?UTF-8?q?=E5=86=B3=20Vscode=20=E7=BC=96=E8=AF=91=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 29 +++++++++++++++++++++------- src/vehicle/ControllableVehicles.cpp | 3 +-- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c408735..08a9ec2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,6 +13,9 @@ cmake_policy(SET CMP0167 NEW) # 使用新的 Boost 查找机制 # 包含 FetchContent 模块 include(FetchContent) +# 生成 compile_commands.json +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + project(collision_avoidance) set(CMAKE_CXX_STANDARD 17) @@ -53,15 +56,27 @@ find_package(Boost 1.69.0 REQUIRED COMPONENTS system filesystem thread) # 添加 libcurl find_package(CURL REQUIRED) -# 添加 JSON 库 +# 修改 JSON 库配置为双模式 if(APPLE) - # macOS 使用 Homebrew 安装的 nlohmann_json - find_package(nlohmann_json 3.11.3 REQUIRED) + # macOS 使用 FetchContent + FetchContent_Declare( + nlohmann_json + GIT_REPOSITORY https://github.com/nlohmann/json.git + GIT_TAG v3.11.3 + ) + FetchContent_MakeAvailable(nlohmann_json) else() - # CentOS 使用系统安装的 nlohmann_json - find_package(nlohmann_json REQUIRED) + # CentOS 使用系统安装的包 + find_package(nlohmann_json 3.11.3 REQUIRED) + + # 验证系统包路径 + if(NOT TARGET nlohmann_json::nlohmann_json) + message(FATAL_ERROR "系统未安装正确版本的 nlohmann_json") + endif() + + # 添加手动包含路径(适用于旧版CMake) + include_directories(${nlohmann_json_INCLUDE_DIRS}) endif() -set(JSON_TARGET nlohmann_json::nlohmann_json) # 源文件列表 set(LIB_SOURCES @@ -95,7 +110,7 @@ target_include_directories(${PROJECT_NAME}_lib target_link_libraries(${PROJECT_NAME}_lib PUBLIC Boost::system - ${JSON_TARGET} + nlohmann_json::nlohmann_json # 统一目标名称 CURL::libcurl ) diff --git a/src/vehicle/ControllableVehicles.cpp b/src/vehicle/ControllableVehicles.cpp index fe49fa9..f1aef2f 100644 --- a/src/vehicle/ControllableVehicles.cpp +++ b/src/vehicle/ControllableVehicles.cpp @@ -1,6 +1,5 @@ -#include "vehicle/ControllableVehicles.h" +#include "ControllableVehicles.h" #include "utils/Logger.h" -#include "nlohmann/json.hpp" #include #include