diff options
Diffstat (limited to 'Tests/FindJNI/JVM')
-rw-r--r-- | Tests/FindJNI/JVM/CMakeLists.txt | 31 | ||||
-rw-r--r-- | Tests/FindJNI/JVM/JVMTgt.java | 7 | ||||
-rw-r--r-- | Tests/FindJNI/JVM/JVMVar.java | 7 | ||||
-rw-r--r-- | Tests/FindJNI/JVM/jvm.cxx | 15 |
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) +{ +} |