Skip to content

Commit ce3bb3f

Browse files
committed
Merge branch 'main' into internal_log_handler
2 parents 2ed4f48 + 9a6cc4e commit ce3bb3f

File tree

4 files changed

+60
-23
lines changed

4 files changed

+60
-23
lines changed

CMakeLists.txt

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,6 @@ else()
2525
set(VCPKG_PREFIX ${CMAKE_BINARY_DIR}/vcpkg)
2626
endif()
2727

28-
# Define custom triplets for vcpkg
29-
if(APPLE)
30-
# On Mac, there is a conflict between libcurl and the version in MATLAB, so
31-
# use libcurl as a shared library and load the MATLAB version at runtime
32-
# run uname -m to determine whether arm64 or x86_64
33-
exec_program(uname ARGS -m OUTPUT_VARIABLE MAC_HOST_SYSTEM)
34-
set(VCPKG_OTEL_TRIPLET ${MAC_HOST_SYSTEM}-osx-otel-matlab)
35-
set(VCPKG_OVERLAY_TRIPLETS ${CMAKE_SOURCE_DIR}/cmake/vcpkg_triplets)
36-
set(VCPKG_TARGET_TRIPLET ${VCPKG_OTEL_TRIPLET})
37-
set(TRIPLET_DEFINITIONS -DVCPKG_TARGET_TRIPLET=${VCPKG_TARGET_TRIPLET})
38-
elseif(WIN32)
39-
# On Windows, there is a conflict between abseil_dll.dll and the version used by Simulink.
40-
# The shared library doesn't seem ABI stable and different versions cannot be used interchangeably.
41-
# To sidestep the problem, use static library.
42-
set(VCPKG_OVERLAY_TRIPLETS ${CMAKE_SOURCE_DIR}/cmake/vcpkg_triplets)
43-
set(VCPKG_TARGET_TRIPLET x64-windows-otel-matlab)
44-
set(TRIPLET_DEFINITIONS -DVCPKG_TARGET_TRIPLET=${VCPKG_TARGET_TRIPLET})
45-
endif()
46-
4728
set(VCPKG_FETCH_CONTENT_NAME vcpkg)
4829
set(VCPKG_GIT_REPOSITORY "https://github.com/microsoft/vcpkg.git")
4930
set(VCPKG_GIT_TAG "fba75d0")
@@ -68,6 +49,28 @@ if(NOT DEFINED VCPKG_INSTALLED_DIR)
6849
set(VCPKG_INSTALLED_DIR ${CMAKE_BINARY_DIR}/vcpkg_installed)
6950
endif()
7051

52+
# Define custom triplets for vcpkg
53+
if(APPLE)
54+
# On Mac, there is a conflict between libcurl and the version in MATLAB, so
55+
# use libcurl as a shared library and load the MATLAB version at runtime
56+
# run uname -m to determine whether arm64 or x86_64
57+
exec_program(uname ARGS -m OUTPUT_VARIABLE MAC_HOST_SYSTEM)
58+
set(VCPKG_OTEL_TRIPLET ${MAC_HOST_SYSTEM}-osx-otel-matlab)
59+
set(VCPKG_OVERLAY_TRIPLETS ${CMAKE_SOURCE_DIR}/cmake/vcpkg_triplets)
60+
set(VCPKG_TARGET_TRIPLET ${VCPKG_OTEL_TRIPLET})
61+
set(TRIPLET_DEFINITIONS -DVCPKG_TARGET_TRIPLET=${VCPKG_TARGET_TRIPLET})
62+
elseif(WIN32)
63+
# On Windows, we use a custom triplet to work around two issues.
64+
# First, there is a conflict between abseil_dll.dll and the version used by Simulink.
65+
# The shared library doesn't seem ABI stable and different versions cannot be used interchangeably.
66+
# To sidestep the problem, use static library.
67+
# Second, define a preprocessor macro _DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR to work around an invalid MEX file issue on GitHub
68+
# See https://github.com/mathworks/OpenTelemetry-Matlab/issues/130
69+
set(VCPKG_OVERLAY_TRIPLETS ${CMAKE_SOURCE_DIR}/cmake/vcpkg_triplets)
70+
set(VCPKG_TARGET_TRIPLET x64-windows-otel-matlab)
71+
set(TRIPLET_DEFINITIONS -DVCPKG_TARGET_TRIPLET=${VCPKG_TARGET_TRIPLET})
72+
endif()
73+
7174
# ######################################
7275
# Options
7376
# ######################################
@@ -184,10 +187,18 @@ if(NOT DEFINED OTEL_CPP_INSTALLED_DIR)
184187

