From c12423cbdc660d4fa445e1ad345d89c6f09009a3 Mon Sep 17 00:00:00 2001 From: Nicola Corti Date: Tue, 26 Apr 2022 07:19:00 -0700 Subject: [PATCH] Use Android SDK version of CMake rather than an external one Summary: This diff updates the CMake command used for configuring the Hermes build from `cmake` from $PATH to the `cmake` bundled with the Android SDK. If not found, fallsback to the previous behavior. This relaxes the requirement of having to ask our users to install CMake in their CLIs. Changelog: [Internal] [Changed] - Use Android SDK version of CMake rather than an external one Reviewed By: neildhar Differential Revision: D35931306 fbshipit-source-id: 8d6c554e5e9040e3bd4fed5f72fbdb0eb61d745a --- ReactAndroid/hermes-engine/build.gradle | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/ReactAndroid/hermes-engine/build.gradle b/ReactAndroid/hermes-engine/build.gradle index d86079cd28c..d1aad236f90 100644 --- a/ReactAndroid/hermes-engine/build.gradle +++ b/ReactAndroid/hermes-engine/build.gradle @@ -16,6 +16,22 @@ plugins { group = "com.facebook.react" version = parent.publishing_version +def cmakeVersion = "3.18.1" +/** + * We use the bundled version of CMake in the Android SDK if available, to don't force Android + * users to install CMake externally. + */ +def findCmakePath(cmakeVersion) { + if (System.getenv("ANDROID_SDK_ROOT")) { + return "${System.getenv("ANDROID_SDK_ROOT")}/cmake/${cmakeVersion}/bin/cmake" + } + if (System.getenv("ANDROID_HOME")) { + return "${System.getenv("ANDROID_HOME")}/cmake/${cmakeVersion}/bin/cmake" + } + return "cmake" +} +logger.error("CMAKE PATH ${findCmakePath(cmakeVersion)}") + def reactNativeRootDir = project(':ReactAndroid').projectDir.parent; def customDownloadDir = System.getenv("REACT_NATIVE_DOWNLOADS_DIR") def downloadsDir = customDownloadDir ? new File(customDownloadDir) : new File(reactNativeRootDir, "sdks/download") @@ -70,12 +86,12 @@ task unzipHermes(dependsOn: downloadHermes, type: Copy) { task configureBuildForHermes(type: Exec) { workingDir(hermesDir) - commandLine(windowsAwareCommandLine("cmake", "-S", ".", "-B", "./build", "-DJSI_DIR=" + jsiDir.absolutePath)) + commandLine(windowsAwareCommandLine(findCmakePath(cmakeVersion), "-S", ".", "-B", "./build", "-DJSI_DIR=" + jsiDir.absolutePath)) } task buildHermes(dependsOn: configureBuildForHermes, type: Exec) { workingDir(hermesDir) - commandLine(windowsAwareCommandLine("cmake", "--build", "./build", "--target", "hermesc", "-j", ndkBuildJobs)) + commandLine(windowsAwareCommandLine(findCmakePath(cmakeVersion), "--build", "./build", "--target", "hermesc", "-j", ndkBuildJobs)) } task prepareHeadersForPrefab(type: Copy) { @@ -140,7 +156,7 @@ android { externalNativeBuild { cmake { - version "3.18.1" + version cmakeVersion path "$hermesDir/CMakeLists.txt" } }