/// <summary> /// Runs the cmake tool. /// </summary> /// <param name="path">The path.</param> /// <param name="platform">The output platform.</param> /// <param name="architecture">The output architecture.</param> /// <param name="customArgs">The custom arguments for the CMake.</param> /// <param name="envVars">Custom environment variables to pass to the child process.</param> public static void RunCmake(string path, TargetPlatform platform, TargetArchitecture architecture, string customArgs = null, Dictionary <string, string> envVars = null) { string cmdLine; switch (platform) { case TargetPlatform.Windows: case TargetPlatform.XboxOne: case TargetPlatform.XboxScarlett: case TargetPlatform.UWP: { string arch; switch (architecture) { case TargetArchitecture.x86: arch = string.Empty; break; case TargetArchitecture.x64: arch = " Win64"; break; case TargetArchitecture.ARM: arch = " ARM"; break; case TargetArchitecture.ARM64: arch = " ARM64"; break; default: throw new InvalidArchitectureException(architecture); } cmdLine = string.Format("CMakeLists.txt -G \"Visual Studio 14 2015{0}\"", arch); break; } case TargetPlatform.Linux: case TargetPlatform.PS4: { cmdLine = "CMakeLists.txt"; break; } case TargetPlatform.Switch: { cmdLine = string.Format("-DCMAKE_TOOLCHAIN_FILE=\"{1}\\Source\\Platforms\\Switch\\Data\\Switch.cmake\" -G \"NMake Makefiles\" -DCMAKE_MAKE_PROGRAM=\"{0}..\\..\\VC\\bin\\nmake.exe\"", Environment.GetEnvironmentVariable("VS140COMNTOOLS"), Globals.EngineRoot); break; } case TargetPlatform.Android: { var ndk = AndroidNdk.Instance.RootPath; var abi = AndroidToolchain.GetAbiName(architecture); var hostName = AndroidSdk.GetHostName(); cmdLine = string.Format("-DCMAKE_TOOLCHAIN_FILE=\"{0}/build/cmake/android.toolchain.cmake\" -DANDROID_NDK=\"{0}\" -DANDROID_STL=c++_shared -DANDROID_ABI={1} -DANDROID_PLATFORM=android-{2} -G \"MinGW Makefiles\" -DCMAKE_MAKE_PROGRAM=\"{0}/prebuilt/{3}/bin/make.exe\"", ndk, abi, Configuration.AndroidPlatformApi, hostName); break; } default: throw new InvalidPlatformException(platform); } if (customArgs != null) { cmdLine += " " + customArgs; } Utilities.Run("cmake", cmdLine, null, path, Utilities.RunOptions.None, envVars); }
/// <inheritdoc /> public override void Build(BuildOptions options) { // Set it to the local path of the mono rep oto use for the build instead of cloning the remote one (helps with rapid testing) string localRepoPath = string.Empty; //localRepoPath = @"D:\Flax\3rdParty\mono"; root = options.IntermediateFolder; if (!string.IsNullOrEmpty(localRepoPath)) { root = localRepoPath; } monoPropsPath = Path.Combine(root, "msvc", "mono.props"); // Get the source if (string.IsNullOrEmpty(localRepoPath)) { CloneGitRepo(root, "https://github.com/FlaxEngine/mono.git", null, "--recursive"); } // Pick a proper branch GitCheckout(root, "flax-master-5-20"); GitResetLocalChanges(root); // Get the default preprocessor defines for Mono on Windows-based platforms { var monoProps = new XmlDocument(); monoProps.Load(monoPropsPath); monoPreprocesorDefines = FindXmlNodeValue(monoProps, "MONO_PREPROCESSOR_DEFINITIONS"); } foreach (var platform in options.Platforms) { switch (platform) { case TargetPlatform.Windows: { BuildMsvc(options, platform, TargetArchitecture.x64); //BuildBcl(options, platform); // Export header files Deploy.VCEnvironment.BuildSolution(Path.Combine(root, "msvc", "libmono-dynamic.vcxproj"), "Release", "x64"); Deploy.VCEnvironment.BuildSolution(Path.Combine(root, "msvc", "build-install.vcxproj"), "Release", "x64"); // Get exported mono methods to forward them in engine module (on Win32 platforms) GetMonoExports(options); if (BuildPlatform == TargetPlatform.Windows) { // Copy header files var dstIncludePath = Path.Combine(options.ThirdPartyFolder, "mono-2.0"); var dstMonoIncludePath = Path.Combine(dstIncludePath, "mono"); if (Directory.Exists(dstMonoIncludePath)) { Directory.Delete(dstMonoIncludePath, true); } Utilities.DirectoryCopy(Path.Combine(root, "msvc", "include"), dstIncludePath); } break; } case TargetPlatform.UWP: { ConfigureMsvc(options, "v141", "10.0.17763.0", "0x0A00", "_UWP=1;DISABLE_JIT;WINAPI_FAMILY=WINAPI_FAMILY_PC_APP;HAVE_EXTERN_DEFINED_WINAPI_SUPPORT"); BuildMsvc(options, platform, TargetArchitecture.x64); break; } case TargetPlatform.XboxOne: { ConfigureMsvc(options, "v141", "10.0.17763.0", "0x0A00", "_XBOX_ONE=1;DISABLE_JIT;WINAPI_FAMILY=WINAPI_FAMILY_PC_APP;HAVE_EXTERN_DEFINED_WINAPI_SUPPORT"); BuildMsvc(options, platform, TargetArchitecture.x64); break; } case TargetPlatform.Linux: { var envVars = new Dictionary <string, string> { { "CC", "clang-7" }, { "CXX", "clang++-7" } }; var binaries = new[] { "lib/libmono-2.0.a", }; var buildDir = Path.Combine(root, "build-linux"); SetupDirectory(buildDir, true); var archName = UnixToolchain.GetToolchainName(platform, TargetArchitecture.x64); Utilities.Run(Path.Combine(root, "autogen.sh"), string.Format("--host={0} --prefix={1} --disable-boehm --disable-mcs-build --enable-static", archName, buildDir), null, root, Utilities.RunOptions.Default, envVars); Utilities.Run("make", null, null, root, Utilities.RunOptions.None, envVars); Utilities.Run("make", "install", null, root, Utilities.RunOptions.None, envVars); var depsFolder = GetThirdPartyFolder(options, platform, TargetArchitecture.x64); foreach (var binary in binaries) { var src = Path.Combine(buildDir, binary); var dst = Path.Combine(depsFolder, Path.GetFileName(binary)); Utilities.FileCopy(src, dst); } break; } case TargetPlatform.PS4: { // TODO: implement automatic extraction of the package from mono-ps4-binaries break; } case TargetPlatform.XboxScarlett: { ConfigureMsvc(options, "v142", "10.0.19041.0", "0x0A00", "_XBOX_ONE=1;DISABLE_JIT;WINAPI_FAMILY=WINAPI_FAMILY_GAMES;HAVE_EXTERN_DEFINED_WINAPI_SUPPORT;CRITICAL_SECTION_NO_DEBUG_INFO=0x01000000"); BuildMsvc(options, platform, TargetArchitecture.x64); break; } case TargetPlatform.Android: { var sdk = AndroidSdk.Instance.RootPath; var ndk = AndroidNdk.Instance.RootPath; var apiLevel = Configuration.AndroidPlatformApi.ToString(); var archName = UnixToolchain.GetToolchainName(platform, TargetArchitecture.ARM64); var toolchainRoot = Path.Combine(ndk, "toolchains", "llvm", "prebuilt", AndroidSdk.GetHostName()); var ndkBin = Path.Combine(toolchainRoot, "bin"); var compilerFlags = string.Format("-DANDROID -DMONODROID=1 -DANDROID64 -D__ANDROID_API__={0} --sysroot=\"{1}/sysroot\" --gcc-toolchain=\"{1}\"", apiLevel, toolchainRoot); var envVars = new Dictionary <string, string> { { "ANDROID_SDK_ROOT", sdk }, { "ANDROID_SDK", sdk }, { "ANDROID_NDK_ROOT", ndk }, { "ANDROID_NDK", ndk }, { "NDK", ndk }, { "NDK_BIN", ndkBin }, { "ANDROID_PLATFORM", "android-" + apiLevel }, { "ANDROID_API", apiLevel }, { "ANDROID_API_VERSION", apiLevel }, { "ANDROID_NATIVE_API_LEVEL", apiLevel }, { "CC", Path.Combine(ndkBin, archName + apiLevel + "-clang") }, { "CXX", Path.Combine(ndkBin, archName + apiLevel + "-clang++") }, { "AR", Path.Combine(ndkBin, archName + "-ar") }, { "AS", Path.Combine(ndkBin, archName + "-as") }, { "LD", Path.Combine(ndkBin, archName + "-ld") }, { "RANLIB", Path.Combine(ndkBin, archName + "-ranlib") }, { "STRIP", Path.Combine(ndkBin, archName + "-strip") }, { "SYSROOT", toolchainRoot }, { "CFLAGS", compilerFlags }, { "CXXFLAGS", compilerFlags }, { "CPPFLAGS", compilerFlags }, }; var monoOptions = new[] { "--disable-crash-reporting", "--disable-executables", "--disable-iconv", "--disable-boehm", "--disable-nls", "--disable-mcs-build", "--enable-maintainer-mode", "--enable-dynamic-btls", "--enable-monodroid", "--with-btls-android-ndk", "--with-sigaltstack=yes", string.Format("--with-btls-android-ndk={0}", ndk), string.Format("--with-btls-android-api={0}", apiLevel), string.Format("--with-btls-android-cmake-toolchain={0}/build/cmake/android.toolchain.cmake", ndk), "--without-ikvm-native", }; var binaries = new[] { "lib/libmonosgen-2.0.so", }; var buildDir = Path.Combine(root, "build-android"); var envArgs = ""; foreach (var e in envVars) { if (e.Value.Contains(' ')) { envArgs += $" \"{e.Key}={e.Value}\""; } else { envArgs += $" {e.Key}={e.Value}"; } } // Compile mono SetupDirectory(buildDir, true); var toolchain = UnixToolchain.GetToolchainName(platform, TargetArchitecture.ARM64); Utilities.Run(Path.Combine(root, "autogen.sh"), string.Format("--host={0} --prefix={1} {2}{3}", toolchain, buildDir, string.Join(" ", monoOptions), envArgs), null, root, Utilities.RunOptions.Default, envVars); Utilities.Run("make", null, null, root, Utilities.RunOptions.None, envVars); Utilities.Run("make", "install", null, root, Utilities.RunOptions.None, envVars); var depsFolder = GetThirdPartyFolder(options, platform, TargetArchitecture.ARM64); foreach (var binary in binaries) { var src = Path.Combine(buildDir, binary); var dst = Path.Combine(depsFolder, Path.GetFileName(binary)); Utilities.FileCopy(src, dst); } // Clean before another build GitResetLocalChanges(root); Utilities.Run("make", "distclean", null, root, Utilities.RunOptions.None); // Compile BCL var installBcl = Path.Combine(root, "bcl-android"); var bclOutput = Path.Combine(GetBinariesFolder(options, platform), "Mono"); var bclLibOutput = Path.Combine(bclOutput, "lib"); var bclLibMonoOutput = Path.Combine(bclLibOutput, "mono"); SetupDirectory(installBcl, true); SetupDirectory(bclOutput, true); SetupDirectory(bclLibOutput, false); SetupDirectory(bclLibMonoOutput, false); Utilities.DirectoryCopy(Path.Combine(buildDir, "etc"), Path.Combine(bclOutput, "etc"), true, true); Utilities.FileCopy(Path.Combine(buildDir, "lib", "libMonoPosixHelper.so"), Path.Combine(bclLibOutput, "libMonoPosixHelper.so")); Utilities.FileCopy(Path.Combine(buildDir, "lib", "libmono-native.so"), Path.Combine(bclLibOutput, "libmono-native.so")); Utilities.FileCopy(Path.Combine(buildDir, "lib", "libmono-btls-shared.so"), Path.Combine(bclLibOutput, "libmono-btls-shared.so")); var bclOptions = new[] { "--disable-boehm", "--disable-btls-lib", "--disable-nls", "--disable-support-build", "--with-mcs-docs=no", }; Utilities.Run(Path.Combine(root, "autogen.sh"), string.Format("--prefix={0} {1}", installBcl, string.Join(" ", bclOptions)), null, root); Utilities.Run("make", $"-j1 -C {root} -C mono", null, root, Utilities.RunOptions.None); Utilities.Run("make", $"-j2 -C {root} -C runtime all-mcs build_profiles=monodroid", null, root, Utilities.RunOptions.None); Utilities.DirectoryCopy(Path.Combine(root, "mcs", "class", "lib", "monodroid"), Path.Combine(bclLibMonoOutput, "2.1"), true, true, "*.dll"); Utilities.DirectoryDelete(Path.Combine(bclLibMonoOutput, "2.1", "Facades")); break; } } } }