Discussion:
cmake with multiple inter-dependent ndk modules
Sheldon Neuberger
2018-02-01 05:28:59 UTC
Permalink
I have a repository with multiple modules that have various
inter-dependencies. These modules contain C++ and Java code. I have them
separated into modules so that consuming projects can take dependencies on
only what they need. Is it possible to setup an android project with cmake
in this way? Here's what I would like:

x/
--CMakeLists.txt
--build.gradle
--java/
----x.java
--cpp/
----x.cpp
----x.hpp
y/
--CMakeLists.txt
--build.gradle
--java/
----y.java
--cpp/
----y.cpp
----y.hpp

in this example, suppose that: x and y are modules; each module builds a
shared library (libx.so and liby.so); and x's cpp code depends on y's cpp
code. So now an android app could depend on y/build.gradle and they would
only get module y, or they could depend on x/build.gradle and they would
get both x and y (because x depends on y).

Given that structure, how would I express x's C++-level dependency on y?

I do have a working example that gets me halfway there, but it has one
super build.gradle:

build.gradle
CMakeLists.txt
x/
--CMakeLists.txt
--java/
----x.java
--cpp/
----x.cpp
----x.hpp
y/
--CMakeLists.txt
--java/
----y.java
--cpp/
----y.cpp
----y.hpp

In this example, the top-level build.gradle sets externalNativeBuild to the
top-level CMakeLists.txt. The top-level CMakeLists.txt calls
add_subdirectory for each module. This builds everything as expected and
allows x's C++ to take a dependency on y, but it requires a consumer to
pull all modules in (via the top-level build.gradle).
--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk+***@googlegroups.com.
To post to this group, send email to android-***@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/cd0c567d-6bca-4861-be32-e5288ee70fda%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Alex Cohn
2018-02-04 18:57:00 UTC
Permalink
You could set two *library* modules, one for *libx* and another for *liby*.
This way, you not only have two independent C++ directories with
*CMakeLists.txt* each, but also the JNI wrappers (the Java classes that
work with each of these libraries) are isolated from each other. It's
easier to maintain JNI this way. In my experience, keeping Java and C++
sides in sync becomes a challenge when the development team grows beyond
one person.

Now your Android Studio project will have three modules: app and two
libraries. Another project can only use one library. Note that it is
possible to wrap such library module in maven, and include it as an
external aar - which contains both Java and C++ precompiled.

BR,
Alex
Post by Sheldon Neuberger
I have a repository with multiple modules that have various
inter-dependencies. These modules contain C++ and Java code. I have them
separated into modules so that consuming projects can take dependencies on
only what they need. Is it possible to setup an android project with cmake
x/
--CMakeLists.txt
--build.gradle
--java/
----x.java
--cpp/
----x.cpp
----x.hpp
y/
--CMakeLists.txt
--build.gradle
--java/
----y.java
--cpp/
----y.cpp
----y.hpp
in this example, suppose that: x and y are modules; each module builds a
shared library (libx.so and liby.so); and x's cpp code depends on y's cpp
code. So now an android app could depend on y/build.gradle and they would
only get module y, or they could depend on x/build.gradle and they would
get both x and y (because x depends on y).
Given that structure, how would I express x's C++-level dependency on y?
I do have a working example that gets me halfway there, but it has one
build.gradle
CMakeLists.txt
x/
--CMakeLists.txt
--java/
----x.java
--cpp/
----x.cpp
----x.hpp
y/
--CMakeLists.txt
--java/
----y.java
--cpp/
----y.cpp
----y.hpp
In this example, the top-level build.gradle sets externalNativeBuild to
the top-level CMakeLists.txt. The top-level CMakeLists.txt calls
add_subdirectory for each module. This builds everything as expected and
allows x's C++ to take a dependency on y, but it requires a consumer to
pull all modules in (via the top-level build.gradle).
--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk+***@googlegroups.com.
To post to this group, send email to android-***@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/2044ff6f-4a36-4e81-bac0-bcfdcb99bc5d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...