From 29eb541fd66fac1622898f45de6239022de5cc7f Mon Sep 17 00:00:00 2001 From: zhangyi1357 <34409786+zhangyi1357@users.noreply.github.com> Date: Fri, 8 Nov 2024 09:46:05 +0800 Subject: [PATCH] fix: add error handling for local protoc compiler detection (#89) * build: add error handling for local protoc compiler detection Ensure that the local `protoc` compiler is found when `AIMRT_USE_LOCAL_PROTOC_COMPILER` is enabled. This improves setup reliability by providing clear feedback if `protoc` is missing, helping users avoid runtime issues. * build: include YamlCpp for enhanced configuration support Add support for YamlCpp to improve configuration handling alongside ROS2 dependencies. * chore: remove redundant gflag setting Clean up the CMake configuration by removing the unnecessary gflag setting for testing, streamlining the build process. --- CMakeLists.txt | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 35e9ede4d..9c25e51a8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -153,9 +153,15 @@ if(AIMRT_BUILD_WITH_PROTOBUF) include(ProtobufGenCode) if(AIMRT_USE_LOCAL_PROTOC_COMPILER) + find_program(PROTOC_EXECUTABLE protoc) + if(NOT PROTOC_EXECUTABLE) + message(FATAL_ERROR "AIMRT_USE_LOCAL_PROTOC_COMPILER is ON, but can not find protoc compiler, " # + "please install protoc and make it available in your PATH.") + endif() + message(STATUS "Found local protoc compiler: ${PROTOC_EXECUTABLE}") set(Protobuf_PROTOC_EXECUTABLE - "protoc" - CACHE STRING "Path to protoc compiler.") + ${PROTOC_EXECUTABLE} + CACHE STRING "Path to local protoc compiler.") add_executable(aimrt::protoc IMPORTED GLOBAL) set_target_properties(aimrt::protoc PROPERTIES IMPORTED_LOCATION ${Protobuf_PROTOC_EXECUTABLE}) set_property(GLOBAL PROPERTY PROTOC_NAMESPACE_PROPERTY "aimrt") @@ -172,11 +178,8 @@ if(AIMRT_BUILD_WITH_ROS2) cmake_policy(SET CMP0148 OLD) endif() - # fix gflag - set(BUILD_TESTING - OFF - CACHE BOOL "") include(GetJsonCpp) + include(GetYamlCpp) find_package(rclcpp REQUIRED) find_package(Python3 REQUIRED) endif()