Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle + Cmake add unexpected Quotation marks when concatenate path

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.

like image 301
vgonisanz Avatar asked Oct 16 '22 15:10

vgonisanz


1 Answers

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})
like image 169
goe Avatar answered Oct 19 '22 02:10

goe