用gradle构建cmake ExternalProject [英] build cmake ExternalProject with gradle
问题描述
我正在尝试将现有的本机库用作android项目的一部分。我遵循了有关将C和C ++代码添加到android studio项目的说明。我已经到达了一个正常运行的CMakeLists.txt文件(已独立测试)的地步,并指示gradle使用它来编译本机代码。
I am trying to use an existing native library as part of an android project. I followed instructions about adding C and C++ Code to a project for android studio. I got to the point where I have a functioning CMakeLists.txt file (tested independently) and I've instructed gradle to use it to compile the native code.
该库我正在使用make,所以我使用ExternalProject_Add来指示cmake如何编译它。以下是相关代码:
The library I'm using uses make so I use ExternalProject_Add to instruct cmake how to compile it. Here is the relevant code:
ExternalProject_Add(foo
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../libfoo
CONFIGURE_COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/../libfoo/configure
--host=arm-linux-androideabi
BUILD_COMMAND ${MAKE}
INSTALL_COMMAND true)
这是build.gradle模块的相关部分:
This is the relevant part of the build.gradle for the module:
externalNativeBuild {
cmake {
path '../cpp/CMakeLists.txt'
}
}
当我运行 ./ gradlew assembleDebug
时,不会编译外部项目。在cmake中添加依赖于 foo
的可执行文件(名为 bar
)后,配置步骤将运行,但构建步骤不会没错我修改了库的代码,以使编译将失败,但是gradle无论如何都会返回成功)。
When I run ./gradlew assembleDebug
, the external project is not compiled. After adding an executable (named bar
) that depends on foo
in cmake, the configure step runs but the build step doesn't. I modified the code of the library so that compilation would fail, but gradle returns success anyway).
这是输出的最后几行./gradlew assembleDebug
。
configure: creating ./config.status
config.status: creating Makefile
config.status: executing depfiles commands
[6/10] Performing build step for 'foo'
[7/10] Performing install step for 'foo'
[8/10] Completed 'foo'
[9/10] Building C object CMakeFiles/bar.dir/bar.c.o
[10/10] Linking C executable bar
BUILD SUCCESSFUL in 18s
有什么想法吗?我在做什么错?
Any ideas what is happening? What am I doing wrong?
我正在使用gradle 4.1和cmake 3.6。
I'm using gradle 4.1 and cmake 3.6.
推荐答案
,您应该使用 BUILD_IN_SOURCE ON
,否则您的 BINARY_DIR
在其他地方,因此 make
不会做任何恕我直言。
you should use BUILD_IN_SOURCE ON
otherwise your BINARY_DIR
is somewhere else so make
do nothing IMHO.
这篇关于用gradle构建cmake ExternalProject的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!