Reputation: 2340
When using CMake in a regular project, some variables (e.g library paths) can be configured via -D
option or by using ccmake
or cmake-gui
The values are saved in the cache, and this provides for a local configuration that is specific to every user/developer of the code.
In Android Studio, CMake can be configured from Gradle, but I haven't been able to find an equivalent to the options above. The local.properties
file can be read from gradle, but it's overwritten by AS.
Is there any way of setting CMake variables to local values from Android Studio?
Example: On a regular CMake project, I can add a line to my CMakeLists.txt like:
set(EIGEN_DIR /usr/local/include/eigen3 CACHE PATH "Eigen path")
And then two different developers may set that value to their particular systems (ie. /usr/local/include/eigen3
or /opt/local/include/eigen3
) without affecting the project source code. However, in Android Studio, the only way seems to be from build.gradle
, which is part of the project, and will get committed to the repositories.
Upvotes: 1
Views: 2014
Reputation: 2340
I found this can be achieved by putting the variables with the desired value in the local.properties
file, and then read them with the code from this answer:
Properties props = new Properties()
props.load(new FileInputStream(project.rootProject.file('local.properties')))
String conf_value = props['conf.value']
and then
externalNativeBuild{
cmake {
arguments "-DMY_CONF_VALUE="+conf_value
...
}
}
Upvotes: 2