Skip to content

Commit 4eb5d95

Browse files
committed
Define _DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR preprocessor macro to work around invalid MEX file issue on Windows. Fixes #130
1 parent 1821f44 commit 4eb5d95

4 files changed

Lines changed: 41 additions & 5 deletions

File tree

CMakeLists.txt

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,12 @@ else()
3636
set(VCPKG_TARGET_TRIPLET ${VCPKG_OTEL_TRIPLET})
3737
set(TRIPLET_DEFINITIONS -DVCPKG_OVERLAY_TRIPLETS="${VCPKG_OVERLAY_TRIPLETS}" -DVCPKG_TARGET_TRIPLET=${VCPKG_TARGET_TRIPLET})
3838
elseif(WIN32)
39-
# On Windows, there is a conflict between abseil_dll.dll and the version used by Simulink.
39+
# On Windows, we use a custom triplet to work around two issues.
40+
# First, there is a conflict between abseil_dll.dll and the version used by Simulink.
4041
# The shared library doesn't seem ABI stable and different versions cannot be used interchangeably.
4142
# To sidestep the problem, use static library.
43+
# Second, define a preprocessor macro _DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR to work around an invalid MEX file issue on GitHub
44+
# See https://github.com/mathworks/OpenTelemetry-Matlab/issues/130
4245
set(VCPKG_OVERLAY_TRIPLETS ${CMAKE_SOURCE_DIR}/cmake/vcpkg_triplets)
4346
set(VCPKG_TARGET_TRIPLET x64-windows-otel-matlab)
4447
set(TRIPLET_DEFINITIONS -DVCPKG_OVERLAY_TRIPLETS="${VCPKG_OVERLAY_TRIPLETS}" -DVCPKG_TARGET_TRIPLET=${VCPKG_TARGET_TRIPLET})
@@ -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(
@@ -309,6 +320,12 @@ if(WITH_OTLP_GRPC)
309320
${OTLP_EXPORTER_SOURCE_DIR}/OtlpGrpcLogRecordExporterProxy.cpp)
310321
endif()
311322

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

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@ 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")

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)