aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Turney <jon.turney@dronecode.org.uk>2018-08-31 15:51:18 +0100
committerJussi Pakkanen <jpakkane@gmail.com>2018-09-10 21:03:41 +0300
commit654101414c873d1ccc7d1c96a3123e27aa0aa0f4 (patch)
treed9f0ad980958a36f5d13beaf7474c64fc127df62
parent39d87269b31e64cfdfb32706236ca84329dbfca4 (diff)
downloadmeson-654101414c873d1ccc7d1c96a3123e27aa0aa0f4.zip
meson-654101414c873d1ccc7d1c96a3123e27aa0aa0f4.tar.gz
meson-654101414c873d1ccc7d1c96a3123e27aa0aa0f4.tar.bz2
Improve windows resource compiler executable selection
Always honour any windres setting in cross-file (we can't be compiling with msvc, but this should apply when cross-compiling using gcc or clang) Always honour WINDRES environment variable Otherwise look for the resource compiler which is part of the same toolset as the C or C++ compiler. Add some commentary on why the conventions for compiled resource file extensions differ between RC and windres Also don't try to report non-existent path when we couldn't find the resource compiler.
-rw-r--r--docs/markdown/Windows-module.md7
-rw-r--r--mesonbuild/modules/windows.py56
2 files changed, 42 insertions, 21 deletions
diff --git a/docs/markdown/Windows-module.md b/docs/markdown/Windows-module.md
index 39f1ba6..8c01a41 100644
--- a/docs/markdown/Windows-module.md
+++ b/docs/markdown/Windows-module.md
@@ -21,3 +21,10 @@ has the following keyword argument.
- `include_directories` lists directories to be both searched by the resource
compiler for referenced resource files, and added to the preprocessor include
search path.
+
+The resource compiler executable used is the first which exists from the
+following list:
+
+1. The `windres` executable given in the `[binaries]` section of the cross-file
+2. The `WINDRES` environment variable
+3. The resource compiler which is part of the same toolset as the C or C++ compiler in use.
diff --git a/mesonbuild/modules/windows.py b/mesonbuild/modules/windows.py
index 87209d6..59e845c 100644
--- a/mesonbuild/modules/windows.py
+++ b/mesonbuild/modules/windows.py
@@ -49,33 +49,47 @@ class WindowsModule(ExtensionModule):
raise MesonException('Resource include dirs should be include_directories().')
extra_args += get_include_args(inc_dirs)
- if comp.id == 'msvc':
- rescomp = ExternalProgram('rc', silent=True)
- res_args = extra_args + ['/nologo', '/fo@OUTPUT@', '@INPUT@']
+ rescomp = None
+ # FIXME: Does not handle `native: true` executables, see
+ # https://github.com/mesonbuild/meson/issues/1531
+ if state.environment.is_cross_build():
+ # If cross compiling see if windres has been specified in the
+ # cross file before trying to find it another way.
+ cross_info = state.environment.cross_info
+ rescomp = ExternalProgram.from_cross_info(cross_info, 'windres')
+
+ if not rescomp or not rescomp.found():
+ if 'WINDRES' in os.environ:
+ # Pick-up env var WINDRES if set. This is often used for
+ # specifying an arch-specific windres.
+ rescomp = ExternalProgram('windres', command=os.environ.get('WINDRES'), silent=True)
+
+ if not rescomp or not rescomp.found():
+ if comp.id == 'msvc':
+ rescomp = ExternalProgram('rc', silent=True)
+ else:
+ rescomp = ExternalProgram('windres', silent=True)
+
+ if not rescomp.found():
+ raise MesonException('Could not find Windows resource compiler')
+
+ if 'rc' in rescomp.get_path():
+ # RC is used to generate .res files, a special binary resource
+ # format, which can be passed directly to LINK (apparently LINK uses
+ # CVTRES internally to convert this to a COFF object)
suffix = 'res'
+ res_args = extra_args + ['/nologo', '/fo@OUTPUT@', '@INPUT@']
else:
+ # ld only supports object files, so windres is used to generate a
+ # COFF object
+ suffix = 'o'
+ res_args = extra_args + ['@INPUT@', '@OUTPUT@']
+
m = 'Argument {!r} has a space which may not work with windres due to ' \
'a MinGW bug: https://sourceware.org/bugzilla/show_bug.cgi?id=4933'
for arg in extra_args:
if ' ' in arg:
mlog.warning(m.format(arg))
- rescomp = None
- # FIXME: Does not handle `native: true` executables, see
- # https://github.com/mesonbuild/meson/issues/1531
- if state.environment.is_cross_build():
- # If cross compiling see if windres has been specified in the
- # cross file before trying to find it another way.
- cross_info = state.environment.cross_info
- rescomp = ExternalProgram.from_cross_info(cross_info, 'windres')
- if not rescomp or not rescomp.found():
- # Pick-up env var WINDRES if set. This is often used for
- # specifying an arch-specific windres.
- rescomp = ExternalProgram(os.environ.get('WINDRES', 'windres'), silent=True)
- res_args = extra_args + ['@INPUT@', '@OUTPUT@']
- suffix = 'o'
- if not rescomp.found():
- raise MesonException('Could not find Windows resource compiler {!r}'
- ''.format(rescomp.get_path()))
res_targets = []
@@ -115,7 +129,7 @@ class WindowsModule(ExtensionModule):
}
# instruct binutils windres to generate a preprocessor depfile
- if comp.id != 'msvc':
+ if 'windres' in rescomp.get_path():
res_kwargs['depfile'] = res_kwargs['output'] + '.d'
res_kwargs['command'] += ['--preprocessor-arg=-MD', '--preprocessor-arg=-MQ@OUTPUT@', '--preprocessor-arg=-MF@DEPFILE@']