diff options
author | Jussi Pakkanen <jpakkane@gmail.com> | 2019-11-28 13:15:51 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-11-28 13:15:51 +0200 |
commit | 575a2c34f811dc003caf415d5343f524c5c8e802 (patch) | |
tree | 02f9f31d088151d769a9cf6b566b74d3b14a31ce /mesonbuild/cmake/traceparser.py | |
parent | bb03cf0dbc7158fd0684047272869abd565e4951 (diff) | |
parent | 82df046bc17435e38907cb605e17a52609c00e36 (diff) | |
download | meson-575a2c34f811dc003caf415d5343f524c5c8e802.zip meson-575a2c34f811dc003caf415d5343f524c5c8e802.tar.gz meson-575a2c34f811dc003caf415d5343f524c5c8e802.tar.bz2 |
Merge pull request #5989 from xclaesse/cmake-part2
cmake: Add support for add_custom_target() and add_dependencies()
Diffstat (limited to 'mesonbuild/cmake/traceparser.py')
-rw-r--r-- | mesonbuild/cmake/traceparser.py | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/mesonbuild/cmake/traceparser.py b/mesonbuild/cmake/traceparser.py index 7daef0b..50cabab 100644 --- a/mesonbuild/cmake/traceparser.py +++ b/mesonbuild/cmake/traceparser.py @@ -43,6 +43,7 @@ class CMakeTarget: self.properties = properties self.imported = imported self.tline = tline + self.depends = [] def __repr__(self): s = 'CMake TARGET:\n -- name: {}\n -- type: {}\n -- imported: {}\n -- properties: {{\n{} }}\n -- tline: {}' @@ -51,12 +52,12 @@ class CMakeTarget: propSTR += " '{}': {}\n".format(i, self.properties[i]) return s.format(self.name, self.type, self.imported, propSTR, self.tline) -class CMakeGeneratorTarget: - def __init__(self): +class CMakeGeneratorTarget(CMakeTarget): + def __init__(self, name): + super().__init__(name, 'CUSTOM', {}) self.outputs = [] # type: List[str] self.command = [] # type: List[List[str]] self.working_dir = None # type: Optional[str] - self.depends = [] # type: List[str] class CMakeTraceParser: def __init__(self, permissive: bool = False): @@ -89,6 +90,7 @@ class CMakeTraceParser: 'target_compile_options': self._cmake_target_compile_options, 'target_include_directories': self._cmake_target_include_directories, 'target_link_options': self._cmake_target_link_options, + 'add_dependencies': self._cmake_add_dependencies, } # Primary pass -- parse everything @@ -235,7 +237,7 @@ class CMakeTraceParser: else: self.targets[args[0]] = CMakeTarget(args[0], 'NORMAL', {}, tline=tline) - def _cmake_add_custom_command(self, tline: CMakeTraceLine): + def _cmake_add_custom_command(self, tline: CMakeTraceLine, name=None): # DOC: https://cmake.org/cmake/help/latest/command/add_custom_command.html args = list(tline.args) # Make a working copy @@ -250,7 +252,7 @@ class CMakeTraceParser: 'IMPLICIT_DEPENDS', 'WORKING_DIRECTORY', 'COMMENT', 'DEPFILE', 'JOB_POOL', 'VERBATIM', 'APPEND', 'USES_TERMINAL', 'COMMAND_EXPAND_LISTS'] - target = CMakeGeneratorTarget() + target = CMakeGeneratorTarget(name) def handle_output(key: str, target: CMakeGeneratorTarget) -> None: target.outputs += [key] @@ -295,6 +297,8 @@ class CMakeTraceParser: target.command = [self._guess_files(x) for x in target.command] self.custom_targets += [target] + if name: + self.targets[name] = target def _cmake_add_custom_target(self, tline: CMakeTraceLine): # DOC: https://cmake.org/cmake/help/latest/command/add_custom_target.html @@ -302,7 +306,8 @@ class CMakeTraceParser: if len(tline.args) < 1: return self._gen_exception('add_custom_target', 'requires at least one argument', tline) - self.targets[tline.args[0]] = CMakeTarget(tline.args[0], 'CUSTOM', {}, tline=tline) + # It's pretty much the same as a custom command + self._cmake_add_custom_command(tline, tline.args[0]) def _cmake_set_property(self, tline: CMakeTraceLine) -> None: # DOC: https://cmake.org/cmake/help/latest/command/set_property.html @@ -398,6 +403,19 @@ class CMakeTraceParser: self.targets[i].properties[name] = value + def _cmake_add_dependencies(self, tline: CMakeTraceLine) -> None: + # DOC: https://cmake.org/cmake/help/latest/command/add_dependencies.html + args = list(tline.args) + + if len(args) < 2: + return self._gen_exception('add_dependencies', 'takes at least 2 arguments', tline) + + target = self.targets.get(args[0]) + if not target: + return self._gen_exception('add_dependencies', 'target not found', tline) + + target.depends += args[1:] + def _cmake_target_compile_definitions(self, tline: CMakeTraceLine) -> None: # DOC: https://cmake.org/cmake/help/latest/command/target_compile_definitions.html self._parse_common_target_options('target_compile_definitions', 'COMPILE_DEFINITIONS', 'INTERFACE_COMPILE_DEFINITIONS', tline) |