185188
set(OTEL_CPP_CXX_STANDARD 14)
186189

187-
if(NOT APPLE OR SKIP_OTEL_CPP_PATCH)
188-
set(patch_command "")
190+
set(PATCHES_DIR ${CMAKE_SOURCE_DIR}/patches)
191+
if(SKIP_OTEL_CPP_PATCH)
192+
set(patch_comand "")
193+
elseif(WIN32)
194+
# Windows patch to add a preprocessor definition _DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR
195+
# See https://github.com/mathworks/OpenTelemetry-Matlab/issues/130
196+
set(patch_command git apply ${PATCHES_DIR}/otel-cpp-windows.patch)
197+
elseif(APPLE)
198+
# Mac patch to fix a linker issue when including gRPC exporter
199+
set(patch_command git apply ${PATCHES_DIR}/otel-cpp-mac.patch)
189200
else()
190-
set(patch_command git apply ${CMAKE_SOURCE_DIR}/otel-cpp.patch)
201+
set(patch_command "")
191202
endif()
192203

193204
ExternalProject_Add(
@@ -310,6 +321,12 @@ if(WITH_OTLP_GRPC)
310321
${OTLP_EXPORTER_SOURCE_DIR}/OtlpGrpcLogRecordExporterProxy.cpp)
311322
endif()
312323

324+
if(WIN32)
325+
# Add a preprocessor definition _DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR to fix an invalid mex file issue on Windows.
326+
# See https://github.com/mathworks/OpenTelemetry-Matlab/issues/130
327+
add_compile_definitions(_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR)
328+
endif()
329+
313330
libmexclass_client_add_proxy_library(
314331
NAME ${OPENTELEMETRY_PROXY_LIBRARY_NAME}
315332
SOURCES ${OPENTELEMETRY_PROXY_SOURCES}

cmake/vcpkg_triplets/x64-windows-otel-matlab.cmake

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,7 @@ if(${PORT} MATCHES "abseil")
66
else()
77
set(VCPKG_LIBRARY_LINKAGE dynamic)
88
endif()
9-
9+
# Define a preprocessor macro _DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR to work around an invalid MEX file issue
10+
# See https://github.com/mathworks/OpenTelemetry-Matlab/issues/130
11+
set(VCPKG_CXX_FLAGS "/D_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR")
12+
set(VCPKG_C_FLAGS "/D_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR")
File renamed without changes.

patches/otel-cpp-windows.patch

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
diff --git a/CMakeLists.txt b/CMakeLists.txt
2+
index cc085b1a..6c4dc0ae 100644
3+
--- a/CMakeLists.txt
4+
+++ b/CMakeLists.txt
5+
@@ -15,6 +15,12 @@ endif()
6+
7+
project(opentelemetry-cpp)
8+
9+
+if(WIN32)
10+
+ # Add a preprocessor macro _DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR to work around an invalid MEX file issue
11+
+ # See https://github.com/mathworks/OpenTelemetry-Matlab/issues/130
12+
+ add_compile_definitions(_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR)
13+
+endif()
14+
+
15+
# Mark variables as used so cmake doesn't complain about them
16+
mark_as_advanced(CMAKE_TOOLCHAIN_FILE)
17+

0 commit comments

Comments
 (0)