diff options
| author | Dylan Baker <dylan@pnwbakers.com> | 2025-01-13 10:58:52 -0800 |
|---|---|---|
| committer | Dylan Baker <dylan@pnwbakers.com> | 2025-10-15 10:21:46 -0700 |
| commit | 3471ea270015f5edc2668e482494021723ed8d46 (patch) | |
| tree | a78dae14db368d128a78d1ca4092fba3b90566f2 | |
| parent | df67cba3c9aecc2fd144a3d0170465eb55a6b48d (diff) | |
| download | meson-3471ea270015f5edc2668e482494021723ed8d46.tar.gz | |
build: move platform specific pic/pie handling into helper
There's really no reason to not do this in the `_extract_pic_pie` helper,
it only increases the chance of us not doing this when we should.
| -rw-r--r-- | mesonbuild/build.py | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/mesonbuild/build.py b/mesonbuild/build.py index 9039e696d..6f280280d 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -1326,20 +1326,9 @@ class BuildTarget(Target): self.suffix = name_suffix self.name_suffix_set = True if isinstance(self, StaticLibrary): - # You can't disable PIC on OS X. The compiler ignores -fno-PIC. - # PIC is always on for Windows (all code is position-independent - # since library loading is done differently) - m = self.environment.machines[self.for_machine] - if m.is_darwin() or m.is_windows(): - self.pic = True - else: - self.pic = self._extract_pic_pie(kwargs, 'pic', 'b_staticpic') + self.pic = self._extract_pic_pie(kwargs, 'pic', 'b_staticpic') if isinstance(self, Executable) or (isinstance(self, StaticLibrary) and not self.pic): - # Executables must be PIE on Android - if self.environment.machines[self.for_machine].is_android(): - self.pie = True - else: - self.pie = self._extract_pic_pie(kwargs, 'pie', 'b_pie') + self.pie = self._extract_pic_pie(kwargs, 'pie', 'b_pie') self.implicit_include_directories = kwargs.get('implicit_include_directories', True) if not isinstance(self.implicit_include_directories, bool): raise InvalidArguments('Implicit_include_directories must be a boolean.') @@ -1365,6 +1354,18 @@ class BuildTarget(Target): self.swift_module_name = self.name def _extract_pic_pie(self, kwargs: BuildTargetKeywordArguments, arg: str, option: str) -> bool: + # You can't disable PIC on OS X. The compiler ignores -fno-PIC. + # PIC is always on for Windows (all code is position-independent + # since library loading is done differently) + m = self.environment.machines[self.for_machine] + assert m is not None, 'for mypy' + if arg == 'pic' and (m.is_darwin() or m.is_windows()): + return True + + # Executables must be PIE on Android + if arg == 'pie' and m.is_android(): + return True + # Check if we have -fPIC, -fpic, -fPIE, or -fpie in cflags all_flags = self.extra_args['c'] + self.extra_args['cpp'] if '-f' + arg.lower() in all_flags or '-f' + arg.upper() in all_flags: |
