add_jar: add option GENERATE_NATIVE_HEADERS

This commit is contained in:
Marc Chevrier
2018-01-19 14:26:46 +01:00
parent be2f050903
commit 4829ea239a
9 changed files with 211 additions and 17 deletions

View File

@@ -0,0 +1,18 @@
project(helloJavaNativeHeaders Java CXX)
cmake_minimum_required (VERSION 2.6)
set(CMAKE_VERBOSE_MAKEFILE 1)
find_package(Java COMPONENTS Development)
include (UseJava)
# JNI support
find_package(JNI)
add_jar(B1 D.java GENERATE_NATIVE_HEADERS D1-native)
add_jar(E1 E.java GENERATE_NATIVE_HEADERS E1-native)
add_jar(hello4 HelloWorld3.java)
add_library(D SHARED D.cpp E.cpp)
target_link_libraries (D PRIVATE D1-native E1-native)

View File

@@ -0,0 +1,10 @@
#include <jni.h>
#include <stdio.h>
#include "D.h"
JNIEXPORT void JNICALL Java_D_printName(JNIEnv*, jobject)
{
printf("D\n");
}

View File

@@ -0,0 +1,19 @@
class D
{
public D()
{
}
public native void printName();
static {
try {
System.loadLibrary("D");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load.\n" + e);
System.exit(1);
}
}
}

View File

@@ -0,0 +1,10 @@
#include <jni.h>
#include <stdio.h>
#include "E.h"
JNIEXPORT void JNICALL Java_E_printName(JNIEnv*, jobject)
{
printf("E\n");
}

View File

@@ -0,0 +1,19 @@
class E
{
public E()
{
}
public native void printName();
static {
try {
System.loadLibrary("D");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load.\n" + e);
System.exit(1);
}
}
}

View File

@@ -0,0 +1,15 @@
class HelloWorld3
{
public static void main(String args[])
{
D d;
d = new D();
d.printName();
E e;
e = new E();
e.printName();
System.out.println("Hello World!");
}
}