aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/markdown/Pkgconfig-module.md1
-rw-r--r--docs/markdown/Release-notes-for-0.42.0.md13
-rw-r--r--mesonbuild/backend/ninjabackend.py19
-rw-r--r--mesonbuild/interpreter.py6
-rw-r--r--mesonbuild/modules/pkgconfig.py10
-rw-r--r--test cases/common/146 C and CPP link/meson.build4
-rw-r--r--test cases/swift/6 modulemap/main.swift5
-rw-r--r--test cases/swift/6 modulemap/meson.build8
-rw-r--r--test cases/swift/6 modulemap/module.modulemap5
-rw-r--r--test cases/swift/6 modulemap/mylib.c5
-rw-r--r--test cases/swift/6 modulemap/mylib.h3
-rw-r--r--test cases/swift/7 modulemap subdir/main.swift5
-rw-r--r--test cases/swift/7 modulemap subdir/meson.build6
-rw-r--r--test cases/swift/7 modulemap subdir/mylib/meson.build4
-rw-r--r--test cases/swift/7 modulemap subdir/mylib/module.modulemap5
-rw-r--r--test cases/swift/7 modulemap subdir/mylib/mylib.c5
-rw-r--r--test cases/swift/7 modulemap subdir/mylib/mylib.h3
17 files changed, 102 insertions, 5 deletions
diff --git a/docs/markdown/Pkgconfig-module.md b/docs/markdown/Pkgconfig-module.md
index 6b9a968..2424421 100644
--- a/docs/markdown/Pkgconfig-module.md
+++ b/docs/markdown/Pkgconfig-module.md
@@ -20,4 +20,5 @@ The generated file's properties are specified with the following keyword argumen
- `requires_private` list of strings to put in the `Requires.private` field
- `libraries_private` list of strings to put in the `Libraries.private` field
- `install_dir` the directory to install to, defaults to the value of option `libdir` followed by `/pkgconfig`
+- `extra_cflags` a list of extra compiler flags to be added to the `Cflags` field after the header search path
- `variables` a list of strings with custom variables to add to the generated file. The strings must be in the form `name=value` and may reference other pkgconfig variables, e.g. `datadir=${prefix}/share`. The names `prefix`, `libdir` and `installdir` are reserved and may not be used.
diff --git a/docs/markdown/Release-notes-for-0.42.0.md b/docs/markdown/Release-notes-for-0.42.0.md
index 4b8fbe3..ea9d7b1 100644
--- a/docs/markdown/Release-notes-for-0.42.0.md
+++ b/docs/markdown/Release-notes-for-0.42.0.md
@@ -23,3 +23,16 @@ future this will become a hard error.
The Vala compiler has an alternative syntax, Genie, that uses the `.gs`
file extension. Meson now recognises and uses Genie files.
+## Pkgconfig support for additional cflags
+
+The Pkgconfig module object can add arbitrary extra cflags to the Cflags
+value in the .pc file, using the "extra_cflags" keyword:
+```meson
+pkg.generate(libraries : libs,
+ subdirs : h,
+ version : '1.0',
+ name : 'libsimple',
+ filebase : 'simple',
+ description : 'A simple demo library.',
+ extra_cflags : '-Dfoo' )
+```
diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py
index 61b5f18..7f974ee 100644
--- a/mesonbuild/backend/ninjabackend.py
+++ b/mesonbuild/backend/ninjabackend.py
@@ -1290,7 +1290,21 @@ int dummy;
os.makedirs(self.get_target_private_dir_abs(target), exist_ok=True)
compile_args = swiftc.get_compile_only_args()
compile_args += swiftc.get_module_args(module_name)
+ compile_args += self.build.get_project_args(swiftc, target.subproject)
+ compile_args += self.build.get_global_args(swiftc)
+ for i in reversed(target.get_include_dirs()):
+ basedir = i.get_curdir()
+ for d in i.get_incdirs():
+ if d not in ('', '.'):
+ expdir = os.path.join(basedir, d)
+ else:
+ expdir = basedir
+ srctreedir = os.path.normpath(os.path.join(self.environment.get_build_dir(), self.build_to_src, expdir))
+ sargs = swiftc.get_include_args(srctreedir)
+ compile_args += sargs
link_args = swiftc.get_output_args(os.path.join(self.environment.get_build_dir(), self.get_target_filename(target)))
+ link_args += self.build.get_project_link_args(swiftc, target.subproject)
+ link_args += self.build.get_global_link_args(swiftc)
rundir = self.get_target_private_dir(target)
out_module_name = self.swift_module_file_name(target)
in_module_files = self.determine_swift_dep_modules(target)
@@ -1300,6 +1314,11 @@ int dummy;
module_includes += swiftc.get_include_args(x)
link_deps = self.get_swift_link_deps(target)
abs_link_deps = [os.path.join(self.environment.get_build_dir(), x) for x in link_deps]
+ for d in target.link_targets:
+ reldir = self.get_target_dir(d)
+ if reldir == '':
+ reldir = '.'
+ link_args += ['-L', os.path.normpath(os.path.join(self.environment.get_build_dir(), reldir))]
(rel_generated, _) = self.split_swift_generated_sources(target)
abs_generated = [os.path.join(self.environment.get_build_dir(), x) for x in rel_generated]
# We need absolute paths because swiftc needs to be invoked in a subdir
diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py
index 916529f..13c3119 100644
--- a/mesonbuild/interpreter.py
+++ b/mesonbuild/interpreter.py
@@ -1273,6 +1273,8 @@ build_target_kwargs = exe_kwargs.copy()
build_target_kwargs.update(['target_type'])
permitted_kwargs = {'add_global_arguments': {'language'},
+ 'add_global_link_arguments': {'language'},
+ 'add_project_link_arguments': {'language'},
'add_languages': {'required'},
'add_project_arguments': {'language'},
'add_test_setup': {'exe_wrapper', 'gdb', 'timeout_multiplier', 'env'},
@@ -2602,7 +2604,7 @@ different subdirectory.
def func_add_global_arguments(self, node, args, kwargs):
self.add_global_arguments(node, self.build.global_args, args, kwargs)
- @noKwargs
+ @permittedKwargs(permitted_kwargs['add_global_link_arguments'])
@stringArgs
def func_add_global_link_arguments(self, node, args, kwargs):
self.add_global_arguments(node, self.build.global_link_args, args, kwargs)
@@ -2612,7 +2614,7 @@ different subdirectory.
def func_add_project_arguments(self, node, args, kwargs):
self.add_project_arguments(node, self.build.projects_args, args, kwargs)
- @noKwargs
+ @permittedKwargs(permitted_kwargs['add_project_link_arguments'])
@stringArgs
def func_add_project_link_arguments(self, node, args, kwargs):
self.add_project_arguments(node, self.build.projects_link_args, args, kwargs)
diff --git a/mesonbuild/modules/pkgconfig.py b/mesonbuild/modules/pkgconfig.py
index 7b0bb83..2dfdbc0 100644
--- a/mesonbuild/modules/pkgconfig.py
+++ b/mesonbuild/modules/pkgconfig.py
@@ -44,7 +44,7 @@ class PkgConfigModule(ExtensionModule):
def generate_pkgconfig_file(self, state, libraries, subdirs, name, description,
url, version, pcfile, pub_reqs, priv_reqs,
- conflicts, priv_libs, variables):
+ conflicts, priv_libs, extra_cflags, variables):
coredata = state.environment.get_coredata()
outdir = state.environment.scratch_dir
fname = os.path.join(outdir, pcfile)
@@ -101,6 +101,9 @@ class PkgConfigModule(ExtensionModule):
h = ''
ofile.write(' ')
ofile.write(os.path.join('-I${includedir}', h))
+ for f in extra_cflags:
+ ofile.write(' ')
+ ofile.write(f)
ofile.write('\n')
def process_libs(self, libs):
@@ -117,7 +120,7 @@ class PkgConfigModule(ExtensionModule):
@permittedKwargs({'libraries', 'version', 'name', 'description', 'filebase',
'subdirs', 'requires', 'requires_private', 'libraries_private',
- 'install_dir', 'variables'})
+ 'install_dir', 'extra_cflags', 'variables'})
def generate(self, state, args, kwargs):
if len(args) > 0:
raise mesonlib.MesonException('Pkgconfig_gen takes no positional arguments.')
@@ -142,6 +145,7 @@ class PkgConfigModule(ExtensionModule):
pub_reqs = mesonlib.stringlistify(kwargs.get('requires', []))
priv_reqs = mesonlib.stringlistify(kwargs.get('requires_private', []))
conflicts = mesonlib.stringlistify(kwargs.get('conflicts', []))
+ extra_cflags = mesonlib.stringlistify(kwargs.get('extra_cflags', []))
def parse_variable_list(stringlist):
reserved = ['prefix', 'libdir', 'includedir']
@@ -177,7 +181,7 @@ class PkgConfigModule(ExtensionModule):
raise mesonlib.MesonException('Install_dir must be a string.')
self.generate_pkgconfig_file(state, libs, subdirs, name, description, url,
version, pcfile, pub_reqs, priv_reqs,
- conflicts, priv_libs, variables)
+ conflicts, priv_libs, extra_cflags, variables)
res = build.Data(mesonlib.File(True, state.environment.get_scratch_dir(), pcfile), pkgroot)
return ModuleReturnValue(res, [res])
diff --git a/test cases/common/146 C and CPP link/meson.build b/test cases/common/146 C and CPP link/meson.build
index 583bd54..af40de7 100644
--- a/test cases/common/146 C and CPP link/meson.build
+++ b/test cases/common/146 C and CPP link/meson.build
@@ -14,6 +14,10 @@
project('C and C++ static link test', ['c', 'cpp'])
+# Verify that adding link arguments works.
+add_global_link_arguments('', language : 'c')
+add_project_link_arguments('', language : 'c')
+
libc = static_library('cfoo', ['foo.c', 'foo.h'])
# Test that linking C libs to external static C++ libs uses the C++ linker
diff --git a/test cases/swift/6 modulemap/main.swift b/test cases/swift/6 modulemap/main.swift
new file mode 100644
index 0000000..1a38c25
--- /dev/null
+++ b/test cases/swift/6 modulemap/main.swift
@@ -0,0 +1,5 @@
+import mylib
+
+let num = getNumber()
+
+print("The number returned from C code is: \(num).")
diff --git a/test cases/swift/6 modulemap/meson.build b/test cases/swift/6 modulemap/meson.build
new file mode 100644
index 0000000..f1c90db
--- /dev/null
+++ b/test cases/swift/6 modulemap/meson.build
@@ -0,0 +1,8 @@
+project('mixed', 'c', 'swift')
+
+i = include_directories('.')
+lib = static_library('mylib', 'mylib.c')
+exe = executable('prog', 'main.swift',
+ include_directories : [i],
+ link_with : lib)
+test('c module', exe)
diff --git a/test cases/swift/6 modulemap/module.modulemap b/test cases/swift/6 modulemap/module.modulemap
new file mode 100644
index 0000000..5aab62e
--- /dev/null
+++ b/test cases/swift/6 modulemap/module.modulemap
@@ -0,0 +1,5 @@
+module mylib [extern_c] {
+ header "mylib.h"
+ link "mylib"
+ export *
+}
diff --git a/test cases/swift/6 modulemap/mylib.c b/test cases/swift/6 modulemap/mylib.c
new file mode 100644
index 0000000..e091836
--- /dev/null
+++ b/test cases/swift/6 modulemap/mylib.c
@@ -0,0 +1,5 @@
+#include"mylib.h"
+
+int getNumber() {
+ return 42;
+}
diff --git a/test cases/swift/6 modulemap/mylib.h b/test cases/swift/6 modulemap/mylib.h
new file mode 100644
index 0000000..21bd9eb
--- /dev/null
+++ b/test cases/swift/6 modulemap/mylib.h
@@ -0,0 +1,3 @@
+#pragma once
+
+int getNumber();
diff --git a/test cases/swift/7 modulemap subdir/main.swift b/test cases/swift/7 modulemap subdir/main.swift
new file mode 100644
index 0000000..1a38c25
--- /dev/null
+++ b/test cases/swift/7 modulemap subdir/main.swift
@@ -0,0 +1,5 @@
+import mylib
+
+let num = getNumber()
+
+print("The number returned from C code is: \(num).")
diff --git a/test cases/swift/7 modulemap subdir/meson.build b/test cases/swift/7 modulemap subdir/meson.build
new file mode 100644
index 0000000..cd769eb
--- /dev/null
+++ b/test cases/swift/7 modulemap subdir/meson.build
@@ -0,0 +1,6 @@
+project('mixed', 'c', 'swift')
+add_project_arguments('-embed-bitcode', language : 'swift')
+subdir('mylib')
+exe = executable('prog', 'main.swift',
+ dependencies : dep)
+test('c module', exe)
diff --git a/test cases/swift/7 modulemap subdir/mylib/meson.build b/test cases/swift/7 modulemap subdir/mylib/meson.build
new file mode 100644
index 0000000..2549e2b
--- /dev/null
+++ b/test cases/swift/7 modulemap subdir/mylib/meson.build
@@ -0,0 +1,4 @@
+
+i = include_directories('.')
+lib = static_library('mylib', 'mylib.c')
+dep = declare_dependency(include_directories : i, link_with : lib)
diff --git a/test cases/swift/7 modulemap subdir/mylib/module.modulemap b/test cases/swift/7 modulemap subdir/mylib/module.modulemap
new file mode 100644
index 0000000..5aab62e
--- /dev/null
+++ b/test cases/swift/7 modulemap subdir/mylib/module.modulemap
@@ -0,0 +1,5 @@
+module mylib [extern_c] {
+ header "mylib.h"
+ link "mylib"
+ export *
+}
diff --git a/test cases/swift/7 modulemap subdir/mylib/mylib.c b/test cases/swift/7 modulemap subdir/mylib/mylib.c
new file mode 100644
index 0000000..e091836
--- /dev/null
+++ b/test cases/swift/7 modulemap subdir/mylib/mylib.c
@@ -0,0 +1,5 @@
+#include"mylib.h"
+
+int getNumber() {
+ return 42;
+}
diff --git a/test cases/swift/7 modulemap subdir/mylib/mylib.h b/test cases/swift/7 modulemap subdir/mylib/mylib.h
new file mode 100644
index 0000000..21bd9eb
--- /dev/null
+++ b/test cases/swift/7 modulemap subdir/mylib/mylib.h
@@ -0,0 +1,3 @@
+#pragma once
+
+int getNumber();