I’m trying to set up a multiplatform project to wrap a native (C++) library built with CMake. I have a small cmake project with
extern C
bindings to use via JNI on Kotlin/JVM and cinterop on Kotin/Native. However, I’m a bit lost when it comes to the gradle config for this, specifically with the jvm (desktop) target.
On Android, it’s easy; just set up
externalNativeBuild
with cmake in gradle and
System.loadLibrary("foo")
at runtime. The IDE even matches up
external
declarations in Kotlin to their corresponding native headers.
On desktop JVM, how would I go about accomplishing the Gradle config? The general goal is to have gradle use
cmake
to build my native sources and include the produced .dylib, .so, and .dll in my library’s jar artifact. I can then use a helper at runtime to extract that lib to a directory I can load from. The gradle tasks dependencies should be wired up so whatever task builds the JVM jar includes the library in its resources.