Repository: mesonbuild/meson

Issue:
Allow installation of output header (-H) for Vala library targets
Currently it is unconditionally named after the library itself, but this is not always what people want. For instance in #890, @grindhold names the library `libhttpseverywhere-0.2`, but the header is called `libhttpseverywhere.h`.

Found while investigating #890



Discussion:
I already suggested that we add `vala_gir` (see #634), `vala_header` and `vala_vapi` to customize the generated files (beside naming them from the target).

Also, we typically want the header subdirectory to follow the target name, not its content.


Resolving patch:
diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py
--- a/mesonbuild/backend/ninjabackend.py
+++ b/mesonbuild/backend/ninjabackend.py
@@ -992,15 +992,14 @@ def generate_vala_compile(self, target, outfile):
             # Library name
             args += ['--library=' + target.name]
             # Outputted header
-            hname = os.path.join(self.get_target_dir(target), target.name + '.h')
+            hname = os.path.join(self.get_target_dir(target), target.vala_header)
             args += ['-H', hname]
             valac_outputs.append(hname)
             # Outputted vapi file
-            base_vapi = target.name + '.vapi'
-            vapiname = os.path.join(self.get_target_dir(target), base_vapi)
+            vapiname = os.path.join(self.get_target_dir(target), target.vala_vapi)
             # Force valac to write the vapi file in the target build dir.
             # Without this, it will write it inside c_out_dir
-            args += ['--vapi=../' + base_vapi]
+            args += ['--vapi', os.path.join('..', target.vala_vapi)]
             valac_outputs.append(vapiname)
         if self.environment.coredata.get_builtin_option('werror'):
             args += valac.get_werror_args()
diff --git a/mesonbuild/build.py b/mesonbuild/build.py
--- a/mesonbuild/build.py
+++ b/mesonbuild/build.py
@@ -55,6 +55,8 @@
                          'name_prefix' : True,
                          'name_suffix' : True,
                          'vs_module_defs' : True, # Only for shared libs
+                         'vala_header': True,
+                         'vala_vapi': True,
                          'pic' : True, # Only for static libs
                         })
 
@@ -449,6 +451,9 @@ def process_kwargs(self, kwargs, environment):
         if not isinstance(valalist, list):
             valalist = [valalist]
         self.add_compiler_args('vala', valalist)
+        if not isinstance(self, Executable):
+            self.vala_header = kwargs.get('vala_header', self.name + '.h')
+            self.vala_vapi = kwargs.get('vala_vapi', self.name + '.vapi')
         dlist = stringlistify(kwargs.get('d_args', []))
         self.add_compiler_args('d', dlist)
         self.link_args = kwargs.get('link_args', [])


Test patch:
diff --git a/test cases/vala/12 custom output/foo.vala b/test cases/vala/12 custom output/foo.vala
new file mode 100644
diff --git a/test cases/vala/12 custom output/meson.build b/test cases/vala/12 custom output/meson.build
new file mode 100644
--- /dev/null
+++ b/test cases/vala/12 custom output/meson.build	
@@ -0,0 +1,9 @@
+project('valatest', 'c', 'vala')
+
+glib = dependency('glib-2.0')
+gobject = dependency('gobject-2.0')
+
+library('foo-1.0', 'foo.vala',
+        vala_header: 'foo.h',
+        vala_vapi: 'foo.vapi',
+        dependencies: [glib, gobject])