mirror of
https://github.com/Kitware/CMake.git
synced 2026-04-20 13:22:22 -05:00
UseJava: Add support for javah tool
Add a `create_javah` API.
This commit is contained in:
10
Tests/JavaJavah/B.cpp
Normal file
10
Tests/JavaJavah/B.cpp
Normal file
@@ -0,0 +1,10 @@
|
||||
|
||||
#include <jni.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "B.h"
|
||||
|
||||
JNIEXPORT void JNICALL Java_B_printName(JNIEnv *, jobject)
|
||||
{
|
||||
printf("B\n");
|
||||
}
|
||||
19
Tests/JavaJavah/B.java
Normal file
19
Tests/JavaJavah/B.java
Normal file
@@ -0,0 +1,19 @@
|
||||
class B
|
||||
{
|
||||
public B()
|
||||
{
|
||||
}
|
||||
|
||||
public native void printName();
|
||||
|
||||
static {
|
||||
try {
|
||||
|
||||
System.loadLibrary("B");
|
||||
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
System.err.println("Native code library failed to load.\n" + e);
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
20
Tests/JavaJavah/CMakeLists.txt
Normal file
20
Tests/JavaJavah/CMakeLists.txt
Normal file
@@ -0,0 +1,20 @@
|
||||
project(helloJavah 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(hello3 B.java HelloWorld2.java)
|
||||
create_javah(TARGET B_javah CLASSES B CLASSPATH hello3)
|
||||
|
||||
add_library(B SHARED B.cpp)
|
||||
add_dependencies(B B_javah)
|
||||
|
||||
target_include_directories(B PRIVATE ${CMAKE_CURRENT_BINARY_DIR}
|
||||
${JAVA_INCLUDE_PATH}
|
||||
${JAVA_INCLUDE_PATH2})
|
||||
10
Tests/JavaJavah/HelloWorld2.java
Normal file
10
Tests/JavaJavah/HelloWorld2.java
Normal file
@@ -0,0 +1,10 @@
|
||||
class HelloWorld2
|
||||
{
|
||||
public static void main(String args[])
|
||||
{
|
||||
B b;
|
||||
b = new B();
|
||||
b.printName();
|
||||
System.out.println("Hello World!");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user