Skip to content

Commit

Permalink
Set binary folder for external components correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomsonTan committed Dec 7, 2023
1 parent f8ba925 commit 12fc770
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions cmake/opentelemetry-build-external-component.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
# 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}")

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 paths of the external
Expand All @@ -14,14 +24,16 @@ if(OPENTELEMETRY_EXTERNAL_COMPONENT_PATH)
# Add custom component path to build tree and consolidate binary artifacts in
# current project binary output directory.
foreach(DIR IN LISTS OPENTELEMETRY_EXTERNAL_COMPONENT_PATH)
add_subdirectory(${DIR} ${PROJECT_BINARY_DIR}/external)
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_PATH})
# Add custom component path to build tree and consolidate binary artifacts in
# current project binary output directory.
set(OPENTELEMETRY_EXTERNAL_COMPONENT_PATH_VAR $ENV{OPENTELEMETRY_EXTERNAL_COMPONENT_PATH})
foreach(DIR IN LISTS OPENTELEMETRY_EXTERNAL_COMPONENT_PATH_VAR)
add_subdirectory(${DIR} ${PROJECT_BINARY_DIR}/external)
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.
Expand Down

0 comments on commit 12fc770

Please sign in to comment.