Skip to content

Commit

Permalink
Use Android SDK version of CMake rather than an external one
Browse files Browse the repository at this point in the history
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
  • Loading branch information
cortinico authored and facebook-github-bot committed Apr 26, 2022
1 parent 59385e8 commit c12423c
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions ReactAndroid/hermes-engine/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -140,7 +156,7 @@ android {

externalNativeBuild {
cmake {
version "3.18.1"
version cmakeVersion
path "$hermesDir/CMakeLists.txt"
}
}
Expand Down

0 comments on commit c12423c

Please sign in to comment.