修改CMakeLists.txt解决 Vscode 编译错误

This commit is contained in:
Tian jianyong 2025-02-06 11:17:03 +08:00
parent 48fbf28761
commit 81fcd1f438
2 changed files with 23 additions and 9 deletions

View File

@ -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
)

View File

@ -1,6 +1,5 @@
#include "vehicle/ControllableVehicles.h"
#include "ControllableVehicles.h"
#include "utils/Logger.h"
#include "nlohmann/json.hpp"
#include <fstream>
#include <stdexcept>