windows.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # Copyright 2015 The Meson development team
  2. # Licensed under the Apache License, Version 2.0 (the "License");
  3. # you may not use this file except in compliance with the License.
  4. # You may obtain a copy of the License at
  5. # http://www.apache.org/licenses/LICENSE-2.0
  6. # Unless required by applicable law or agreed to in writing, software
  7. # distributed under the License is distributed on an "AS IS" BASIS,
  8. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. # See the License for the specific language governing permissions and
  10. # limitations under the License.
  11. from .. import mesonlib, dependencies, build
  12. from ..mesonlib import MesonException
  13. import os
  14. class WindowsModule:
  15. def detect_compiler(self, compilers):
  16. for c in compilers:
  17. if c.language == 'c' or c.language == 'cpp':
  18. return c
  19. raise MesonException('Resource compilation requires a C or C++ compiler.')
  20. def compile_resources(self, state, args, kwargs):
  21. comp = self.detect_compiler(state.compilers)
  22. extra_args = mesonlib.stringlistify(kwargs.get('args', []))
  23. if comp.id == 'msvc':
  24. rescomp = dependencies.ExternalProgram('rc', silent=True)
  25. res_args = extra_args + ['/nologo', '/fo@OUTPUT@', '@INPUT@']
  26. suffix = 'res'
  27. else:
  28. # Pick-up env var WINDRES if set. This is often used for specifying
  29. # an arch-specific windres.
  30. rescomp_name = os.environ.get('WINDRES', 'windres')
  31. rescomp = dependencies.ExternalProgram(rescomp_name, silent=True)
  32. res_args = extra_args + ['@INPUT@', '@OUTPUT@']
  33. suffix = 'o'
  34. if not rescomp.found():
  35. raise MesonException('Could not find Windows resource compiler %s.' % ' '.join(rescomp.get_command()))
  36. res_files = mesonlib.stringlistify(args)
  37. res_kwargs = {'output' : '@BASENAME@.' + suffix,
  38. 'arguments': res_args}
  39. res_gen = build.Generator([rescomp], res_kwargs)
  40. res_output = build.GeneratedList(res_gen)
  41. [res_output.add_file(os.path.join(state.subdir, a)) for a in res_files]
  42. return res_output
  43. def initialize():
  44. return WindowsModule()