The JDK system dependency is important for detecting JDK include paths that may be useful when developing a JNI interface.pull/8645/head
parent
50cf8bcaba
commit
4c13aa30a1
13 changed files with 193 additions and 7 deletions
@ -0,0 +1,16 @@ |
||||
## JDK System Dependency |
||||
|
||||
When building projects such as those interacting with the JNI, you need access |
||||
to a few header files located in a Java installation. This system dependency |
||||
will add the correct include paths to your target. It assumes that either |
||||
`JAVA_HOME` will be set to a valid Java installation, or the default `javac` on |
||||
your system is a located in the `bin` directory of a Java installation. Note: |
||||
symlinks are resolved. |
||||
|
||||
```meson |
||||
jdk = dependency('jdk', version : '>=1.8') |
||||
``` |
||||
|
||||
Currently this system dependency only works on `linux`, `win32`, and `darwin`. |
||||
This can easily be extended given the correct information about your compiler |
||||
and platform in an issue. |
@ -0,0 +1,9 @@ |
||||
#include <jni.h> |
||||
|
||||
#include "com_mesonbuild_JdkTest.h" |
||||
|
||||
JNIEXPORT jint JNICALL Java_com_mesonbuild_JdkTest_jdk_1test |
||||
(JNIEnv *env, jclass clazz) |
||||
{ |
||||
return (jint)0xdeadbeef; |
||||
} |
@ -0,0 +1,21 @@ |
||||
/* DO NOT EDIT THIS FILE - it is machine generated */ |
||||
#include <jni.h> |
||||
/* Header for class com_mesonbuild_JdkTest */ |
||||
|
||||
#ifndef _Included_com_mesonbuild_JdkTest |
||||
#define _Included_com_mesonbuild_JdkTest |
||||
#ifdef __cplusplus |
||||
extern "C" { |
||||
#endif |
||||
/*
|
||||
* Class: com_mesonbuild_JdkTest |
||||
* Method: jdk_test |
||||
* Signature: ()I |
||||
*/ |
||||
JNIEXPORT jint JNICALL Java_com_mesonbuild_JdkTest_jdk_1test |
||||
(JNIEnv *, jclass); |
||||
|
||||
#ifdef __cplusplus |
||||
} |
||||
#endif |
||||
#endif |
@ -0,0 +1,14 @@ |
||||
sources = files( |
||||
'native.c', |
||||
'com_mesonbuild_JdkTest.c', |
||||
) |
||||
|
||||
jdkjava = shared_module( |
||||
'jdkjava', |
||||
sources, |
||||
dependencies : [jdk], |
||||
) |
||||
|
||||
jdkjava_dep = declare_dependency( |
||||
link_with : jdkjava, |
||||
) |
@ -0,0 +1,11 @@ |
||||
#include <jni.h> |
||||
|
||||
JNIEXPORT jint JNICALL |
||||
JNI_OnLoad(JavaVM *vm, void *reserved) |
||||
{ |
||||
return JNI_VERSION_1_8; |
||||
} |
||||
|
||||
JNIEXPORT void JNICALL |
||||
JNI_OnUnload(JavaVM *vm, void *reserved) |
||||
{} |
@ -0,0 +1,18 @@ |
||||
project('jdkjava', ['c', 'java']) |
||||
|
||||
if build_machine.system() == 'cygwin' |
||||
error('MESON_SKIP_TEST: cygwin test failures') |
||||
endif |
||||
|
||||
if build_machine.system() == 'windows' and build_machine.cpu_family() == 'x86' |
||||
error('MESON_SKIP_TEST: failing builds on 32bit Windows because a 32bit JDK isn not available in the Azure Pipelines Windows images') |
||||
endif |
||||
|
||||
fs = import('fs') |
||||
|
||||
java = find_program('java') |
||||
|
||||
jdk = dependency('jdk', version : '>=1.8') |
||||
|
||||
subdir('lib') |
||||
subdir('src') |
@ -0,0 +1,15 @@ |
||||
package com.mesonbuild; |
||||
|
||||
public final class JdkTest { |
||||
private static native int jdk_test(); |
||||
|
||||
public static void main(String[] args) { |
||||
if (jdk_test() != 0xdeadbeef) { |
||||
throw new RuntimeException("jdk_test() did not return 0"); |
||||
} |
||||
} |
||||
|
||||
static { |
||||
System.loadLibrary("jdkjava"); |
||||
} |
||||
} |
@ -0,0 +1,17 @@ |
||||
jdkjar = jar( |
||||
'jdkjar', |
||||
'com' / 'mesonbuild' / 'JdkTest.java', |
||||
main_class : 'com.mesonbuild.JdkTest', |
||||
) |
||||
|
||||
test( |
||||
'jdktest', |
||||
java, |
||||
args: [ |
||||
'-Djava.library.path=@0@'.format(fs.parent(jdkjava.full_path())), |
||||
'-jar', |
||||
jdkjar, |
||||
], |
||||
protocol : 'exitcode', |
||||
depends : [jdkjava], |
||||
) |
Loading…
Reference in new issue