Change how sysroot is passed to CMake. (#105)

* Change how sysroot is passed to CMake.

In the CMake documentation, it is specified that the
CMAKE_SYSROOT variable should be passed in toolchain
file variable. It has no effect to set this variable
in CMakeLists.txt like the current implementation.
(This is why CMAKE_FIND_ROOT_PATH is needed.)
The --sysroot option is not passed to the compiler in
the current approach.

This commit, instead, sets the sysroot variable in CMake
command line arguments. This makes it effective, and no
CMAKE_FIND_ROOT_PATH is needed.

Moreover, it is not the duty of architecture to decide
whether we are cross-compiling or not. For example, if
I compile this on my Linux VM on mac M1 to i.MX8 processor,
both host and target has the same arm64 architecture, but
they doesn't share the same sysroot, so the standard
cross-compile procedure should be followed. So, the real
difference for cross-compile is that whether we share
the same sysroot, rather than whether we have the same arch.
So this commit changes the detection method to compare sysroot.
This commit is contained in:
andreadaoud
2022-08-07 11:53:34 +09:00
committed by GitHub
parent b09a90eee6
commit 63f86a7001
3 changed files with 16 additions and 22 deletions
+8 -7
View File
@@ -351,24 +351,25 @@ class NativeBundle {
// Run the native build.
final String cmakeBuildType = buildMode.isPrecompiled ? 'Release' : 'Debug';
final String targetArch = buildInfo.targetArch;
final String targetArch =
buildInfo.targetArch == 'arm64' ? 'aarch64' : 'x86_64';
final String hostArch = _getCurrentHostPlatformArchName();
final String targetCompilerTriple = buildInfo.targetCompilerTriple;
final String targetSysroot = buildInfo.targetSysroot;
final String systemIncludeDirectories = buildInfo.systemIncludeDirectories;
final bool needCrossBuild = targetArch != hostArch;
final bool needCrossBuildOptionsForArm64 = targetArch == 'arm64';
RunResult result = await _processUtils.run(
<String>[
'cmake',
'-DCMAKE_BUILD_TYPE=$cmakeBuildType',
'-DFLUTTER_TARGET_BACKEND_TYPE=${buildInfo.targetBackendType}',
if (needCrossBuild) '-DFLUTTER_TARGET_PLATFORM_SYSROOT=$targetSysroot',
if (needCrossBuild && systemIncludeDirectories != null)
if (targetSysroot != '/') '-DCMAKE_SYSROOT=$targetSysroot',
if (buildInfo.targetArch != hostArch)
'-DCMAKE_SYSTEM_PROCESSOR=$targetArch',
if (systemIncludeDirectories != null)
'-DFLUTTER_SYSTEM_INCLUDE_DIRECTORIES=$systemIncludeDirectories',
if (needCrossBuildOptionsForArm64 && targetCompilerTriple != null)
if (targetCompilerTriple != null)
'-DCMAKE_C_COMPILER_TARGET=$targetCompilerTriple',
if (needCrossBuildOptionsForArm64 && targetCompilerTriple != null)
if (targetCompilerTriple != null)
'-DCMAKE_CXX_COMPILER_TARGET=$targetCompilerTriple',
eLinuxDir.path,
],