Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUILD] Accept path list in OPENTELEMETRY_EXTERNAL_COMPONENT_PATH #2439

Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions cmake/opentelemetry-build-external-component.cmake
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
# Copyright The OpenTelemetry Authors
# SPDX-License-Identifier: Apache-2.0

function(get_directory_name_in_path PATH_VAR RESULT_VAR)
# get_filename_component does not work with paths ending in / or \, so remove it.
string(REGEX REPLACE "/$" "" PATH_TRIMMED "${PATH_VAR}")
string(REGEX REPLACE "\\$" "" PATH_TRIMMED "${PATH_VAR}")
ThomsonTan marked this conversation as resolved.
Show resolved Hide resolved

get_filename_component(DIR_NAME ${PATH_TRIMMED} NAME)

set(${RESULT_VAR} "${DIR_NAME}" PARENT_SCOPE)
endfunction()

# 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_PATH - Setting local paths of the external
# component as env variable. Multiple paths can be set by separating them with.
# - OPENTELEMETRY_EXTERNAL_COMPONENT_URL Setting github-repo of external component
# as env variable

Expand All @@ -13,13 +23,18 @@
if(OPENTELEMETRY_EXTERNAL_COMPONENT_PATH)
# Add custom component path to build tree and consolidate binary artifacts in
# current project binary output directory.
add_subdirectory(${OPENTELEMETRY_EXTERNAL_COMPONENT_PATH}
${PROJECT_BINARY_DIR}/external)
foreach(DIR IN LISTS OPENTELEMETRY_EXTERNAL_COMPONENT_PATH)
get_directory_name_in_path(${DIR} EXTERNAL_EXPORTER_DIR_NAME)
add_subdirectory(${DIR} ${PROJECT_BINARY_DIR}/external/${EXTERNAL_EXPORTER_DIR_NAME})
ThomsonTan marked this conversation as resolved.
Show resolved Hide resolved
endforeach()
elseif(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)
set(OPENTELEMETRY_EXTERNAL_COMPONENT_PATH_VAR $ENV{OPENTELEMETRY_EXTERNAL_COMPONENT_PATH})
foreach(DIR IN LISTS OPENTELEMETRY_EXTERNAL_COMPONENT_PATH_VAR)
get_directory_name_in_path(${DIR} EXTERNAL_EXPORTER_DIR_NAME)
add_subdirectory(${DIR} ${PROJECT_BINARY_DIR}/external/${EXTERNAL_EXPORTER_DIR_NAME})
endforeach()
elseif(DEFINED $ENV{OPENTELEMETRY_EXTERNAL_COMPONENT_URL})
# This option requires CMake 3.11+: add standard remote repo to build tree.
include(FetchContent)
Expand Down