FindJNI¶
Find Java Native Interface (JNI) headers and libraries.
JNI enables Java code running in a Java Virtual Machine (JVM) or Dalvik Virtual Machine (DVM) on Android to call and be called by native applications and libraries written in other languages such as C and C++.
This module finds if Java is installed and determines where the
include files and libraries are. It also determines what the name of
the library is. The caller may set variable JAVA_HOME to specify a
Java installation prefix explicitly.
Added in version 3.24: Added imported targets, components AWT, JVM, and Android NDK support.
If no components are specified, the module defaults to an empty components
list while targeting Android, and all available components otherwise.
When using Android NDK, the corresponding package version is reported and a
specific release can be requested. At Android API level 31 and above, the
additional NativeHelper component can be requested. NativeHelper is
also exposed as an implicit dependency of the JVM component (only if this
does not cause a conflict) which provides a uniform access to JVM functions.
Imported Targets¶
Added in version 3.24.
JNI::JNIMain JNI target, defined only if
jni.hwas found.JNI::AWTJava AWT Native Interface (JAWT) library, defined only if component
AWTwas found.JNI::JVMJava Virtual Machine (JVM) library, defined only if component
JVMwas found.JNI::NativeHelperWhen targeting Android API level 31 and above, the import target will provide access to
libnativehelper.sothat exposes JVM functions such asJNI_CreateJavaVM.
Result Variables¶
This module sets the following result variables:
JNI_INCLUDE_DIRSThe include directories to use.
JNI_LIBRARIESThe libraries to use (JAWT and JVM).
JNI_FOUNDTRUEif JNI headers and libraries were found.JNI_<component>_FOUNDAdded in version 3.24.
TRUEif<component>was found.JNI_VERSIONFull Android NDK package version (including suffixes such as
-beta3and-rc1) or undefined otherwise.JNI_VERSION_MAJORAdded in version 3.24.
Android NDK major version or undefined otherwise.
JNI_VERSION_MINORAdded in version 3.24.
Android NDK minor version or undefined otherwise.
JNI_VERSION_PATCHAdded in version 3.24.
Android NDK patch version or undefined otherwise.
Cache Variables¶
The following cache variables are also available to set or use:
JAVA_AWT_LIBRARYThe path to the Java AWT Native Interface (JAWT) library.
JAVA_JVM_LIBRARYThe path to the Java Virtual Machine (JVM) library.
JAVA_INCLUDE_PATHThe include path to
jni.h.JAVA_INCLUDE_PATH2The include path to machine-dependant headers
jni_md.handjniport.h. The variable is defined only ifjni.hdepends on one of these headers. In contrast, Android NDKjni.hcan be typically used standalone.JAVA_AWT_INCLUDE_PATHThe include path to
jawt.h.