aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarco Trevisan (Treviño) <mail@3v1n0.net>2021-05-07 20:20:29 +0200
committerJussi Pakkanen <jpakkane@gmail.com>2021-05-08 21:27:35 +0300
commit739e499554850d2cb8268bed219e8ba127051f76 (patch)
tree01f83e072029d70698b23b858ade37bfdbf1b950
parent6033c0f0da764e9d81e35366a6ba81b8f6b984f7 (diff)
downloadmeson-739e499554850d2cb8268bed219e8ba127051f76.zip
meson-739e499554850d2cb8268bed219e8ba127051f76.tar.gz
meson-739e499554850d2cb8268bed219e8ba127051f76.tar.bz2
ninjabackend: Add pch includes as early as possible not to be overridden
When pch are used for a target meson will make the compiler to include the pre-compiled header. While this is useful, this needs to happen before any other header has been included, otherwise: 1) we won't take advantage of pch for anything else previously included 2) gcc will just fail as it won't even try to look for a pre-compiled header in this case [1] This case can happen quite a easily when a dependency provides an included header in its cflags. As per this, split _generate_single_compile() in two phases, one is responsible of initializing the compiler data, while the other is defining commands for the context. In this way, when pch can be used, we can insert the pch inclusion earlier than any other provided by the target. [1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100462
-rw-r--r--mesonbuild/backend/ninjabackend.py22
1 files changed, 18 insertions, 4 deletions
diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py
index fa07235..05427d3 100644
--- a/mesonbuild/backend/ninjabackend.py
+++ b/mesonbuild/backend/ninjabackend.py
@@ -2328,8 +2328,12 @@ https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47485'''))
bargs = []
return (sargs, bargs)
- @lru_cache(maxsize=None)
def _generate_single_compile(self, target, compiler, is_generated=False):
+ commands = self._generate_single_compile_base_args(target, compiler, is_generated)
+ commands += self._generate_single_compile_target_args(target, compiler, is_generated)
+ return commands
+
+ def _generate_single_compile_base_args(self, target, compiler, is_generated):
base_proxy = self.get_base_options_for_target(target)
# Create an empty commands list, and start adding arguments from
# various sources in the order in which they must override each other
@@ -2341,12 +2345,16 @@ https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47485'''))
# These have the lowest priority.
commands += compilers.get_base_compile_args(base_proxy,
compiler)
+ return commands
+
+ @lru_cache(maxsize=None)
+ def _generate_single_compile_target_args(self, target, compiler, is_generated):
# The code generated by valac is usually crap and has tons of unused
# variables and such, so disable warnings for Vala C sources.
no_warn_args = (is_generated == 'vala')
# Add compiler args and include paths from several sources; defaults,
# build options, external dependencies, etc.
- commands += self.generate_basic_compiler_args(target, compiler, no_warn_args)
+ commands = self.generate_basic_compiler_args(target, compiler, no_warn_args)
# Add custom target dirs as includes automatically, but before
# target-specific include directories.
if target.implicit_include_directories:
@@ -2410,7 +2418,14 @@ https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47485'''))
raise AssertionError(f'BUG: sources should not contain headers {src!r}')
compiler = get_compiler_for_source(target.compilers.values(), src)
- commands = self._generate_single_compile(target, compiler, is_generated)
+ commands = self._generate_single_compile_base_args(target, compiler, is_generated)
+
+ # Include PCH header as first thing as it must be the first one or it will be
+ # ignored by gcc https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100462
+ if self.environment.coredata.options.get(OptionKey('b_pch')) and is_generated != 'pch':
+ commands += self.get_pch_include_args(compiler, target)
+
+ commands += self._generate_single_compile_target_args(target, compiler, is_generated)
commands = commands.compiler.compiler_args(commands)
# Create introspection information
@@ -2441,7 +2456,6 @@ https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47485'''))
# PCH handling
if self.environment.coredata.options.get(OptionKey('b_pch')):
- commands += self.get_pch_include_args(compiler, target)
pchlist = target.get_pch(compiler.language)
else:
pchlist = []