diff --git a/CMakeLists.txt b/CMakeLists.txt index c8bce5be1f..8d278c0c06 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,7 +50,6 @@ option(WITH_STL "Whether to use Standard Library for C++latest features" OFF) option(WITH_ABSEIL "Whether to use Abseil for C++latest features" OFF) if(WITH_ABSEIL) - add_definitions(-DHAVE_ABSEIL) find_package(absl CONFIG REQUIRED) set(CORE_RUNTIME_LIBS absl::any absl::base absl::bits absl::city) diff --git a/api/CMakeLists.txt b/api/CMakeLists.txt index 20d786e0cb..89839b48be 100644 --- a/api/CMakeLists.txt +++ b/api/CMakeLists.txt @@ -41,6 +41,10 @@ if(BUILD_TESTING) add_subdirectory(test) endif() +if(WITH_ABSEIL) + target_compile_definitions(opentelemetry_api INTERFACE HAVE_ABSEIL) +endif() + if(WITH_STL) message("Building with standard library types...") target_compile_definitions(opentelemetry_api INTERFACE HAVE_CPP_STDLIB diff --git a/api/include/opentelemetry/nostd/variant.h b/api/include/opentelemetry/nostd/variant.h index cab15547fe..c2c04ad41b 100644 --- a/api/include/opentelemetry/nostd/variant.h +++ b/api/include/opentelemetry/nostd/variant.h @@ -47,7 +47,7 @@ OPENTELEMETRY_END_NAMESPACE # endif # ifdef HAVE_ABSEIL -# include "absl/types/variant.h" +# include # else # include "./absl/types/variant.h" # endif diff --git a/sdk/src/common/core.cc b/sdk/src/common/core.cc index 2bc6da52a9..101258f97a 100644 --- a/sdk/src/common/core.cc +++ b/sdk/src/common/core.cc @@ -7,7 +7,7 @@ #include "opentelemetry/nostd/variant.h" // clang-format on -#if defined(HAVE_ABSEIL) +#if !defined(HAVE_CPP_STDLIB) && !defined(OTABSL_USES_STD_VARIANT) /* The option of building and linking with Abseil library implies that Abseil * may already provide the ThrowBadVariantAccess implementation if its own. * Reconsider the implementation below: we are potentially introducing @@ -28,9 +28,19 @@ namespace absl { +# if defined(HAVE_ABSEIL) +ABSL_NAMESPACE_BEGIN +# else +OTABSL_NAMESPACE_BEGIN +# endif namespace variant_internal { void __cdecl ThrowBadVariantAccess(){/* TODO: std::terminate or re-throw? */}; } +# if defined(HAVE_ABSEIL) +ABSL_NAMESPACE_END +# else +OTABSL_NAMESPACE_END +# endif } // namespace absl #endif