aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mesonbuild/backend/backends.py2
-rw-r--r--mesonbuild/build.py28
-rw-r--r--test cases/common/62 exe static shared/meson.build5
-rw-r--r--test cases/common/62 exe static shared/prog.c7
-rw-r--r--test cases/common/62 exe static shared/shlib2.c7
-rw-r--r--test cases/common/62 exe static shared/subdir/exports.h12
-rw-r--r--test cases/common/62 exe static shared/subdir/shlib.c11
7 files changed, 52 insertions, 20 deletions
diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py
index d5af056..16f7ada 100644
--- a/mesonbuild/backend/backends.py
+++ b/mesonbuild/backend/backends.py
@@ -341,6 +341,8 @@ class Backend():
commands += compiler.get_werror_args()
if isinstance(target, build.SharedLibrary):
commands += compiler.get_pic_args()
+ if isinstance(target, build.StaticLibrary) and target.pic:
+ commands += compiler.get_pic_args()
for dep in target.get_external_deps():
# Cflags required by external deps might have UNIX-specific flags,
# so filter them out if needed
diff --git a/mesonbuild/build.py b/mesonbuild/build.py
index 1ef183b..a532509 100644
--- a/mesonbuild/build.py
+++ b/mesonbuild/build.py
@@ -44,12 +44,19 @@ known_basic_kwargs = {'install' : True,
'native' : True,
}
-known_shlib_kwargs = known_basic_kwargs.copy()
-known_shlib_kwargs.update({'version' : True,
- 'soversion' : True,
- 'name_prefix' : True,
- 'name_suffix' : True,
- 'vs_module_defs' : True})
+# These contain kwargs supported by both static and shared libraries. These are
+# combined here because a library() call might be shared_library() or
+# static_library() at runtime based on the configuration.
+# FIXME: Find a way to pass that info down here so we can have proper target
+# kwargs checking when specifically using shared_library() or static_library().
+known_lib_kwargs = known_basic_kwargs.copy()
+known_lib_kwargs.update({'version' : True, # Only for shared libs
+ 'soversion' : True, # Only for shared libs
+ 'name_prefix' : True,
+ 'name_suffix' : True,
+ 'vs_module_defs' : True, # Only for shared libs
+ 'pic' : True, # Only for static libs
+ })
def compilers_are_msvc(compilers):
"""
@@ -516,6 +523,10 @@ class BuildTarget():
if not isinstance(name_suffix, str):
raise InvalidArguments('Name suffix must be a string.')
self.suffix = name_suffix
+ if isinstance(self, StaticLibrary):
+ self.pic = kwargs.get('pic', False)
+ if not isinstance(self.pic, bool):
+ raise InvalidArguments('Argument pic must be boolean')
def get_subdir(self):
return self.subdir
@@ -831,6 +842,9 @@ class StaticLibrary(BuildTarget):
def type_suffix(self):
return "@sta"
+ def check_unknown_kwargs(self, kwargs):
+ self.check_unknown_kwargs_int(kwargs, known_lib_kwargs)
+
class SharedLibrary(BuildTarget):
def __init__(self, name, subdir, subproject, is_cross, sources, objects, environment, kwargs):
self.soversion = None
@@ -988,7 +1002,7 @@ class SharedLibrary(BuildTarget):
self.link_depends.append(path)
def check_unknown_kwargs(self, kwargs):
- self.check_unknown_kwargs_int(kwargs, known_shlib_kwargs)
+ self.check_unknown_kwargs_int(kwargs, known_lib_kwargs)
def get_import_filename(self):
"""
diff --git a/test cases/common/62 exe static shared/meson.build b/test cases/common/62 exe static shared/meson.build
index 3c75391..8631e68 100644
--- a/test cases/common/62 exe static shared/meson.build
+++ b/test cases/common/62 exe static shared/meson.build
@@ -1,6 +1,7 @@
project('statchain', 'c')
subdir('subdir')
-statlib = static_library('stat', 'stat.c', link_with : shlib)
-exe = executable('prog', 'prog.c', link_with : statlib)
+statlib = static_library('stat', 'stat.c', link_with : shlib, pic : true)
+shlib2 = shared_library('shr2', 'shlib2.c', link_with : statlib)
+exe = executable('prog', 'prog.c', link_with : shlib2)
test('runtest', exe)
diff --git a/test cases/common/62 exe static shared/prog.c b/test cases/common/62 exe static shared/prog.c
index 4f82a6b..26603b6 100644
--- a/test cases/common/62 exe static shared/prog.c
+++ b/test cases/common/62 exe static shared/prog.c
@@ -1,5 +1,10 @@
+int shlibfunc2();
int statlibfunc();
int main(int argc, char **argv) {
- return statlibfunc() == 42 ? 0 : 1;
+ if (statlibfunc() != 42)
+ return 1;
+ if (shlibfunc2() != 24)
+ return 1;
+ return 0;
}
diff --git a/test cases/common/62 exe static shared/shlib2.c b/test cases/common/62 exe static shared/shlib2.c
new file mode 100644
index 0000000..e26d11c
--- /dev/null
+++ b/test cases/common/62 exe static shared/shlib2.c
@@ -0,0 +1,7 @@
+#include "subdir/exports.h"
+
+int statlibfunc(void);
+
+int DLL_PUBLIC shlibfunc2(void) {
+ return statlibfunc() - 18;
+}
diff --git a/test cases/common/62 exe static shared/subdir/exports.h b/test cases/common/62 exe static shared/subdir/exports.h
new file mode 100644
index 0000000..c89ccb2
--- /dev/null
+++ b/test cases/common/62 exe static shared/subdir/exports.h
@@ -0,0 +1,12 @@
+#pragma once
+
+#if defined _WIN32 || defined __CYGWIN__
+ #define DLL_PUBLIC __declspec(dllexport)
+#else
+ #if defined __GNUC__
+ #define DLL_PUBLIC __attribute__ ((visibility("default")))
+ #else
+ #pragma message ("Compiler does not support symbol visibility.")
+ #define DLL_PUBLIC
+ #endif
+#endif
diff --git a/test cases/common/62 exe static shared/subdir/shlib.c b/test cases/common/62 exe static shared/subdir/shlib.c
index d649c7d..002c83f 100644
--- a/test cases/common/62 exe static shared/subdir/shlib.c
+++ b/test cases/common/62 exe static shared/subdir/shlib.c
@@ -1,13 +1,4 @@
-#if defined _WIN32 || defined __CYGWIN__
- #define DLL_PUBLIC __declspec(dllexport)
-#else
- #if defined __GNUC__
- #define DLL_PUBLIC __attribute__ ((visibility("default")))
- #else
- #pragma message ("Compiler does not support symbol visibility.")
- #define DLL_PUBLIC
- #endif
-#endif
+#include "exports.h"
int DLL_PUBLIC shlibfunc() {
return 42;