I need to set an environment variable when building an Android app using NDK so that all the CMakeLists.txt files in my NDK project can access that value. Most likely I only need to set that value for this particular app. Any straightforward to do that?
Things I've tried:
I've tried to use a bash script to set the env, and run the script before preBuild
during gradle build. I think the script was executed, however, the env var is not set, at least not readable from CMakeLists.txt files. Here's the code in app/build.gradle
:
task runBuildScript(type: Exec) {
commandLine "bash", "-c", './set-env.sh'
}
project.afterEvaluate {
preBuild.dependsOn(runBuildScript)
}
This is pretty much all the script does:
DIR="${BASH_SOURCE[0]}"
export SDK_BASE=$( cd "$( dirname "$DIR" )/../../" > /dev/null && pwd )
This is how I plan to use that env var in my CMakeLists.txt files:
LIST(APPEND CMAKE_MODULE_PATH "$ENV{SDK_BASE}/build-tools/cmake")
include(sdk_module) # this line will only work if the above command can find the module from the correct location
FYI, I'm using Android Studio on Mac to build this app, if that matters.