diff --git a/dependencies/XEDConfig.cmake.in b/dependencies/XEDConfig.cmake.in index c720e83c..34d454dd 100644 --- a/dependencies/XEDConfig.cmake.in +++ b/dependencies/XEDConfig.cmake.in @@ -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() diff --git a/dependencies/xed.cmake b/dependencies/xed.cmake index 69877bcb..414ae02c 100644 --- a/dependencies/xed.cmake +++ b/dependencies/xed.cmake @@ -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}")