修改CMakeLists.txt解决 Vscode 编译错误
This commit is contained in:
parent
48fbf28761
commit
81fcd1f438
@ -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
|
||||
)
|
||||
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
#include "vehicle/ControllableVehicles.h"
|
||||
#include "ControllableVehicles.h"
|
||||
#include "utils/Logger.h"
|
||||
#include "nlohmann/json.hpp"
|
||||
#include <fstream>
|
||||
#include <stdexcept>
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user