meson.build 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. # Generate both header and source via template together.
  2. myenums = gnome.mkenums('abc1',
  3. sources : 'meson-sample.h',
  4. h_template : 'enums.h.in',
  5. c_template : 'enums.c.in',
  6. install_header : true,
  7. install_dir : get_option('includedir'))
  8. enums_c1 = myenums[0]
  9. enums_h1 = myenums[1]
  10. conf = configuration_data()
  11. conf.set('ENUM_FILE', 'enums.h')
  12. main = configure_file(
  13. input : 'main.c',
  14. output : 'main1.c',
  15. configuration : conf)
  16. enumexe1 = executable('enumprog1', main, enums_c1, enums_h1,
  17. dependencies : gobj)
  18. test('enum test 1', enumexe1)
  19. # Generate both header and source via template individually and overriding.
  20. enums_h2 = gnome.mkenums('abc2',
  21. sources : 'meson-sample.h',
  22. h_template : 'enums2.h.in',
  23. ftail : '/* trailing header file info */',
  24. install_header : true,
  25. install_dir : get_option('includedir'))
  26. enums_c2 = gnome.mkenums('abc2',
  27. sources : 'meson-sample.h',
  28. depends : [enums_h1, enums_h2],
  29. c_template : 'enums2.c.in',
  30. ftail : '/* trailing source file info */',
  31. install_header : true,
  32. install_dir : get_option('includedir'))
  33. conf = configuration_data()
  34. conf.set('ENUM_FILE', 'enums2.h')
  35. main = configure_file(
  36. input : 'main.c',
  37. output : 'main2.c',
  38. configuration : conf)
  39. enumexe2 = executable('enumprog2', main, enums_c2, enums_h2,
  40. dependencies : gobj)
  41. test('enum test 2', enumexe2)
  42. # Generate both header and source by options only.
  43. # These are specified in a way that should produce the same result as above
  44. # (modulo any filename changes.)
  45. enums_h3 = gnome.mkenums('enums3.h',
  46. sources : 'meson-sample.h',
  47. fhead : '''#ifndef MESON_ENUMS_H
  48. #define MESON_ENUMS_H
  49. #include <glib-object.h>
  50. G_BEGIN_DECLS
  51. ''',
  52. fprod : '''
  53. /* enumerations from "@basename@" */
  54. ''',
  55. vhead : '''GType @enum_name@_get_type(void) G_GNUC_CONST;
  56. #define @ENUMPREFIX@_TYPE_@ENUMSHORT@ (@enum_name@_get_type())
  57. ''',
  58. ftail : '''
  59. G_END_DECLS
  60. #endif /* MESON_ENUMS_H */
  61. ''',
  62. install_header : true,
  63. install_dir : get_option('includedir'))
  64. enums_c3 = gnome.mkenums('enums3.c',
  65. sources : 'meson-sample.h',
  66. depends : enums_h3,
  67. fhead : '''#include "enums3.h"
  68. ''',
  69. fprod : '''
  70. /* enumerations from "@basename@" */
  71. #include "@basename@"
  72. ''',
  73. vhead : '''
  74. GType
  75. @enum_name@_get_type(void) {
  76. static volatile gsize g_define_type_id__volatile = 0;
  77. if(g_once_init_enter(&g_define_type_id__volatile)) {
  78. static const G@Type@Value values [] = {
  79. ''',
  80. vprod : ''' { @VALUENAME@, "@VALUENAME@", "@valuenick@" },''',
  81. vtail : ''' { 0, NULL, NULL }
  82. };
  83. GType g_define_type_id =
  84. g_@type@_register_static(g_intern_static_string("@EnumName@"), values);
  85. g_once_init_leave(&g_define_type_id__volatile, g_define_type_id);
  86. }
  87. return g_define_type_id__volatile;
  88. }
  89. ''')
  90. conf = configuration_data()
  91. conf.set('ENUM_FILE', 'enums3.h')
  92. main = configure_file(
  93. input : 'main.c',
  94. output : 'main3.c',
  95. configuration : conf)
  96. enumexe3 = executable('enumprog3', main, enums_c3, enums_h3,
  97. dependencies : gobj)
  98. test('enum test 3', enumexe3)
  99. enums4 = gnome.mkenums_simple('enums4', sources : 'meson-sample.h',
  100. function_prefix : '_')
  101. enumexe4 = executable('enumprog4', 'main4.c', enums4, dependencies : gobj)
  102. enums5 = gnome.mkenums_simple('enums5', sources : 'meson-sample.h',
  103. decorator : 'MESON_EXPORT',
  104. header_prefix : '#include "meson-decls.h"')
  105. enumexe5 = executable('enumprog5', main, enums5, dependencies : gobj)