meson.build 2.41 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
# examples/book/buildapp

# input: gnome, gtkmm_dep, build_examples_by_default, compile_schemas_sh,
#        copy_to_subdir_sh
# input and output: examples_targets

exapp_main = ['exampleapplication.cc', 'exampleappwindow.cc', 'main.cc']
exapp_prefs = exapp_main + \
  ['exampleappprefs.cc', 'exampleapp.gresource.xml', 'org.gtkmm.exampleapp.gschema.xml']

examples_book_buildapp = [
# [[dir-name], exe-name, [sources]]
  [['step1'], 'exampleapp', exapp_main],
  [['step2'], 'exampleapp', exapp_main + ['exampleapp.gresource.xml']],
  [['step3'], 'exampleapp', exapp_main + ['exampleapp.gresource.xml']],
  [['step4'], 'exampleapp', exapp_main + ['exampleapp.gresource.xml']],
  [['step5'], 'exampleapp', exapp_prefs],
  [['step6'], 'exampleapp', exapp_prefs],
  [['step7'], 'exampleapp', exapp_prefs],
  [['step8'], 'exampleapp', exapp_prefs],
  [['step9'], 'exampleapp', exapp_prefs],
]

glib_compile_schemas = find_program('glib-compile-schemas', required: false)

foreach ex : examples_book_buildapp
  dir = ''
  foreach dir_part : ex[0]
    dir = join_paths(dir, dir_part)
  endforeach
  ex_name = join_paths(dir, ex[1]).underscorify()
  ex_sources = []
  resources = []
  schemas = []
  foreach src : ex[2]
    if src.endswith('.gresource.xml')
      resources = gnome.compile_resources(dir.underscorify() + '_resources',
        join_paths(dir, src),
        source_dir: dir
      )
    elif src.endswith('.gschema.xml')
      if glib_compile_schemas.found()
        schemas = custom_target(dir.underscorify() + '_schemas',
          input: join_paths(dir, src),
          output: dir.underscorify() + '_gschemas.compiled',
          command: [
            compile_schemas_sh,
            dir,
            meson.current_source_dir(),
            meson.current_build_dir(),            
            '@OUTPUT@'
          ]
        )
      endif
    else
      ex_sources += join_paths(dir, src)
    endif
  endforeach

  exe_file = executable(ex_name, ex_sources, resources, schemas,
    dependencies: gtkmm_dep,
    gui_app: true,
    build_by_default: build_examples_by_default
  )

  stamp_file_name = ex_name + '_copy.stamp'
  custom_target(stamp_file_name,
    input: exe_file,
    output: stamp_file_name,
    command: [
      copy_to_subdir_sh,
      '@INPUT@',
      dir,
      ex[1],
      '@OUTPUT@',
    ],
    build_by_default: build_examples_by_default
  )

  examples_targets += join_paths('examples', 'book', 'buildapp', stamp_file_name)
endforeach