From 12fc770f9df8fecbff945f99cc0554d3528f50b3 Mon Sep 17 00:00:00 2001 From: Tom Tan Date: Thu, 7 Dec 2023 15:09:52 -0800 Subject: [PATCH] Set binary folder for external components correctly --- .../opentelemetry-build-external-component.cmake | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/cmake/opentelemetry-build-external-component.cmake b/cmake/opentelemetry-build-external-component.cmake index bd82b3f471..72368a0d05 100644 --- a/cmake/opentelemetry-build-external-component.cmake +++ b/cmake/opentelemetry-build-external-component.cmake @@ -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 @@ -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.