summaryrefslogtreecommitdiffstats
path: root/Tests/FindJNI
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2022-04-07 13:11:37 (GMT)
committerKitware Robot <kwrobot@kitware.com>2022-04-07 13:11:56 (GMT)
commitc8f912fa59dfce0097606b7b69e5c1b38471bebf (patch)
tree56fc6842c7a751066035be192bb196d8aae5887d /Tests/FindJNI
parentf0a2ec12e2743a7be39201e2bc563ab37debd791 (diff)
parent00c4f488f2f15af08a4168fbcb59b5919d2e5565 (diff)
downloadCMake-c8f912fa59dfce0097606b7b69e5c1b38471bebf.zip
CMake-c8f912fa59dfce0097606b7b69e5c1b38471bebf.tar.gz
CMake-c8f912fa59dfce0097606b7b69e5c1b38471bebf.tar.bz2
Merge topic 'FindJNI-targets'
00c4f488f2 FindJNI: support Android NDK 171d45c039 FindJNI: added components and imported targets 35e92ec619 FindJNI: improved description Acked-by: Kitware Robot <kwrobot@kitware.com> Acked-by: Alex <leha-bot@yandex.ru> Merge-request: !7069
Diffstat (limited to 'Tests/FindJNI')
-rw-r--r--Tests/FindJNI/AWT/AWTTgt.java7
-rw-r--r--Tests/FindJNI/AWT/AWTVar.java7
-rw-r--r--Tests/FindJNI/AWT/CMakeLists.txt31
-rw-r--r--Tests/FindJNI/AWT/awt.cxx23
-rw-r--r--Tests/FindJNI/CMakeLists.txt12
-rw-r--r--Tests/FindJNI/JVM/CMakeLists.txt31
-rw-r--r--Tests/FindJNI/JVM/JVMTgt.java7
-rw-r--r--Tests/FindJNI/JVM/JVMVar.java7
-rw-r--r--Tests/FindJNI/JVM/jvm.cxx15
-rw-r--r--Tests/FindJNI/Minimal/CMakeLists.txt35
-rw-r--r--Tests/FindJNI/Minimal/MinimalTgt.java7
-rw-r--r--Tests/FindJNI/Minimal/MinimalVar.java7
-rw-r--r--Tests/FindJNI/Minimal/minimal.cxx38
13 files changed, 227 insertions, 0 deletions
diff --git a/Tests/FindJNI/AWT/AWTTgt.java b/Tests/FindJNI/AWT/AWTTgt.java
new file mode 100644
index 0000000..dce37f3
--- /dev/null
+++ b/Tests/FindJNI/AWT/AWTTgt.java
@@ -0,0 +1,7 @@
+class AWTTgt
+{
+ public static void main(String[] args)
+ {
+ System.loadLibrary("AWTTgt");
+ }
+}
diff --git a/Tests/FindJNI/AWT/AWTVar.java b/Tests/FindJNI/AWT/AWTVar.java
new file mode 100644
index 0000000..a918c28
--- /dev/null
+++ b/Tests/FindJNI/AWT/AWTVar.java
@@ -0,0 +1,7 @@
+class AWTVar
+{
+ public static void main(String[] args)
+ {
+ System.loadLibrary("AWTVar");
+ }
+}
diff --git a/Tests/FindJNI/AWT/CMakeLists.txt b/Tests/FindJNI/AWT/CMakeLists.txt
new file mode 100644
index 0000000..bdf49ea
--- /dev/null
+++ b/Tests/FindJNI/AWT/CMakeLists.txt
@@ -0,0 +1,31 @@
+cmake_minimum_required (VERSION 3.23)
+project (TestAWT)
+
+find_package (JNI REQUIRED COMPONENTS AWT)
+find_package (Java REQUIRED COMPONENTS Runtime Development)
+
+add_library (AWTTgt MODULE awt.cxx)
+target_link_libraries (AWTTgt PRIVATE JNI::AWT)
+
+add_library (AWTVar MODULE awt.cxx)
+target_include_directories (AWTVar PRIVATE ${JNI_INCLUDE_DIRS})
+target_link_libraries (AWTVar PRIVATE ${JNI_LIBRARIES})
+
+enable_testing ()
+
+foreach (test AWTTgt AWTVar)
+ add_test (NAME Compile${test} COMMAND ${Java_JAVAC_EXECUTABLE}
+ ${TestAWT_SOURCE_DIR}/${test}.java)
+ add_test (NAME Remove${test} COMMAND ${CMAKE_COMMAND} -E remove
+ ${TestAWT_SOURCE_DIR}/${test}.class)
+
+ add_test (NAME ${test} COMMAND ${Java_JAVA_EXECUTABLE}
+ -cp ${TestAWT_SOURCE_DIR}
+ -Djava.library.path=$<TARGET_FILE_DIR:${test}>
+ ${test}
+ )
+
+ set_tests_properties (Compile${test} PROPERTIES FIXTURES_SETUP Init${test})
+ set_tests_properties (Remove${test} PROPERTIES FIXTURES_CLEANUP Init${test})
+ set_tests_properties (${test} PROPERTIES FIXTURES_REQUIRED Init${test})
+endforeach ()
diff --git a/Tests/FindJNI/AWT/awt.cxx b/Tests/FindJNI/AWT/awt.cxx
new file mode 100644
index 0000000..64e7652
--- /dev/null
+++ b/Tests/FindJNI/AWT/awt.cxx
@@ -0,0 +1,23 @@
+#include <jawt.h>
+
+extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved)
+{
+ void* tmp;
+
+ if (vm->GetEnv(&tmp, JNI_VERSION_1_2) != JNI_OK) {
+ return -1;
+ }
+
+ JAWT awt;
+ awt.version = JAWT_VERSION_1_3;
+
+ if (JAWT_GetAWT(static_cast<JNIEnv*>(tmp), &awt) == JNI_FALSE) {
+ return -1;
+ }
+
+ return JNI_VERSION_1_2;
+}
+
+extern "C" JNIEXPORT void JNICALL JNI_OnUnload(JavaVM* vm, void* reserved)
+{
+}
diff --git a/Tests/FindJNI/CMakeLists.txt b/Tests/FindJNI/CMakeLists.txt
new file mode 100644
index 0000000..0a0f756
--- /dev/null
+++ b/Tests/FindJNI/CMakeLists.txt
@@ -0,0 +1,12 @@
+foreach(test IN ITEMS Minimal JVM AWT)
+ add_test(NAME FindJNI.${test} COMMAND
+ ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION>
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/FindJNI/${test}"
+ "${CMake_BINARY_DIR}/Tests/FindJNI/${test}"
+ ${build_generator_args}
+ --build-project Test${test}
+ --build-options ${build_options}
+ --test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION>
+ )
+endforeach()
diff --git a/Tests/FindJNI/JVM/CMakeLists.txt b/Tests/FindJNI/JVM/CMakeLists.txt
new file mode 100644
index 0000000..cead6ae
--- /dev/null
+++ b/Tests/FindJNI/JVM/CMakeLists.txt
@@ -0,0 +1,31 @@
+cmake_minimum_required (VERSION 3.23)
+project (TestJVM)
+
+find_package (JNI REQUIRED COMPONENTS JVM)
+find_package (Java REQUIRED COMPONENTS Runtime Development)
+
+add_library (JVMTgt MODULE jvm.cxx)
+target_link_libraries (JVMTgt PRIVATE JNI::JVM)
+
+add_library (JVMVar MODULE jvm.cxx)
+target_include_directories (JVMVar PRIVATE ${JNI_INCLUDE_DIRS})
+target_link_libraries (JVMVar PRIVATE ${JNI_LIBRARIES})
+
+enable_testing ()
+
+foreach (test JVMTgt JVMVar)
+ add_test (NAME Compile${test} COMMAND ${Java_JAVAC_EXECUTABLE}
+ ${TestJVM_SOURCE_DIR}/${test}.java)
+ add_test (NAME Remove${test} COMMAND ${CMAKE_COMMAND} -E remove
+ ${TestJVM_SOURCE_DIR}/${test}.class)
+
+ add_test (NAME ${test} COMMAND ${Java_JAVA_EXECUTABLE}
+ -cp ${TestJVM_SOURCE_DIR}
+ -Djava.library.path=$<TARGET_FILE_DIR:${test}>
+ ${test}
+ )
+
+ set_tests_properties (Compile${test} PROPERTIES FIXTURES_SETUP Init${test})
+ set_tests_properties (Remove${test} PROPERTIES FIXTURES_CLEANUP Init${test})
+ set_tests_properties (${test} PROPERTIES FIXTURES_REQUIRED Init${test})
+endforeach ()
diff --git a/Tests/FindJNI/JVM/JVMTgt.java b/Tests/FindJNI/JVM/JVMTgt.java
new file mode 100644
index 0000000..aa5dbb8
--- /dev/null
+++ b/Tests/FindJNI/JVM/JVMTgt.java
@@ -0,0 +1,7 @@
+class JVMTgt
+{
+ public static void main(String[] args)
+ {
+ System.loadLibrary("JVMTgt");
+ }
+}
diff --git a/Tests/FindJNI/JVM/JVMVar.java b/Tests/FindJNI/JVM/JVMVar.java
new file mode 100644
index 0000000..0e84a6f
--- /dev/null
+++ b/Tests/FindJNI/JVM/JVMVar.java
@@ -0,0 +1,7 @@
+class JVMVar
+{
+ public static void main(String[] args)
+ {
+ System.loadLibrary("JVMVar");
+ }
+}
diff --git a/Tests/FindJNI/JVM/jvm.cxx b/Tests/FindJNI/JVM/jvm.cxx
new file mode 100644
index 0000000..f79ccce
--- /dev/null
+++ b/Tests/FindJNI/JVM/jvm.cxx
@@ -0,0 +1,15 @@
+#include <jni.h>
+
+extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved)
+{
+ jsize n = 0;
+ if (JNI_GetCreatedJavaVMs(nullptr, 0, &n) != JNI_OK || n <= 0) {
+ return -1;
+ }
+
+ return JNI_VERSION_1_2;
+}
+
+extern "C" JNIEXPORT void JNICALL JNI_OnUnload(JavaVM* vm, void* reserved)
+{
+}
diff --git a/Tests/FindJNI/Minimal/CMakeLists.txt b/Tests/FindJNI/Minimal/CMakeLists.txt
new file mode 100644
index 0000000..f499c0a
--- /dev/null
+++ b/Tests/FindJNI/Minimal/CMakeLists.txt
@@ -0,0 +1,35 @@
+cmake_minimum_required (VERSION 3.23)
+project (TestMinimal)
+
+set (CMAKE_CXX_VISIBILITY_PRESET hidden)
+
+find_package (JNI REQUIRED)
+find_package (Java REQUIRED COMPONENTS Runtime Development)
+
+add_library (MinimalTgt MODULE minimal.cxx)
+target_link_libraries (MinimalTgt PRIVATE JNI::JNI)
+
+add_library (MinimalVar MODULE minimal.cxx)
+target_include_directories (MinimalVar PRIVATE ${JNI_INCLUDE_DIRS})
+target_link_libraries (MinimalVar PRIVATE ${JNI_LIBRARIES})
+
+enable_testing ()
+
+foreach (test MinimalTgt MinimalVar)
+ add_test (NAME Compile${test} COMMAND ${Java_JAVAC_EXECUTABLE}
+ ${TestMinimal_SOURCE_DIR}/${test}.java)
+ add_test (NAME Remove${test} COMMAND ${CMAKE_COMMAND} -E remove
+ ${TestMinimal_SOURCE_DIR}/${test}.class)
+
+ add_test (NAME ${test} COMMAND ${Java_JAVA_EXECUTABLE}
+ -cp ${TestMinimal_SOURCE_DIR}
+ -Djava.library.path=$<TARGET_FILE_DIR:${test}>
+ ${test}
+ )
+
+ set_tests_properties (Compile${test} PROPERTIES FIXTURES_SETUP Init${test})
+ set_tests_properties (Remove${test} PROPERTIES FIXTURES_CLEANUP Init${test})
+ set_tests_properties (${test} PROPERTIES FIXTURES_REQUIRED Init${test})
+
+ set_tests_properties (${test} PROPERTIES PASS_REGULAR_EXPRESSION "^FindJNI\n$")
+endforeach ()
diff --git a/Tests/FindJNI/Minimal/MinimalTgt.java b/Tests/FindJNI/Minimal/MinimalTgt.java
new file mode 100644
index 0000000..d9c98b5
--- /dev/null
+++ b/Tests/FindJNI/Minimal/MinimalTgt.java
@@ -0,0 +1,7 @@
+class MinimalTgt
+{
+ public static void main(String[] args)
+ {
+ System.loadLibrary("MinimalTgt");
+ }
+}
diff --git a/Tests/FindJNI/Minimal/MinimalVar.java b/Tests/FindJNI/Minimal/MinimalVar.java
new file mode 100644
index 0000000..9f05c74
--- /dev/null
+++ b/Tests/FindJNI/Minimal/MinimalVar.java
@@ -0,0 +1,7 @@
+class MinimalVar
+{
+ public static void main(String[] args)
+ {
+ System.loadLibrary("MinimalVar");
+ }
+}
diff --git a/Tests/FindJNI/Minimal/minimal.cxx b/Tests/FindJNI/Minimal/minimal.cxx
new file mode 100644
index 0000000..4423613
--- /dev/null
+++ b/Tests/FindJNI/Minimal/minimal.cxx
@@ -0,0 +1,38 @@
+#include <cassert>
+
+#include <jni.h>
+
+extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved)
+{
+ void* tmp;
+ if (vm->GetEnv(&tmp, JNI_VERSION_1_2) != JNI_OK) {
+ return -1;
+ }
+
+ // The following lines do:
+ //
+ // System.out.println("FindJNI");
+ //
+ JNIEnv* env = static_cast<JNIEnv*>(tmp);
+
+ jclass clzS = env->FindClass("java/lang/System");
+ jclass clzP = env->FindClass("java/io/PrintStream");
+
+ jfieldID outF = env->GetStaticFieldID(clzS, "out", "Ljava/io/PrintStream;");
+ jobject out = env->GetStaticObjectField(clzS, outF);
+ jmethodID println =
+ env->GetMethodID(clzP, "println", "(Ljava/lang/String;)V");
+
+ env->CallVoidMethod(out, println, env->NewStringUTF("FindJNI"));
+
+ return JNI_VERSION_1_2;
+}
+
+extern "C" JNIEXPORT void JNICALL JNI_OnUnload(JavaVM* vm, void* reserved)
+{
+ void* env;
+ jint result = vm->GetEnv(&env, JNI_VERSION_1_2);
+ assert(result == JNI_OK);
+
+ assert(static_cast<JNIEnv*>(env)->GetVersion() == JNI_VERSION_1_2);
+}