From efde01033b2181c10f2d1b236170c9ab1320b7ec Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Wed, 28 Jun 2023 12:03:34 -0700 Subject: [PATCH] [BUILD] Enable building otel-cpp extensions from main repo (#1937) --- CMakeLists.txt | 2 ++ ...entelemetry-build-external-component.cmake | 30 +++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 cmake/opentelemetry-build-external-component.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 37e0be94a6..27930fe793 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -628,6 +628,8 @@ if(NOT WITH_API_ONLY) endif() endif() +include(cmake/opentelemetry-build-external-component.cmake) + if(OPENTELEMETRY_INSTALL) # Export cmake config and support find_packages(opentelemetry-cpp CONFIG) # Write config file for find_packages(opentelemetry-cpp CONFIG) diff --git a/cmake/opentelemetry-build-external-component.cmake b/cmake/opentelemetry-build-external-component.cmake new file mode 100644 index 0000000000..cd30eb082f --- /dev/null +++ b/cmake/opentelemetry-build-external-component.cmake @@ -0,0 +1,30 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +# Enable building external components through otel-cpp build +# The config options are +# - OPENTELEMETRY_EXTERNAL_COMPONENT_PATH - Setting local path of the external +# component as env variable +# - OPENTELEMETRY_EXTERNAL_COMPONENT_URL Setting github-repo of external component +# as env variable + + +# Add custom vendor component from local path, or GitHub repo +if(DEFINED $ENV{OPENTELEMETRY_EXTERNAL_COMPONENT_PATH}) + # Add custom component path to build tree and consolidate binary artifacts in + # current project binary output directory. + add_subdirectory($ENV{OPENTELEMETRY_EXTERNAL_COMPONENT_PATH} + ${PROJECT_BINARY_DIR}/external) +elseif(DEFINED $ENV{OPENTELEMETRY_EXTERNAL_COMPONENT_URL}) + # This option requires CMake 3.11+: add standard remote repo to build tree. + include(FetchContent) + FetchContent_Declare( + external + GIT_REPOSITORY $ENV{OPENTELEMETRY_EXTERNAL_COMPONENT_URL} + GIT_TAG "main") + FetchContent_GetProperties(external) + if(NOT external_POPULATED) + FetchContent_Populate(external) + add_subdirectory(${external_SOURCE_DIR}) + endif() +endif()