Repository: mesonbuild/meson

Issue:
gnome.mkenums_simple() installs the generated C source file
The following snippet:

```meson
enum_sources = gnome.mkenums_simple(
  'dm-enums', install_header: true,
  install_dir: join_paths(get_option('includedir'), api_name),
  sources: installed_headers,
)
```

Will result in `dm-enums.c` being installed in the include directory:

```
Installing dmodel/dm-enums.c to /usr/include/dmodel-0/dm-enums.c
Installing dmodel/dm-enums.h to /usr/include/dmodel-0/dm-enums.h
```



Discussion:
Tested with Meson 0.44.1 and 0.45.1.

Full code base available [here](https://github.com/endlessm/libdmodel), but I'll try to come up with a smaller reproducer.
The issue is that `gnome.mkenums_simple()` will not use template files; this leads to this block:

```py3
         if c_template is None and h_template is None:
             generic_cmd = cmd + ['@INPUT@']
             custom_kwargs['install'] = install_header
             if 'install_dir' not in custom_kwargs:
                 custom_kwargs['install_dir'] = \
                     state.environment.coredata.get_builtin_option('includedir')
             target = self._make_mkenum_custom_target(state, sources, basename,
                                                      generic_cmd, custom_kwargs)
             return ModuleReturnValue(target, [target])
```

The `install` custom argument is set to `install_header`, which is `True` for both the C source and the C header targets.

The `gnome.mkenums_simple()` wrapper does:

```py3
c_file_kwargs = copy.deepcopy(mkenums_kwargs)
```

But it should always remove `install_header` from the `mkenums_kwargs` if it finds it.

Resolving patch:
diff --git a/mesonbuild/modules/gnome.py b/mesonbuild/modules/gnome.py
--- a/mesonbuild/modules/gnome.py
+++ b/mesonbuild/modules/gnome.py
@@ -1046,6 +1046,12 @@ def mkenums_simple(self, state, args, kwargs):
             raise MesonException(
                 'Sources keyword argument must be a string or array.')
 
+        # The `install_header` argument will be used by mkenums() when
+        # not using template files, so we need to forcibly unset it
+        # when generating the C source file, otherwise we will end up
+        # installing it
+        c_file_kwargs['install_header'] = False
+
         header_prefix = kwargs.get('header_prefix', '')
         decl_decorator = kwargs.get('decorator', '')
         func_prefix = kwargs.get('function_prefix', '')


Test patch:
diff --git a/test cases/frameworks/7 gnome/installed_files.txt b/test cases/frameworks/7 gnome/installed_files.txt
--- a/test cases/frameworks/7 gnome/installed_files.txt	
+++ b/test cases/frameworks/7 gnome/installed_files.txt	
@@ -1,6 +1,7 @@
 usr/include/enums.h
 usr/include/enums2.h
 usr/include/enums3.h
+usr/include/enums5.h
 usr/include/marshaller.h
 usr/lib/?libgir_lib.so
 usr/lib/?libdep1lib.so
diff --git a/test cases/frameworks/7 gnome/mkenums/meson.build b/test cases/frameworks/7 gnome/mkenums/meson.build
--- a/test cases/frameworks/7 gnome/mkenums/meson.build	
+++ b/test cases/frameworks/7 gnome/mkenums/meson.build	
@@ -123,6 +123,7 @@ enums4 = gnome.mkenums_simple('enums4', sources : 'meson-sample.h',
 enumexe4 = executable('enumprog4', 'main4.c', enums4, dependencies : gobj)
 
 enums5 = gnome.mkenums_simple('enums5', sources : 'meson-sample.h',
+                              install_header : true,
                               decorator : 'MESON_EXPORT',
                               header_prefix : '#include "meson-decls.h"')
 enumexe5 = executable('enumprog5', main, enums5, dependencies : gobj)