diff options
author | Jon Turney <jon.turney@dronecode.org.uk> | 2018-09-30 17:11:11 +0100 |
---|---|---|
committer | Jon Turney <jon.turney@dronecode.org.uk> | 2018-10-02 13:19:08 +0100 |
commit | d0acada1d5f7ef16b8ec34d5cbb924190051a310 (patch) | |
tree | b8cf95faf1281039fd7700c628db706ccbe45a59 | |
parent | d769de316d311fbb672abba678c0e2043e93b0c8 (diff) | |
download | meson-d0acada1d5f7ef16b8ec34d5cbb924190051a310.tar.gz |
Probe Windows resource compiler type
Determine the type of the Windows resource compiler by looking at its
output, not its name.
Also log the name and version of the resource compiler we are using.
-rw-r--r-- | mesonbuild/modules/windows.py | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/mesonbuild/modules/windows.py b/mesonbuild/modules/windows.py index 17cb87524..f0d5113f8 100644 --- a/mesonbuild/modules/windows.py +++ b/mesonbuild/modules/windows.py @@ -12,7 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. +import enum import os +import re from .. import mlog from .. import mesonlib, build @@ -24,6 +26,10 @@ from ..interpreter import CustomTargetHolder from ..interpreterbase import permittedKwargs, FeatureNewKwargs from ..dependencies import ExternalProgram +class ResourceCompilerType(enum.Enum): + windres = 1 + rc = 2 + class WindowsModule(ExtensionModule): def detect_compiler(self, compilers): @@ -62,7 +68,19 @@ class WindowsModule(ExtensionModule): if not rescomp.found(): raise MesonException('Could not find Windows resource compiler') - self._rescomp = rescomp + for (arg, match, type) in [ + ('/?', '^.*Microsoft.*Resource Compiler.*$', ResourceCompilerType.rc), + ('--version', '^.*GNU windres.*$', ResourceCompilerType.windres), + ]: + p, o, e = mesonlib.Popen_safe(rescomp.get_command() + [arg]) + m = re.search(match, o, re.MULTILINE) + if m: + mlog.log('Windows resource compiler: %s' % m.group()) + self._rescomp = (rescomp, type) + break + else: + raise MesonException('Could not determine type of Windows resource compiler') + return self._rescomp @FeatureNewKwargs('windows.compile_resources', '0.47.0', ['depend_files', 'depends']) @@ -80,8 +98,8 @@ class WindowsModule(ExtensionModule): raise MesonException('Resource include dirs should be include_directories().') extra_args += get_include_args(inc_dirs) - rescomp = self._find_resource_compiler(state) - if 'rc' in rescomp.get_path(): + rescomp, rescomp_type = self._find_resource_compiler(state) + if rescomp_type == ResourceCompilerType.rc: # 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) @@ -137,7 +155,7 @@ class WindowsModule(ExtensionModule): } # instruct binutils windres to generate a preprocessor depfile - if 'windres' in rescomp.get_path(): + if rescomp_type == ResourceCompilerType.windres: res_kwargs['depfile'] = res_kwargs['output'] + '.d' res_kwargs['command'] += ['--preprocessor-arg=-MD', '--preprocessor-arg=-MQ@OUTPUT@', '--preprocessor-arg=-MF@DEPFILE@'] |