From d105985d78e5246692156fc9e2850e37b643ff90 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 8 Aug 2022 10:51:23 +0200 Subject: [PATCH] build/python/cmake: set CMAKE_OSX_SYSROOT on macOS --- python/build/cmake.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/python/build/cmake.py b/python/build/cmake.py index 9017efd56..4f1af6a1f 100644 --- a/python/build/cmake.py +++ b/python/build/cmake.py @@ -1,4 +1,5 @@ import os +import re import subprocess from build.project import Project @@ -31,6 +32,26 @@ set(CMAKE_CXX_FLAGS "{toolchain.cxxflags} {toolchain.cppflags}") __write_cmake_compiler(f, 'C', toolchain.cc) __write_cmake_compiler(f, 'CXX', toolchain.cxx) + if cmake_system_name == 'Darwin': + # On macOS, cmake forcibly adds an "-isysroot" flag even if + # one is already present in the flags variable; this breaks + # cross-compiling for iOS, and can be worked around by setting + # the CMAKE_OSX_SYSROOT variable + # (https://cmake.org/cmake/help/latest/variable/CMAKE_OSX_SYSROOT.html). + m = re.search(r'-isysroot +(\S+)', toolchain.cflags) + if m: + sysroot = m.group(1) + + print(f'set(CMAKE_OSX_SYSROOT {sysroot})', file=f) + + # search libraries and headers only in the sysroot, not on + # the build host + f.write(f""" +set(CMAKE_FIND_ROOT_PATH "{toolchain.install_prefix};{sysroot}") +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) +""") + def configure(toolchain, src, build, args=(), env=None): cross_args = []