summaryrefslogtreecommitdiffstats
path: root/Tests
diff options
context:
space:
mode:
Diffstat (limited to 'Tests')
-rw-r--r--Tests/CMakeLists.txt25
-rw-r--r--Tests/JavaJavah/B.cpp10
-rw-r--r--Tests/JavaJavah/B.java19
-rw-r--r--Tests/JavaJavah/CMakeLists.txt20
-rw-r--r--Tests/JavaJavah/HelloWorld2.java10
5 files changed, 84 insertions, 0 deletions
diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt
index 35b29bf..801d7e8 100644
--- a/Tests/CMakeLists.txt
+++ b/Tests/CMakeLists.txt
@@ -3036,6 +3036,31 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release
--build-options ${build_options}
--test-command ${JAVA_RUNTIME} -classpath hello2.jar HelloWorld)
list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/JavaJarSourceList")
+
+ # For next test, java tool must have same architecture as toolchain
+ math(EXPR _object_mode "${CMAKE_SIZEOF_VOID_P} * 8")
+ execute_process(
+ COMMAND "${Java_JAVA_EXECUTABLE}" -d${_object_mode} -version
+ OUTPUT_QUIET ERROR_QUIET RESULT_VARIABLE _result
+ )
+ if(_result EQUAL 0)
+ if(CMAKE_CONFIGURATION_TYPES)
+ set (JAVAH_LIBRARY_PATH ${CMake_BINARY_DIR}/Tests/JavaJavah/$<CONFIGURATION>)
+ else()
+ set (JAVAH_LIBRARY_PATH ${CMake_BINARY_DIR}/Tests/JavaJavah)
+ endif()
+ add_test(NAME Java.Javah COMMAND ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/JavaJavah"
+ "${CMake_BINARY_DIR}/Tests/JavaJavah"
+ ${build_generator_args}
+ --build-project helloJavah
+ --build-two-config
+ --build-run-dir "${CMake_BINARY_DIR}/Tests/JavaJavah/"
+ --build-options ${build_options}
+ --test-command ${JAVA_RUNTIME} -Djava.library.path=${JAVAH_LIBRARY_PATH} -classpath hello3.jar HelloWorld2)
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/JavaJavah")
+ endif()
endif()
endif()
endif()
diff --git a/Tests/JavaJavah/B.cpp b/Tests/JavaJavah/B.cpp
new file mode 100644
index 0000000..2666757
--- /dev/null
+++ b/Tests/JavaJavah/B.cpp
@@ -0,0 +1,10 @@
+
+#include <jni.h>
+#include <stdio.h>
+
+#include "B.h"
+
+JNIEXPORT void JNICALL Java_B_printName(JNIEnv *, jobject)
+{
+ printf("B\n");
+}
diff --git a/Tests/JavaJavah/B.java b/Tests/JavaJavah/B.java
new file mode 100644
index 0000000..d731f39
--- /dev/null
+++ b/Tests/JavaJavah/B.java
@@ -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);
+ }
+ }
+}
diff --git a/Tests/JavaJavah/CMakeLists.txt b/Tests/JavaJavah/CMakeLists.txt
new file mode 100644
index 0000000..83b0ad0
--- /dev/null
+++ b/Tests/JavaJavah/CMakeLists.txt
@@ -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})
diff --git a/Tests/JavaJavah/HelloWorld2.java b/Tests/JavaJavah/HelloWorld2.java
new file mode 100644
index 0000000..faf7277
--- /dev/null
+++ b/Tests/JavaJavah/HelloWorld2.java
@@ -0,0 +1,10 @@
+class HelloWorld2
+{
+ public static void main(String args[])
+ {
+ B b;
+ b = new B();
+ b.printName();
+ System.out.println("Hello World!");
+ }
+}