Fix XED runtime always defaulting to /MT

This commit is contained in:
Duncan Ogilvie
2026-05-02 20:06:08 +02:00
committed by Kyle Elliott
parent 0e324aee8c
commit ba4c420b50
2 changed files with 32 additions and 1 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
# /Users/admin/Projects/cxx-common/ports/xed/XEDConfig.cmake
# Reference: https://github.com/lifting-bits/cxx-common/blob/e0063b2f5986582ed8dcab0c2863abf0893b3082/ports/xed/XEDConfig.cmake
if(XED_FOUND)
return()
+31
View File
@@ -23,6 +23,37 @@ set(MFILE_ARGS
"--compiler=${compiler}"
)
# XED is built by mbuild, not CMake, so it does not honor
# CMAKE_MSVC_RUNTIME_LIBRARY. mbuild also ties "--static" to /MT by default.
# Dna.LLVMInterop and the CMake-built dependencies use the DLL CRT (/MD), so
# disable mbuild's implicit CRT flag and pass the matching MSVC runtime flag
# explicitly. Without this, xed.lib/xed-ild.lib embed /DEFAULTLIB:libcmt.lib
# and the Dna.LLVMInterop link emits LNK4098.
if(CMAKE_SYSTEM_NAME STREQUAL "Windows" AND MSVC)
set(xed_msvc_runtime_flag "")
if(DEFINED CMAKE_MSVC_RUNTIME_LIBRARY AND NOT CMAKE_MSVC_RUNTIME_LIBRARY STREQUAL "")
if(CMAKE_MSVC_RUNTIME_LIBRARY MATCHES "DebugDLL$")
set(xed_msvc_runtime_flag "/MDd")
elseif(CMAKE_MSVC_RUNTIME_LIBRARY MATCHES "DLL$")
set(xed_msvc_runtime_flag "/MD")
elseif(CMAKE_MSVC_RUNTIME_LIBRARY MATCHES "Debug$")
set(xed_msvc_runtime_flag "/MTd")
else()
set(xed_msvc_runtime_flag "/MT")
endif()
elseif(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(xed_msvc_runtime_flag "/MDd")
else()
set(xed_msvc_runtime_flag "/MD")
endif()
list(APPEND MFILE_ARGS
"--no-mscrt"
"--extra-ccflags=${xed_msvc_runtime_flag}"
"--extra-cxxflags=${xed_msvc_runtime_flag}"
)
endif()
if(CMAKE_OSX_SYSROOT)
list(APPEND MFILE_ARGS "--extra-ccflags=-isysroot ${CMAKE_OSX_SYSROOT}")
list(APPEND MFILE_ARGS "--extra-cxxflags=-isysroot ${CMAKE_OSX_SYSROOT}")