diff options
Diffstat (limited to 'mesonbuild')
-rw-r--r-- | mesonbuild/cmake/interpreter.py | 66 | ||||
-rw-r--r-- | mesonbuild/cmake/traceparser.py | 11 |
2 files changed, 74 insertions, 3 deletions
diff --git a/mesonbuild/cmake/interpreter.py b/mesonbuild/cmake/interpreter.py index 66d0994..5f887ee 100644 --- a/mesonbuild/cmake/interpreter.py +++ b/mesonbuild/cmake/interpreter.py @@ -301,6 +301,72 @@ class ConverterTarget: self.public_compile_opts += props.get('INTERFACE_COMPILE_DEFINITIONS', []) self.public_compile_opts += props.get('INTERFACE_COMPILE_OPTIONS', []) self.link_flags += props.get('INTERFACE_LINK_OPTIONS', []) + + # TODO refactor this copy paste from CMakeDependency for future releases + reg_is_lib = re.compile(r'^(-l[a-zA-Z0-9_]+|-l?pthread)$') + to_process = [self.cmake_name] + processed = [] + while len(to_process) > 0: + curr = to_process.pop(0) + + if curr in processed or curr not in trace.targets: + continue + + tgt = trace.targets[curr] + cfgs = [] + cfg = '' + otherDeps = [] + libraries = [] + mlog.debug(tgt) + + if 'INTERFACE_COMPILE_DEFINITIONS' in tgt.properties: + self.public_compile_opts += ['-D' + re.sub('^-D', '', x) for x in tgt.properties['INTERFACE_COMPILE_DEFINITIONS'] if x] + + if 'INTERFACE_COMPILE_OPTIONS' in tgt.properties: + self.public_compile_opts += [x for x in tgt.properties['INTERFACE_COMPILE_OPTIONS'] if x] + + if 'IMPORTED_CONFIGURATIONS' in tgt.properties: + cfgs += [x for x in tgt.properties['IMPORTED_CONFIGURATIONS'] if x] + cfg = cfgs[0] + + if 'CONFIGURATIONS' in tgt.properties: + cfgs += [x for x in tgt.properties['CONFIGURATIONS'] if x] + cfg = cfgs[0] + + if 'RELEASE' in cfgs: + cfg = 'RELEASE' + + if 'IMPORTED_IMPLIB_{}'.format(cfg) in tgt.properties: + libraries += [x for x in tgt.properties['IMPORTED_IMPLIB_{}'.format(cfg)] if x] + elif 'IMPORTED_IMPLIB' in tgt.properties: + libraries += [x for x in tgt.properties['IMPORTED_IMPLIB'] if x] + elif 'IMPORTED_LOCATION_{}'.format(cfg) in tgt.properties: + libraries += [x for x in tgt.properties['IMPORTED_LOCATION_{}'.format(cfg)] if x] + elif 'IMPORTED_LOCATION' in tgt.properties: + libraries += [x for x in tgt.properties['IMPORTED_LOCATION'] if x] + + if 'LINK_LIBRARIES' in tgt.properties: + otherDeps += [x for x in tgt.properties['LINK_LIBRARIES'] if x] + + if 'INTERFACE_LINK_LIBRARIES' in tgt.properties: + otherDeps += [x for x in tgt.properties['INTERFACE_LINK_LIBRARIES'] if x] + + if 'IMPORTED_LINK_DEPENDENT_LIBRARIES_{}'.format(cfg) in tgt.properties: + otherDeps += [x for x in tgt.properties['IMPORTED_LINK_DEPENDENT_LIBRARIES_{}'.format(cfg)] if x] + elif 'IMPORTED_LINK_DEPENDENT_LIBRARIES' in tgt.properties: + otherDeps += [x for x in tgt.properties['IMPORTED_LINK_DEPENDENT_LIBRARIES'] if x] + + for j in otherDeps: + if j in trace.targets: + to_process += [j] + elif reg_is_lib.match(j) or os.path.exists(j): + libraries += [j] + + for j in libraries: + if j not in self.link_libraries: + self.link_libraries += [j] + + processed += [curr] elif self.type.upper() not in ['EXECUTABLE', 'OBJECT_LIBRARY']: mlog.warning('CMake: Target', mlog.bold(self.cmake_name), 'not found in CMake trace. This can lead to build errors') diff --git a/mesonbuild/cmake/traceparser.py b/mesonbuild/cmake/traceparser.py index 50cabab..84b2120 100644 --- a/mesonbuild/cmake/traceparser.py +++ b/mesonbuild/cmake/traceparser.py @@ -89,6 +89,7 @@ class CMakeTraceParser: 'target_compile_definitions': self._cmake_target_compile_definitions, 'target_compile_options': self._cmake_target_compile_options, 'target_include_directories': self._cmake_target_include_directories, + 'target_link_libraries': self._cmake_target_link_libraries, 'target_link_options': self._cmake_target_link_options, 'add_dependencies': self._cmake_add_dependencies, } @@ -432,6 +433,10 @@ class CMakeTraceParser: # DOC: https://cmake.org/cmake/help/latest/command/target_link_options.html self._parse_common_target_options('target_link_options', 'LINK_OPTIONS', 'INTERFACE_LINK_OPTIONS', tline) + def _cmake_target_link_libraries(self, tline: CMakeTraceLine) -> None: + # DOC: https://cmake.org/cmake/help/latest/command/target_link_libraries.html + self._parse_common_target_options('target_link_options', 'LINK_LIBRARIES', 'INTERFACE_LINK_LIBRARIES', tline) + def _parse_common_target_options(self, func: str, private_prop: str, interface_prop: str, tline: CMakeTraceLine, ignore: Optional[List[str]] = None, paths: bool = False): if ignore is None: ignore = ['BEFORE'] @@ -453,14 +458,14 @@ class CMakeTraceParser: if i in ignore: continue - if i in ['INTERFACE', 'PUBLIC', 'PRIVATE']: + if i in ['INTERFACE', 'LINK_INTERFACE_LIBRARIES', 'PUBLIC', 'PRIVATE', 'LINK_PUBLIC', 'LINK_PRIVATE']: mode = i continue - if mode in ['INTERFACE', 'PUBLIC']: + if mode in ['INTERFACE', 'LINK_INTERFACE_LIBRARIES', 'PUBLIC', 'LINK_PUBLIC']: interface += [i] - if mode in ['PUBLIC', 'PRIVATE']: + if mode in ['PUBLIC', 'PRIVATE', 'LINK_PRIVATE']: private += [i] if paths: |