Apply JNI lookup logic from Eli Schwartz in https://todo.sr.ht/~breakfastquay/rubberband/25

This commit is contained in:
Chris Cannam
2022-10-13 13:16:31 +01:00
parent 502241ccf5
commit 16698932d8

View File

@@ -128,14 +128,22 @@ have_sincos = cpp.has_function('sincos',
prefix: '#define _GNU_SOURCE\n#include <math.h>', prefix: '#define _GNU_SOURCE\n#include <math.h>',
args: '-lm') args: '-lm')
javac = find_program('javac', required: false)
jar = find_program('jar', required: false)
# Look for JNI only if javac and jar are found. This is because the # Find out whether we can build the optional JNI target. Thanks to Eli
# auto-JNI-dependency module in Meson 0.62 and 0.63 appears to bail # Schwartz for the fix here; this has been through a few previous
# out of the build completely if it can't find javac, even when # iterations. Initially we just looked for jni.h, but it's often in an
# required is false # obscure place so that didn't work very well. Then tried Meson's
if javac.found() and jar.found() # automatic dependency('jni') handling, but that fails in Meson
# 0.62/0.63 if javac is not present (even if required is false). Then
# tried guarding that check behind a successful find_program('javac'),
# but that fails on systems in which a stub javac is installed that is
# not a compiler (because the subsequent Meson jni magic still
# requires javac as a compiler). Now try adding Java as a complete
# language pack, optionally, and only go on to JNI if that succeeds,
# making sure that nothing "clever" happens if Java is not found.
#
have_java = add_languages('java', required: false)
if have_java
jni_dep = dependency('jni', version: '>= 7.0.0', required: false) jni_dep = dependency('jni', version: '>= 7.0.0', required: false)
if not jni_dep.found() if not jni_dep.found()
if cpp.has_header('jni.h', args: extra_include_args) if cpp.has_header('jni.h', args: extra_include_args)
@@ -144,7 +152,7 @@ if javac.found() and jar.found()
endif endif
else else
# Declare jni_dep so it isn't totally undefined - but it won't be # Declare jni_dep so it isn't totally undefined - but it won't be
# used below because we are conditional on javac/jar as well # used below because we are conditional on have_java as well
jni_dep = declare_dependency() jni_dep = declare_dependency()
endif endif
@@ -601,7 +609,7 @@ if get_option('default_library') != 'shared' and rubberband_additional_static_li
) )
endif endif
if jni_dep.found() and javac.found() and jar.found() if have_java and jni_dep.found()
target_summary += { 'JNI library': [ true, 'Name: ' + rubberband_jni_name ] } target_summary += { 'JNI library': [ true, 'Name: ' + rubberband_jni_name ] }
message('Will build Java Native Interface') message('Will build Java Native Interface')
rubberband_jni = shared_library( rubberband_jni = shared_library(
@@ -622,6 +630,8 @@ if jni_dep.found() and javac.found() and jar.found()
# NB the JNI library is not versioned # NB the JNI library is not versioned
install: true, install: true,
) )
javac = find_program('javac')
jar = find_program('jar')
rubberband_class = custom_target( rubberband_class = custom_target(
'rubberband_class', 'rubberband_class',
input: 'com/breakfastquay/rubberband/RubberBandStretcher.java', input: 'com/breakfastquay/rubberband/RubberBandStretcher.java',
@@ -637,7 +647,7 @@ if jni_dep.found() and javac.found() and jar.found()
) )
else else
target_summary += { 'JNI library': false } target_summary += { 'JNI library': false }
if not (javac.found() and jar.found()) if not have_java
message('Not building Java Native Interface: Java compiler or archiver missing') message('Not building Java Native Interface: Java compiler or archiver missing')
else else
message('Not building Java Native Interface: JNI header not found') message('Not building Java Native Interface: JNI header not found')