![zhangyi1357](/assets/img/avatar_default.png)
* build: refactor CMake scripts to use functions for variable scope Wrap multiple CMake scripts in functions to restrict variable scope and prevent unintended resets. This ensures better modularity and maintainability in the build process while adhering to modern CMake best practices. * refactor: simplify opentelemetry fetch logic Streamline the handling of OpenTelemetry dependencies by removing unnecessary function wrappers and directly implementing the fetching logic. This improves readability and maintainability while ensuring that relevant variables are correctly set within the proper scope. * refactor: encapsulate OpenTelemetry configuration in a function Wrap the OpenTelemetry setup in a function to limit variable scope, improving code organization and maintainability.
49 lines
983 B
CMake
49 lines
983 B
CMake
# Copyright (c) 2023, AgiBot Inc.
|
|
# All rights reserved.
|
|
|
|
include(FetchContent)
|
|
|
|
message(STATUS "get yaml-cpp ...")
|
|
|
|
set(yaml-cpp_DOWNLOAD_URL
|
|
"https://github.com/jbeder/yaml-cpp/archive/0.8.0.tar.gz"
|
|
CACHE STRING "")
|
|
|
|
if(yaml-cpp_LOCAL_SOURCE)
|
|
FetchContent_Declare(
|
|
yaml-cpp
|
|
SOURCE_DIR ${yaml-cpp_LOCAL_SOURCE}
|
|
OVERRIDE_FIND_PACKAGE)
|
|
else()
|
|
FetchContent_Declare(
|
|
yaml-cpp
|
|
URL ${yaml-cpp_DOWNLOAD_URL}
|
|
DOWNLOAD_EXTRACT_TIMESTAMP TRUE
|
|
OVERRIDE_FIND_PACKAGE)
|
|
endif()
|
|
|
|
# Wrap it in a function to restrict the scope of the variables
|
|
function(get_yaml_cpp)
|
|
FetchContent_GetProperties(yaml-cpp)
|
|
if(NOT yaml-cpp_POPULATED)
|
|
set(BUILD_TESTING OFF)
|
|
|
|
set(YAML_CPP_BUILD_TESTS OFF)
|
|
|
|
set(YAML_CPP_BUILD_TOOLS OFF)
|
|
|
|
set(YAML_CPP_INSTALL ON)
|
|
|
|
set(YAML_CPP_FORMAT_SOURCE OFF)
|
|
|
|
set(YAML_CPP_BUILD_CONTRIB OFF)
|
|
|
|
FetchContent_MakeAvailable(yaml-cpp)
|
|
endif()
|
|
endfunction()
|
|
|
|
get_yaml_cpp()
|
|
|
|
# import targets:
|
|
# yaml-cpp::yaml-cpp
|