summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/markdown/snippets/b_msvcrt_clang.md4
-rw-r--r--mesonbuild/compilers/mixins/clang.py27
-rw-r--r--unittests/windowstests.py9
3 files changed, 39 insertions, 1 deletions
diff --git a/docs/markdown/snippets/b_msvcrt_clang.md b/docs/markdown/snippets/b_msvcrt_clang.md
new file mode 100644
index 000000000..2a509bda6
--- /dev/null
+++ b/docs/markdown/snippets/b_msvcrt_clang.md
@@ -0,0 +1,4 @@
+## `-Db_msvcrt` on clang
+
+`-Db_msvcrt` will now link the appropriate runtime library, and set
+the appropriate preprocessor symbols, also when the compiler is clang.
diff --git a/mesonbuild/compilers/mixins/clang.py b/mesonbuild/compilers/mixins/clang.py
index 72b987a12..863d2502d 100644
--- a/mesonbuild/compilers/mixins/clang.py
+++ b/mesonbuild/compilers/mixins/clang.py
@@ -54,6 +54,23 @@ class ClangCompiler(GnuLikeCompiler):
id = 'clang'
+ # -fms-runtime-lib is not supported together with -c, emulate it
+ CRT_D_ARGS: T.Dict[str, T.List[str]] = {
+ 'none': [],
+ 'md': ['-D_MT', '-D_DLL'],
+ 'mdd': ['-D_MT', '-D_DLL', '-D_DEBUG'],
+ 'mt': ['-D_MT'],
+ 'mtd': ['-D_MT', '-D_DEBUG'],
+ }
+
+ CRT_ARGS: T.Dict[str, T.List[str]] = {
+ 'none': [],
+ 'md': ['-fms-runtime-lib=dll'],
+ 'mdd': ['-fms-runtime-lib=dll_dbg'],
+ 'mt': ['-fms-runtime-lib=static'],
+ 'mtd': ['-fms-runtime-lib=static_dbg'],
+ }
+
def __init__(self, defines: T.Optional[T.Dict[str, str]]):
super().__init__()
self.defines = defines or {}
@@ -65,11 +82,19 @@ class ClangCompiler(GnuLikeCompiler):
# linkers don't have base_options.
if isinstance(self.linker, AppleDynamicLinker):
self.base_options.add(OptionKey('b_bitcode'))
- elif isinstance(self.linker, MSVCDynamicLinker):
+ elif isinstance(self.linker, MSVCDynamicLinker) or self.info.is_windows():
self.base_options.add(OptionKey('b_vscrt'))
# All Clang backends can also do LLVM IR
self.can_compile_suffixes.add('ll')
+ def get_crt_compile_args(self, crt_val: str, buildtype: str) -> T.List[str]:
+ crt_val = self.get_crt_val(crt_val, buildtype)
+ return self.CRT_D_ARGS[crt_val]
+
+ def get_crt_link_args(self, crt_val: str, buildtype: str) -> T.List[str]:
+ crt_val = self.get_crt_val(crt_val, buildtype)
+ return self.CRT_ARGS[crt_val]
+
def get_colorout_args(self, colortype: str) -> T.List[str]:
return clang_color_args[colortype][:]
diff --git a/unittests/windowstests.py b/unittests/windowstests.py
index 2cb1407c1..bf1225d18 100644
--- a/unittests/windowstests.py
+++ b/unittests/windowstests.py
@@ -398,7 +398,16 @@ class WindowsTests(BasePlatformTests):
if OptionKey('b_vscrt') not in cc.base_options:
raise SkipTest('Compiler does not support setting the VS CRT')
+ MSVCRT_MAP = {
+ '/MD': '-fms-runtime-lib=dll',
+ '/MDd': '-fms-runtime-lib=dll_dbg',
+ '/MT': '-fms-runtime-lib=static',
+ '/MTd': '-fms-runtime-lib=static_dbg',
+ }
+
def sanitycheck_vscrt(vscrt):
+ if cc.get_argument_syntax() != 'msvc':
+ vscrt = MSVCRT_MAP[vscrt]
checks = self.get_meson_log_sanitychecks()
self.assertGreater(len(checks), 0)
for check in checks: