From cba55fcbd965adb81e6a3efe9e02fda3246e5c46 Mon Sep 17 00:00:00 2001 From: Tian jianyong <11429339@qq.com> Date: Fri, 20 Dec 2024 14:01:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=20CMakeLists.txt=20=E5=92=8C?= =?UTF-8?q?=E6=89=93=E5=8C=85=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 26 ++++++++++++++++++-------- assistant_snippet_Wd4Hs2Iqxj.txt | 8 +++++++- scripts/prepare_deploy.sh | 6 +++++- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b7e18e8..a53f47c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,6 +3,9 @@ cmake_minimum_required(VERSION 3.14...3.27) # 设置 CMake 策略 cmake_policy(SET CMP0074 NEW) # 使用 _ROOT 变量 +# 包含 FetchContent 模块 +include(FetchContent) + project(airport_collision_avoidance) set(CMAKE_CXX_STANDARD 17) @@ -34,13 +37,19 @@ find_package(Boost REQUIRED COMPONENTS system filesystem thread) # 添加 libcurl find_package(CURL REQUIRED) -# 添加 nlohmann_json -include(FetchContent) -FetchContent_Declare( - json - URL https://github.com/nlohmann/json/releases/download/v3.11.3/json.tar.xz -) -FetchContent_MakeAvailable(json) +# 添加 JSON 库 +if(APPLE) + # macOS 使用 Homebrew 安装的 nlohmann_json + find_package(nlohmann_json 3.11.3 REQUIRED) + set(JSON_TARGET nlohmann_json::nlohmann_json) +else() + # CentOS 使用系统安装的 json-devel + set(JSON_INCLUDE_DIR "/usr/include/json") + if(NOT EXISTS ${JSON_INCLUDE_DIR}) + message(FATAL_ERROR "json-devel not found. Please install: yum install -y json-devel") + endif() + set(JSON_TARGET "") +endif() # 源文件列表 set(LIB_SOURCES @@ -69,12 +78,13 @@ target_include_directories(${PROJECT_NAME}_lib ${CMAKE_CURRENT_SOURCE_DIR}/src ${Boost_INCLUDE_DIRS} ${CURL_INCLUDE_DIRS} + $<$>:${JSON_INCLUDE_DIR}> # 仅在非 macOS 系统添加 ) target_link_libraries(${PROJECT_NAME}_lib PUBLIC Boost::system - nlohmann_json::nlohmann_json + ${JSON_TARGET} CURL::libcurl ) diff --git a/assistant_snippet_Wd4Hs2Iqxj.txt b/assistant_snippet_Wd4Hs2Iqxj.txt index 181a742..b2abf86 100644 --- a/assistant_snippet_Wd4Hs2Iqxj.txt +++ b/assistant_snippet_Wd4Hs2Iqxj.txt @@ -13,4 +13,10 @@ 13|sudo yum install -y devtoolset-7-gcc devtoolset-7-gcc-c++ 14| 15|# 启用 GCC 7 -16|scl enable devtoolset-7 bash \ No newline at end of file +16|scl enable devtoolset-7 bash +17| +18|# 确保已启用 EPEL 仓库 +19|sudo yum install -y epel-release +20| +21|# 安装 nlohmann-json-devel +22|sudo yum install -y nlohmann-json-devel \ No newline at end of file diff --git a/scripts/prepare_deploy.sh b/scripts/prepare_deploy.sh index a3e2c18..0e12e34 100644 --- a/scripts/prepare_deploy.sh +++ b/scripts/prepare_deploy.sh @@ -48,7 +48,11 @@ fi log_info "Installing build dependencies..." sudo yum groupinstall -y "Development Tools" sudo yum install -y epel-release -sudo yum install -y cmake3 boost-devel openssl-devel nlohmann-json-devel python3-devel libcurl-devel +sudo yum install -y cmake3 boost-devel openssl-devel python3-devel libcurl-devel + +# Install nlohmann-json from EPEL +log_info "Installing nlohmann-json..." +sudo yum install -y nlohmann-json-devel # Install GCC 7 log_info "Installing GCC 7..."