Skip to content

Commit ba4c420

Browse files
mrexodiakyle-elliott-tob
authored andcommitted
Fix XED runtime always defaulting to /MT
1 parent 0e324ae commit ba4c420

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

dependencies/XEDConfig.cmake.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# /Users/admin/Projects/cxx-common/ports/xed/XEDConfig.cmake
1+
# Reference: https://github.com/lifting-bits/cxx-common/blob/e0063b2f5986582ed8dcab0c2863abf0893b3082/ports/xed/XEDConfig.cmake
22

33
if(XED_FOUND)
44
return()

dependencies/xed.cmake

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,37 @@ set(MFILE_ARGS
2323
"--compiler=${compiler}"
2424
)
2525

26+
# XED is built by mbuild, not CMake, so it does not honor
27+
# CMAKE_MSVC_RUNTIME_LIBRARY. mbuild also ties "--static" to /MT by default.
28+
# Dna.LLVMInterop and the CMake-built dependencies use the DLL CRT (/MD), so
29+
# disable mbuild's implicit CRT flag and pass the matching MSVC runtime flag
30+
# explicitly. Without this, xed.lib/xed-ild.lib embed /DEFAULTLIB:libcmt.lib
31+
# and the Dna.LLVMInterop link emits LNK4098.
32+
if(CMAKE_SYSTEM_NAME STREQUAL "Windows" AND MSVC)
33+
set(xed_msvc_runtime_flag "")
34+
if(DEFINED CMAKE_MSVC_RUNTIME_LIBRARY AND NOT CMAKE_MSVC_RUNTIME_LIBRARY STREQUAL "")
35+
if(CMAKE_MSVC_RUNTIME_LIBRARY MATCHES "DebugDLL$")
36+
set(xed_msvc_runtime_flag "/MDd")
37+
elseif(CMAKE_MSVC_RUNTIME_LIBRARY MATCHES "DLL$")
38+
set(xed_msvc_runtime_flag "/MD")
39+
elseif(CMAKE_MSVC_RUNTIME_LIBRARY MATCHES "Debug$")
40+
set(xed_msvc_runtime_flag "/MTd")
41+
else()
42+
set(xed_msvc_runtime_flag "/MT")
43+
endif()
44+
elseif(CMAKE_BUILD_TYPE STREQUAL "Debug")
45+
set(xed_msvc_runtime_flag "/MDd")
46+
else()
47+
set(xed_msvc_runtime_flag "/MD")
48+
endif()
49+
50+
list(APPEND MFILE_ARGS
51+
"--no-mscrt"
52+
"--extra-ccflags=${xed_msvc_runtime_flag}"
53+
"--extra-cxxflags=${xed_msvc_runtime_flag}"
54+
)
55+
endif()
56+
2657
if(CMAKE_OSX_SYSROOT)
2758
list(APPEND MFILE_ARGS "--extra-ccflags=-isysroot ${CMAKE_OSX_SYSROOT}")
2859
list(APPEND MFILE_ARGS "--extra-cxxflags=-isysroot ${CMAKE_OSX_SYSROOT}")

0 commit comments

Comments
 (0)