python/build/cmake: write toolchain file only if cross-compiling
This commit is contained in:
parent
0ffbe5b5ea
commit
4d6f220a2f
|
@ -56,11 +56,25 @@ set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
|
||||||
""")
|
""")
|
||||||
|
|
||||||
def configure(toolchain: AnyToolchain, src: str, build: str, args: list[str]=[], env: Optional[Mapping[str, str]]=None) -> None:
|
def configure(toolchain: AnyToolchain, src: str, build: str, args: list[str]=[], env: Optional[Mapping[str, str]]=None) -> None:
|
||||||
cross_args = []
|
cross_args: list[str] = []
|
||||||
|
|
||||||
if toolchain.is_windows:
|
if toolchain.is_windows:
|
||||||
cross_args.append('-DCMAKE_RC_COMPILER=' + cast(str, toolchain.windres))
|
cross_args.append('-DCMAKE_RC_COMPILER=' + cast(str, toolchain.windres))
|
||||||
|
|
||||||
|
configure = [
|
||||||
|
'cmake',
|
||||||
|
src,
|
||||||
|
|
||||||
|
'-DCMAKE_INSTALL_PREFIX=' + toolchain.install_prefix,
|
||||||
|
'-DCMAKE_BUILD_TYPE=release',
|
||||||
|
|
||||||
|
'-GNinja',
|
||||||
|
] + cross_args + args
|
||||||
|
|
||||||
|
if toolchain.host_triplet is not None:
|
||||||
|
# cross-compiling: write a toolchain file
|
||||||
|
os.makedirs(build, exist_ok=True)
|
||||||
|
|
||||||
# Several targets need a sysroot to prevent pkg-config from
|
# Several targets need a sysroot to prevent pkg-config from
|
||||||
# looking for libraries on the build host (TODO: fix this
|
# looking for libraries on the build host (TODO: fix this
|
||||||
# properly); but we must not do that on Android because the NDK
|
# properly); but we must not do that on Android because the NDK
|
||||||
|
@ -68,22 +82,11 @@ def configure(toolchain: AnyToolchain, src: str, build: str, args: list[str]=[],
|
||||||
if not toolchain.is_android and not toolchain.is_darwin:
|
if not toolchain.is_android and not toolchain.is_darwin:
|
||||||
cross_args.append('-DCMAKE_SYSROOT=' + toolchain.install_prefix)
|
cross_args.append('-DCMAKE_SYSROOT=' + toolchain.install_prefix)
|
||||||
|
|
||||||
os.makedirs(build, exist_ok=True)
|
|
||||||
cmake_toolchain_file = os.path.join(build, 'cmake_toolchain_file')
|
cmake_toolchain_file = os.path.join(build, 'cmake_toolchain_file')
|
||||||
with open(cmake_toolchain_file, 'w') as f:
|
with open(cmake_toolchain_file, 'w') as f:
|
||||||
__write_cmake_toolchain_file(f, toolchain)
|
__write_cmake_toolchain_file(f, toolchain)
|
||||||
|
|
||||||
configure = [
|
configure.append('-DCMAKE_TOOLCHAIN_FILE=' + cmake_toolchain_file)
|
||||||
'cmake',
|
|
||||||
src,
|
|
||||||
|
|
||||||
'-DCMAKE_TOOLCHAIN_FILE=' + cmake_toolchain_file,
|
|
||||||
|
|
||||||
'-DCMAKE_INSTALL_PREFIX=' + toolchain.install_prefix,
|
|
||||||
'-DCMAKE_BUILD_TYPE=release',
|
|
||||||
|
|
||||||
'-GNinja',
|
|
||||||
] + cross_args + args
|
|
||||||
|
|
||||||
if env is None:
|
if env is None:
|
||||||
env = toolchain.env
|
env = toolchain.env
|
||||||
|
|
Loading…
Reference in New Issue