From 1270af4b9a7183113bf92a01e22c67b1b7bb2a82 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Wed, 14 Feb 2018 10:31:18 -0800 Subject: [PATCH 1/3] tests/15 mixed pch: Use current style --- test cases/common/15 mixed pch/meson.build | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/test cases/common/15 mixed pch/meson.build b/test cases/common/15 mixed pch/meson.build index 19129d83d..ad8bb9529 100644 --- a/test cases/common/15 mixed pch/meson.build +++ b/test cases/common/15 mixed pch/meson.build @@ -1,6 +1,9 @@ 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'], +) From d3d0d4affb8880ff46c152dccb54d12851f3ca4c Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Wed, 14 Feb 2018 10:32:57 -0800 Subject: [PATCH 2/3] tests/15 mixed pch: Add a test using only the headers Which is supposed to work for GCC and Clang. --- test cases/common/15 mixed pch/meson.build | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test cases/common/15 mixed pch/meson.build b/test cases/common/15 mixed pch/meson.build index ad8bb9529..8e9da9397 100644 --- a/test cases/common/15 mixed pch/meson.build +++ b/test cases/common/15 mixed pch/meson.build @@ -7,3 +7,13 @@ exe = executable( 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 From b11035693c4d10b233cac0a0afaac923592b1053 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Wed, 14 Feb 2018 11:27:23 -0800 Subject: [PATCH 3/3] backends: Only add pch args that are appropriate for the compiler Currently we try both C and C++ when determining which PCH files to include. The problem with this approach is that if there are no C or C++ files (only headers) and the target has both C and C++ sources then the PCHs will be passed to the wrong compiler. The solution is less code, we already have the compiler, the compiler knows what language it is, so we don't need to walk both C and C++. Fixes #3068 --- mesonbuild/backend/backends.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py index 292b02780..215d73b6e 100644 --- a/mesonbuild/backend/backends.py +++ b/mesonbuild/backend/backends.py @@ -407,16 +407,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):