Browse code

refactor: Pass application configuration values via a header

Payson Wallach authored on 10/03/2021 20:42:53
Showing 3 changed files

... ...
@@ -7,12 +7,35 @@ project(
7 7
   version: '0.1.0'
8 8
 )
9 9
 
10
+vala = meson.get_compiler('vala')
11
+
12
+vapi_dir = join_paths(meson.source_root(), 'vapi')
13
+
10 14
 glib_dep = dependency('gtk+-3.0')
11 15
 
16
+conf = configuration_data()
17
+conf.set_quoted('APP_ID', meson.project_name())
18
+
19
+config_h = configure_file(
20
+  output: 'config.h',
21
+  configuration: conf
22
+)
23
+
24
+config_dep = declare_dependency(
25
+  dependencies: vala.find_library('config', dirs: vapi_dir),
26
+  sources: config_h
27
+)
28
+
29
+add_project_arguments(
30
+  ['-DG_LOG_DOMAIN="@0@"'.format(meson.project_name())],
31
+  language:'c'
32
+)
33
+
12 34
 executable(
13 35
   meson.project_name(),
14 36
   'src/Main.vala',
15 37
   dependencies: [
38
+    config_dep,
16 39
     glib_dep
17 40
   ],
18 41
   install: true
... ...
@@ -27,8 +27,8 @@ namespace Amber {
27 27
 
28 28
         public Helper () {
29 29
             Object (
30
-                application_id: "com.paysonwallach.amber.helper",
31
-                flags : ApplicationFlags.HANDLES_OPEN);
30
+                application_id: Config.APP_ID,
31
+                flags: ApplicationFlags.HANDLES_OPEN);
32 32
         }
33 33
 
34 34
         public override void open (File[] files, string hint) {
35 35
new file mode 100644
... ...
@@ -0,0 +1,4 @@
1
+[CCode (cprefix = "", lower_case_cprefix = "", cheader_filename = "config.h")]
2
+namespace Config {
3
+    public const string APP_ID;
4
+}