diff --git a/mesonbuild/dependencies/cmake.py b/mesonbuild/dependencies/cmake.py index 4a722157ff56..42cffd595c4c 100644 --- a/mesonbuild/dependencies/cmake.py +++ b/mesonbuild/dependencies/cmake.py @@ -546,7 +546,7 @@ def _detect_dep(self, name: str, package_version: str, modules: T.List[T.Tuple[s # Make sure all elements in the lists are unique and sorted incDirs = sorted(set(incDirs)) compileOptions = sorted(set(compileOptions)) - libraries = sorted(set(libraries)) + libraries = sort_link_args(libraries) mlog.debug(f'Include Dirs: {incDirs}') mlog.debug(f'Compiler Options: {compileOptions}') @@ -654,3 +654,27 @@ def __call__(self, name: str, env: Environment, kwargs: T.Dict[str, T.Any], lang @staticmethod def log_tried() -> str: return CMakeDependency.log_tried() + + +def sort_link_args(args: T.List[str]) -> T.List[str]: + itr = iter(args) + result: T.Set[T.Union[T.Tuple[str], T.Tuple[str, str]]] = set() + + while True: + try: + arg = next(itr) + except StopIteration: + break + + if arg == '-framework': + # Frameworks '-framework ...' are two arguments that need to stay together + try: + arg2 = next(itr) + except StopIteration: + raise MesonException(f'Linker arguments contain \'-framework\' with no argument value: {args}') + + result.add((arg, arg2)) + else: + result.add((arg,)) + + return [x for xs in sorted(result) for x in xs]