diff options
author | Jon Turney <jon.turney@dronecode.org.uk> | 2018-09-30 16:43:32 +0100 |
---|---|---|
committer | Jon Turney <jon.turney@dronecode.org.uk> | 2018-10-01 21:30:45 +0100 |
commit | d769de316d311fbb672abba678c0e2043e93b0c8 (patch) | |
tree | e75992cf6e109bf1b2bc53b7c37f2abda956a9bb /mesonbuild/modules/windows.py | |
parent | dc7bb37c465822b3918c7d4d942b4b32ed66d155 (diff) | |
download | meson-d769de316d311fbb672abba678c0e2043e93b0c8.zip meson-d769de316d311fbb672abba678c0e2043e93b0c8.tar.gz meson-d769de316d311fbb672abba678c0e2043e93b0c8.tar.bz2 |
Factor out windows resource compiler determination
Factor out determination of the windows resource compiler as
_find_resource_compiler(). Cache the result, so the work is only done once.
Diffstat (limited to 'mesonbuild/modules/windows.py')
-rw-r--r-- | mesonbuild/modules/windows.py | 42 |
1 files changed, 25 insertions, 17 deletions
diff --git a/mesonbuild/modules/windows.py b/mesonbuild/modules/windows.py index 59e845c..17cb875 100644 --- a/mesonbuild/modules/windows.py +++ b/mesonbuild/modules/windows.py @@ -32,26 +32,14 @@ class WindowsModule(ExtensionModule): return compilers[l] raise MesonException('Resource compilation requires a C or C++ compiler.') - @FeatureNewKwargs('windows.compile_resources', '0.47.0', ['depend_files', 'depends']) - @permittedKwargs({'args', 'include_directories', 'depend_files', 'depends'}) - def compile_resources(self, state, args, kwargs): - comp = self.detect_compiler(state.compilers) + def _find_resource_compiler(self, state): + # FIXME: Does not handle `native: true` executables, see + # See https://github.com/mesonbuild/meson/issues/1531 - extra_args = mesonlib.stringlistify(kwargs.get('args', [])) - wrc_depend_files = extract_as_list(kwargs, 'depend_files', pop = True) - wrc_depends = extract_as_list(kwargs, 'depends', pop = True) - for d in wrc_depends: - if isinstance(d, CustomTargetHolder): - extra_args += get_include_args([d.outdir_include()]) - inc_dirs = extract_as_list(kwargs, 'include_directories', pop = True) - for incd in inc_dirs: - if not isinstance(incd.held_object, (str, build.IncludeDirs)): - raise MesonException('Resource include dirs should be include_directories().') - extra_args += get_include_args(inc_dirs) + if hasattr(self, '_rescomp'): + return self._rescomp 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. @@ -65,6 +53,7 @@ class WindowsModule(ExtensionModule): rescomp = ExternalProgram('windres', command=os.environ.get('WINDRES'), silent=True) if not rescomp or not rescomp.found(): + comp = self.detect_compiler(state.compilers) if comp.id == 'msvc': rescomp = ExternalProgram('rc', silent=True) else: @@ -73,6 +62,25 @@ class WindowsModule(ExtensionModule): if not rescomp.found(): raise MesonException('Could not find Windows resource compiler') + self._rescomp = rescomp + return self._rescomp + + @FeatureNewKwargs('windows.compile_resources', '0.47.0', ['depend_files', 'depends']) + @permittedKwargs({'args', 'include_directories', 'depend_files', 'depends'}) + def compile_resources(self, state, args, kwargs): + extra_args = mesonlib.stringlistify(kwargs.get('args', [])) + wrc_depend_files = extract_as_list(kwargs, 'depend_files', pop = True) + wrc_depends = extract_as_list(kwargs, 'depends', pop = True) + for d in wrc_depends: + if isinstance(d, CustomTargetHolder): + extra_args += get_include_args([d.outdir_include()]) + inc_dirs = extract_as_list(kwargs, 'include_directories', pop = True) + for incd in inc_dirs: + if not isinstance(incd.held_object, (str, build.IncludeDirs)): + 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(): # RC is used to generate .res files, a special binary resource # format, which can be passed directly to LINK (apparently LINK uses |