Merge pull request #885 from centricular/fix-staticlib-pic-error

Warn if -fPIC is passed instead of pic to static libraries (instead of erroring out)
pull/868/head
Jussi Pakkanen 8 years ago committed by GitHub
commit 3a3db9fc5e
  1. 21
      mesonbuild/build.py
  2. 6
      test cases/common/62 exe static shared/meson.build
  3. 3
      test cases/common/62 exe static shared/shlib2.c
  4. 3
      test cases/common/62 exe static shared/stat2.c
  5. 2
      test cases/frameworks/7 gnome/mkenums/meson.build

@ -510,18 +510,18 @@ class BuildTarget():
name_prefix = kwargs['name_prefix']
if isinstance(name_prefix, list):
if len(name_prefix) != 0:
raise InvalidArguments('Array must be empty to signify null.')
raise InvalidArguments('name_prefix array must be empty to signify null.')
elif not isinstance(name_prefix, str):
raise InvalidArguments('Name prefix must be a string.')
raise InvalidArguments('name_prefix must be a string.')
self.prefix = name_prefix
if 'name_suffix' in kwargs:
name_suffix = kwargs['name_suffix']
if isinstance(name_suffix, list):
if len(name_suffix) != 0:
raise InvalidArguments('Array must be empty to signify null.')
raise InvalidArguments('name_suffix array must be empty to signify null.')
else:
if not isinstance(name_suffix, str):
raise InvalidArguments('Name suffix must be a string.')
raise InvalidArguments('name_suffix must be a string.')
self.suffix = name_suffix
if isinstance(self, StaticLibrary):
# You can't disable PIC on OS X. The compiler ignores -fno-PIC.
@ -529,10 +529,13 @@ class BuildTarget():
# since library loading is done differently)
if for_darwin(self.is_cross, self.environment) or for_windows(self.is_cross, self.environment):
self.pic = True
elif '-fPIC' in clist + cpplist:
mlog.log(mlog.red('WARNING:'), "Use the 'pic' kwarg instead of passing -fPIC manually to static library {!r}".format(self.name))
self.pic = True
else:
self.pic = kwargs.get('pic', False)
if not isinstance(self.pic, bool):
raise InvalidArguments('Argument pic must be boolean')
raise InvalidArguments('Argument pic to static library {!r} must be boolean'.format(self.name))
def get_subdir(self):
return self.subdir
@ -634,11 +637,13 @@ by calling get_variable() on the subproject object.''')
if hasattr(t, 'held_object'):
t = t.held_object
if not isinstance(t, (StaticLibrary, SharedLibrary)):
raise InvalidArguments('Link target is not library.')
raise InvalidArguments('Link target {!r} is not library.'.format(t.name))
if isinstance(self, SharedLibrary) and isinstance(t, StaticLibrary) and not t.pic:
raise InvalidArguments("Can't link a non-PIC static library into a shared library")
msg = "Can't link non-PIC static library {!r} into shared library {!r}. ".format(t.name, self.name)
msg += "Use the 'pic' option to static_library to build with PIC."
raise InvalidArguments(msg)
if self.is_cross != t.is_cross:
raise InvalidArguments('Tried to mix cross built and native libraries in target %s.' % self.name)
raise InvalidArguments('Tried to mix cross built and native libraries in target {!r}'.format(self.name))
self.link_targets.append(t)
def set_generated(self, genlist):

@ -1,7 +1,11 @@
project('statchain', 'c')
subdir('subdir')
statlib = static_library('stat', 'stat.c', link_with : shlib, pic : true)
# Test that -fPIC in c_args is also accepted
statlib2 = static_library('stat2', 'stat2.c', c_args : '-fPIC', pic : false)
# Test that pic is needed for both direct and indirect static library
# dependencies of shared libraries (on Linux and BSD)
statlib = static_library('stat', 'stat.c', link_with : [shlib, statlib2], pic : true)
shlib2 = shared_library('shr2', 'shlib2.c', link_with : statlib)
exe = executable('prog', 'prog.c', link_with : shlib2)
test('runtest', exe)

@ -1,7 +1,8 @@
#include "subdir/exports.h"
int statlibfunc(void);
int statlibfunc2(void);
int DLL_PUBLIC shlibfunc2(void) {
return statlibfunc() - 18;
return statlibfunc() - statlibfunc2();
}

@ -0,0 +1,3 @@
int statlibfunc2() {
return 18;
}

@ -32,7 +32,7 @@ enums_h2 = gnome.mkenums('abc2',
enums_c2 = gnome.mkenums('abc2',
sources : 'meson-sample.h',
depends : enums_h2,
depends : [enums_h1, enums_h2],
c_template : 'enums2.c.in',
ftail : '/* trailing source file info */',
install_header : true,

Loading…
Cancel
Save