windows.compile_resources: fix compiling multiple resources within one project

pull/2815/head
Andrei Alexeyev 7 years ago
parent ef7cb9f280
commit f8bd1c5ff2
No known key found for this signature in database
GPG Key ID: 363707CD4C7FE8A4
  1. 40
      mesonbuild/modules/windows.py
  2. 1
      test cases/windows/13 resources with custom targets/inc/meson.build
  3. 1
      test cases/windows/13 resources with custom targets/inc/resource/resource.h
  4. 11
      test cases/windows/13 resources with custom targets/meson.build
  5. 23
      test cases/windows/13 resources with custom targets/res/meson.build
  6. 3
      test cases/windows/13 resources with custom targets/res/myres.rc.in
  7. 3
      test cases/windows/13 resources with custom targets/res/myres_static.rc

@ -68,15 +68,41 @@ class WindowsModule(ExtensionModule):
if not rescomp.found():
raise MesonException('Could not find Windows resource compiler %s.' % ' '.join(rescomp.get_command()))
res_kwargs = {
'output': '@BASENAME@.' + suffix,
'input': args,
'command': [rescomp] + res_args,
}
res_targets = []
res_target = build.CustomTarget('Windows resource', state.subdir, state.subproject, res_kwargs)
def add_target(src):
if isinstance(src, list):
for subsrc in src:
add_target(subsrc)
return
return ModuleReturnValue(res_target, [res_target])
if hasattr(src, 'held_object'):
src = src.held_object
res_kwargs = {
'output': '@BASENAME@.' + suffix,
'input': [src],
'command': [rescomp] + res_args,
}
if isinstance(src, (str, mesonlib.File)):
name = 'file {!r}'.format(str(src))
elif isinstance(src, build.CustomTarget):
if len(src.get_outputs()) > 1:
raise MesonException('windows.compile_resources does not accept custom targets with more than 1 output.')
name = 'target {!r}'.format(src.get_id())
else:
raise MesonException('Unexpected source type {!r}. windows.compile_resources accepts only strings, files, custom targets, and lists thereof.'.format(src))
# Path separators are not allowed in target names
name = name.replace('/', '_').replace('\\', '_')
res_targets.append(build.CustomTarget('Windows resource for ' + name, state.subdir, state.subproject, res_kwargs))
add_target(args)
return ModuleReturnValue(res_targets, [res_targets])
def initialize():
return WindowsModule()

@ -59,11 +59,12 @@ if meson.get_compiler('c').get_id() == 'gcc' and host_machine.system() == 'windo
# We hope you never have to implement something like this.
endif
subdir('inc')
subdir('res')
exe = executable('prog', 'prog.c',
res,
gui_app : true)
foreach id : [0, 1, 2]
exe = executable('prog_@0@'.format(id), 'prog.c',
res[id],
gui_app : true)
test('winmain', exe)
test('winmain_@0@'.format(id), exe)
endforeach

@ -2,12 +2,17 @@ win = import('windows')
rc_writer = find_program('./gen-res.py')
rc_target = custom_target('RC source file',
input : 'myres.rc.in',
output : 'myres.rc',
command : [rc_writer, '@INPUT@', '@OUTPUT@', files('sample.ico')],
install : false,
build_always : true)
res = win.compile_resources(rc_target,
include_directories : inc)
rc_sources = []
foreach id : [1, 2]
rc_sources += custom_target('RC source file @0@'.format(id),
input : 'myres.rc.in',
output : 'myres_@0@.rc'.format(id),
command : [rc_writer, '@INPUT@', '@OUTPUT@', files('sample.ico')],
install : false,
build_always : true)
endforeach
rc_sources += files('myres_static.rc')
res = win.compile_resources(rc_sources)

@ -1,4 +1,3 @@
#include<windows.h>
#include"resource.h"
ICON_ID ICON "{icon}"
1 ICON "{icon}"

Loading…
Cancel
Save