File tree 6 files changed +51
-54
lines changed
api/include/opentelemetry/detail
test_common/src/http/client/nosend
6 files changed +51
-54
lines changed Original file line number Diff line number Diff line change @@ -645,6 +645,37 @@ if(BUILD_TESTING)
645
645
endif ()
646
646
message (STATUS "GTEST_INCLUDE_DIRS = ${GTEST_INCLUDE_DIRS} " )
647
647
message (STATUS "GTEST_BOTH_LIBRARIES = ${GTEST_BOTH_LIBRARIES} " )
648
+
649
+ # Try to find gmock
650
+ if (NOT GMOCK_LIB AND TARGET GTest::gmock)
651
+ set (GMOCK_LIB GTest::gmock)
652
+ elseif (MSVC )
653
+ # Explicitly specify that we consume GTest from shared library. The rest of
654
+ # code logic below determines whether we link Release or Debug flavor of the
655
+ # library. These flavors have different prefix on Windows, gmock and gmockd
656
+ # respectively.
657
+ add_definitions (-DGTEST_LINKED_AS_SHARED_LIBRARY=1)
658
+ if (GMOCK_LIB)
659
+ # unset GMOCK_LIB to force find_library to redo the lookup, as the cached
660
+ # entry could cause linking to incorrect flavor of gmock and leading to
661
+ # runtime error.
662
+ unset (GMOCK_LIB CACHE )
663
+ endif ()
664
+ endif ()
665
+ if (NOT GMOCK_LIB)
666
+ if (MSVC AND CMAKE_BUILD_TYPE STREQUAL "Debug" )
667
+ find_library (GMOCK_LIB gmockd PATH_SUFFIXES lib)
668
+ else ()
669
+ find_library (GMOCK_LIB gmock PATH_SUFFIXES lib)
670
+ endif ()
671
+ # Reset GMOCK_LIB if it was not found, or some target may link
672
+ # GMOCK_LIB-NOTFOUND
673
+ if (NOT GMOCK_LIB)
674
+ unset (GMOCK_LIB)
675
+ unset (GMOCK_LIB CACHE )
676
+ endif ()
677
+ endif ()
678
+
648
679
enable_testing ()
649
680
if (WITH_BENCHMARK)
650
681
# Benchmark respects the CMAKE_PREFIX_PATH
Original file line number Diff line number Diff line change 11
11
12
12
#define OPENTELEMETRY_CONCAT (A, B ) OPENTELEMETRY_CONCAT_(A, B)
13
13
#define OPENTELEMETRY_CONCAT_ (A, B ) A##B
14
+
15
+ // Import the C++20 feature-test macros
16
+ #ifdef __has_include
17
+ # if __has_include(<version>)
18
+ # include < version>
19
+ # endif
20
+ #elif defined(_MSC_VER) && ((defined(__cplusplus) && __cplusplus >= 202002L) || \
21
+ (defined(_MSVC_LANG) && _MSVC_LANG >= 202002L ))
22
+ # if _MSC_VER >= 1922
23
+ # include < version>
24
+ # endif
25
+ #endif
Original file line number Diff line number Diff line change 1
1
// Copyright The OpenTelemetry Authors
2
2
// SPDX-License-Identifier: Apache-2.0
3
3
4
+ #include < opentelemetry/version.h>
5
+
4
6
#include < chrono>
5
7
#include < ctime>
6
8
#include < nlohmann/json.hpp>
7
9
#include < string>
8
10
11
+ #if defined(__cpp_lib_format)
12
+ # include < format>
13
+ #endif
14
+
9
15
#include " opentelemetry/exporters/elasticsearch/es_log_recordable.h"
10
16
#include " opentelemetry/logs/severity.h"
11
17
#include " opentelemetry/nostd/variant.h"
@@ -71,7 +77,8 @@ void ElasticSearchRecordable::SetTimestamp(
71
77
72
78
// If built with with at least cpp 20 then use std::format
73
79
// Otherwise use the old style to format the timestamp in UTC
74
- #if __cplusplus >= 202002L
80
+ // @see https://en.cppreference.com/w/cpp/feature_test#cpp_lib_format
81
+ #if defined(__cpp_lib_format) && __cpp_lib_format >= 201907
75
82
const std::string dateStr = std::format (" {:%FT%T%Ez}" , timePoint);
76
83
#else
77
84
std::time_t time = std::chrono::system_clock::to_time_t (timePoint);
Original file line number Diff line number Diff line change @@ -313,29 +313,6 @@ if(BUILD_TESTING)
313
313
TEST_PREFIX exporter.otlp.
314
314
TEST_LIST otlp_metrics_serialization_test)
315
315
316
- if (NOT GMOCK_LIB AND TARGET GTest::gmock)
317
- set (GMOCK_LIB GTest::gmock)
318
- elseif (MSVC )
319
- # Explicitly specify that we consume GTest from shared library. The rest of
320
- # code logic below determines whether we link Release or Debug flavor of the
321
- # library. These flavors have different prefix on Windows, gmock and gmockd
322
- # respectively.
323
- add_definitions (-DGTEST_LINKED_AS_SHARED_LIBRARY=1)
324
- if (GMOCK_LIB)
325
- # unset GMOCK_LIB to force find_library to redo the lookup, as the cached
326
- # entry could cause linking to incorrect flavor of gmock and leading to
327
- # runtime error.
328
- unset (GMOCK_LIB CACHE )
329
- endif ()
330
- endif ()
331
- if (NOT GMOCK_LIB)
332
- if (MSVC AND CMAKE_BUILD_TYPE STREQUAL "Debug" )
333
- find_library (GMOCK_LIB gmockd PATH_SUFFIXES lib)
334
- else ()
335
- find_library (GMOCK_LIB gmock PATH_SUFFIXES lib)
336
- endif ()
337
- endif ()
338
-
339
316
if (WITH_OTLP_GRPC)
340
317
add_executable (otlp_grpc_exporter_test test /otlp_grpc_exporter_test.cc)
341
318
target_link_libraries (
Original file line number Diff line number Diff line change @@ -49,17 +49,6 @@ if(BUILD_TESTING)
49
49
TEST_PREFIX exporter.
50
50
TEST_LIST zipkin_recordable_test)
51
51
52
- if (MSVC )
53
- if (GMOCK_LIB)
54
- unset (GMOCK_LIB CACHE )
55
- endif ()
56
- endif ()
57
- if (MSVC AND CMAKE_BUILD_TYPE STREQUAL "Debug" )
58
- find_library (GMOCK_LIB gmockd PATH_SUFFIXES lib)
59
- else ()
60
- find_library (GMOCK_LIB gmock PATH_SUFFIXES lib)
61
- endif ()
62
-
63
52
add_executable (zipkin_exporter_test test /zipkin_exporter_test.cc)
64
53
65
54
target_link_libraries (
Original file line number Diff line number Diff line change @@ -8,25 +8,6 @@ if(${BUILD_TESTING})
8
8
set_target_properties (opentelemetry_http_client_nosend
9
9
PROPERTIES EXPORT_NAME opentelemetry_http_client_nosend)
10
10
11
- if (MSVC )
12
- # Explicitly specify that we consume GTest from shared library. The rest of
13
- # code logic below determines whether we link Release or Debug flavor of the
14
- # library. These flavors have different prefix on Windows, gmock and gmockd
15
- # respectively.
16
- add_definitions (-DGTEST_LINKED_AS_SHARED_LIBRARY=1)
17
- if (GMOCK_LIB)
18
- # unset GMOCK_LIB to force find_library to redo the lookup, as the cached
19
- # entry could cause linking to incorrect flavor of gmock and leading to
20
- # runtime error.
21
- unset (GMOCK_LIB CACHE )
22
- endif ()
23
- endif ()
24
- if (MSVC AND CMAKE_BUILD_TYPE STREQUAL "Debug" )
25
- find_library (GMOCK_LIB gmockd PATH_SUFFIXES lib)
26
- else ()
27
- find_library (GMOCK_LIB gmock PATH_SUFFIXES lib)
28
- endif ()
29
-
30
11
target_link_libraries (
31
12
opentelemetry_http_client_nosend opentelemetry_ext
32
13
opentelemetry_test_common ${GMOCK_LIB} ${GTEST_BOTH_LIBRARIES} )
You can’t perform that action at this time.
0 commit comments