From c676c168cd5b1f613d265b0d73b298549de7b28b Mon Sep 17 00:00:00 2001 From: esigo Date: Sat, 1 Jan 2022 20:46:16 +0100 Subject: [PATCH 1/2] importing gsl::span if std::span is not available --- CMakeLists.txt | 30 +++++++++++-------- api/include/opentelemetry/std/span.h | 4 +-- .../instrumentation_library.h | 1 + 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2ec050fd84..30ab7ee1ce 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -102,7 +102,9 @@ else() ) endif() -option(WITH_STL "Whether to use Standard Library for C++latest features" OFF) +option(WITH_STL "Whether to use Standard Library for C++ latest features" OFF) +option(WITH_GSL + "Whether to use Guidelines Support Library for C++ latest features" OFF) option(WITH_ABSEIL "Whether to use Abseil for C++latest features" OFF) @@ -137,18 +139,6 @@ if(WITH_STL) # (absl::variant or std::variant) in variant unit test code is consistent with # the global project build definitions. add_definitions(-DHAVE_CPP_STDLIB) - add_definitions(-DHAVE_GSL) - - # Guidelines Support Library path. Used if we are not on not get C++20. - # - # TODO: respect WITH_ABSEIL as alternate implementation of std::span - find_package(Microsoft.GSL QUIET) - if(TARGET Microsoft.GSL::GSL) - list(APPEND CORE_RUNTIME_LIBS Microsoft.GSL::GSL) - else() - set(GSL_DIR third_party/ms-gsl) - include_directories(${GSL_DIR}/include) - endif() # Optimize for speed to reduce the hops if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") @@ -165,6 +155,20 @@ if(WITH_STL) endif() endif() +if(WITH_GSL) + add_definitions(-DHAVE_GSL) + + # Guidelines Support Library path. Used if we are not on not get C++20. + # + find_package(Microsoft.GSL QUIET) + if(TARGET Microsoft.GSL::GSL) + list(APPEND CORE_RUNTIME_LIBS Microsoft.GSL::GSL) + else() + set(GSL_DIR third_party/ms-gsl) + include_directories(${GSL_DIR}/include) + endif() +endif() + option(WITH_OTLP "Whether to include the OpenTelemetry Protocol in the SDK" OFF) option(WITH_ZIPKIN "Whether to include the Zipkin exporter in the SDK" OFF) diff --git a/api/include/opentelemetry/std/span.h b/api/include/opentelemetry/std/span.h index ae614a9425..5fdff57fd5 100644 --- a/api/include/opentelemetry/std/span.h +++ b/api/include/opentelemetry/std/span.h @@ -11,7 +11,7 @@ #if defined __has_include # if __has_include() // Check for __cpp_{feature} # include -# if defined(__cpp_lib_span) +# if defined(__cpp_lib_span) && __cplusplus > 201703L # define HAVE_SPAN # endif # endif @@ -21,7 +21,7 @@ # define HAVE_SPAN # endif # // Check for other compiler span implementation -# if !defined(_MSVC_LANG) && __has_include() +# if !defined(_MSVC_LANG) && __has_include() && __cplusplus > 201703L // This works as long as compiler standard is set to C++20 # define HAVE_SPAN # endif diff --git a/sdk/include/opentelemetry/sdk/instrumentationlibrary/instrumentation_library.h b/sdk/include/opentelemetry/sdk/instrumentationlibrary/instrumentation_library.h index eeea6cd7aa..628ebff82b 100644 --- a/sdk/include/opentelemetry/sdk/instrumentationlibrary/instrumentation_library.h +++ b/sdk/include/opentelemetry/sdk/instrumentationlibrary/instrumentation_library.h @@ -3,6 +3,7 @@ #pragma once +#include #include "opentelemetry/nostd/string_view.h" #include "opentelemetry/nostd/unique_ptr.h" #include "opentelemetry/version.h" From 3071ae7a0fe45442a4bdbe55d0b1c817db149556 Mon Sep 17 00:00:00 2001 From: Ehsan Saei <71217171+esigo@users.noreply.github.com> Date: Sun, 16 Jan 2022 13:15:20 +0100 Subject: [PATCH 2/2] stop defining have_gsl --- api/CMakeLists.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/api/CMakeLists.txt b/api/CMakeLists.txt index 83f89db094..adea77ca2d 100644 --- a/api/CMakeLists.txt +++ b/api/CMakeLists.txt @@ -47,8 +47,7 @@ endif() if(WITH_STL) message("Building with standard library types...") - target_compile_definitions(opentelemetry_api INTERFACE HAVE_CPP_STDLIB - HAVE_GSL) + target_compile_definitions(opentelemetry_api INTERFACE HAVE_CPP_STDLIB) else() message("Building with nostd types...") endif()