summaryrefslogtreecommitdiffstats
path: root/Tests/FindJNI/JVM
diff options
context:
space:
mode:
authorSergiu Deitsch <sergiu.deitsch@gmail.com>2022-03-13 14:56:33 (GMT)
committerSergiu Deitsch <sergiu.deitsch@gmail.com>2022-04-04 17:46:32 (GMT)
commit171d45c039eac3427a7ff7c4bbccba9f1414c68d (patch)
tree0083934798f2b2f88e9f5b37f65f7098efd1f76a /Tests/FindJNI/JVM
parent35e92ec61913d5fb30cd7ca3df2e1ad8728e7e98 (diff)
downloadCMake-171d45c039eac3427a7ff7c4bbccba9f1414c68d.zip
CMake-171d45c039eac3427a7ff7c4bbccba9f1414c68d.tar.gz
CMake-171d45c039eac3427a7ff7c4bbccba9f1414c68d.tar.bz2
FindJNI: added components and imported targets
Diffstat (limited to 'Tests/FindJNI/JVM')
-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
4 files changed, 60 insertions, 0 deletions
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)
+{
+}