diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py index 29c31683d..62cc75602 100644 --- a/mesonbuild/backend/backends.py +++ b/mesonbuild/backend/backends.py @@ -410,16 +410,10 @@ class Backend: args = [] pchpath = self.get_target_private_dir(target) includeargs = compiler.get_include_args(pchpath, False) - for lang in ['c', 'cpp']: - p = target.get_pch(lang) - if not p: - continue - if compiler.can_compile(p[-1]): - header = p[0] - args += compiler.get_pch_use_args(pchpath, header) - if len(args) > 0: - args = includeargs + args - return args + p = target.get_pch(compiler.get_language()) + if p: + args += compiler.get_pch_use_args(pchpath, p[0]) + return includeargs + args @staticmethod def escape_extra_args(compiler, args): diff --git a/test cases/common/15 mixed pch/meson.build b/test cases/common/15 mixed pch/meson.build index 19129d83d..8e9da9397 100644 --- a/test cases/common/15 mixed pch/meson.build +++ b/test cases/common/15 mixed pch/meson.build @@ -1,6 +1,19 @@ project('mixed C and C++ pch test', 'cpp', 'c') -exe = executable('prog', 'main.cc', 'func.c', -c_pch : ['pch/func.h', 'pch/func_pch.c'], -cpp_pch : ['pch/main_pch.cc', 'pch/main.h']) +exe = executable( + 'prog', + files('main.cc', 'func.c'), + c_pch : ['pch/func.h', 'pch/func_pch.c'], + cpp_pch : ['pch/main_pch.cc', 'pch/main.h'], +) + +cc = meson.get_compiler('c') +if cc.get_id() != 'msvc' + exe2 = executable( + 'prog2', + files('main.cc', 'func.c'), + c_pch : 'pch/func.h', + cpp_pch : 'pch/main.h', + ) +endif