I'm using Android studio with a native project to use a precompiled C++ library. I use gradle + CMake to link the project to the wrapper to call the library
I define in my local.properties a variable:
dependencies.common.dir="/home/vgonisanz/foo"
My gradle.build call CMake:
cmake {
cppFlags ""
arguments "-DANDROID_ABI=armeabi-v7a",
"-DDEPENDENCIES_COMMON_PATH=" + getCommonDir('dependencies.common.dir')
}
ndk {
abiFilters "armeabi-v7a"
}
My CMakelists.txt contains the following code:
set(COMMON_INCLUDE_PATH "${DEPENDENCIES_COMMON_PATH}/modules/module_foo/include")
message("Using dependency path: ${DEPENDENCIES_COMMON_PATH}")
message("Using include path: ${COMMON_INCLUDE_PATH}")
include_directories(${COMMON_INCLUDE_PATH})
But when I build the library not find the expected path in ${COMMON_INCLUDE_PATH}. The path is correct, and works if is hardcoded, so I check the CMake output at my file app/.externalNativeBuild/cmake/debug/armeabi-v7a/cmake_build_output.txt
and the output is:
Using dependency path: "/home/vgonisanz/foo"
Using include path: "/home/vgonisanz/foo"/modules/module_foo/include
Configuring done
The problem is that CMake variable is between quotation mark and that breaks the build. I usually concat path and variables with CMake in this way so, Why is this happening in gradle environment?
I could set up variables in gradle.build but I wish to know if exist a way to solve in CMakeLists.txt to avoid change it in this way.
When you call this:
"-DDEPENDENCIES_COMMON_PATH=" + getCommonDir('dependencies.common.dir')
Gradle includes the quotes to the sentences sent to cmake. You can remove the quotes inside CMake using REPLACE feature. For example:
string(REPLACE "\"" "" DEPENDENCIES_COMMON_PATH ${DEPENDENCIES_COMMON_PATH})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With