Clebert Suconic
Clebert Suconic

Reputation: 5383

How to use FIND_JNI on cmake

I'm trying to write a build for my project where I'm trying to replace autobuild, and I need to proper use FIND_JNI.

I could make a simple build but it's not properly finding jni.h

And I need to find a proper way (without a hack) to define the Java include as this needs to be portable to other users.

Upvotes: 26

Views: 12195

Answers (2)

Akrax
Akrax

Reputation: 131

That solution did not worked for me, I used:

find_package(JNI REQUIRED)    
include_directories(${JNI_INCLUDE_DIRS})

and

echo $JAVA_HOME

must return a valid path.

Upvotes: 5

sakra
sakra

Reputation: 65891

The following code works for me. In your root CMakeLists.txt file add:

find_package(JNI)

if (JNI_FOUND)
    message (STATUS "JNI_INCLUDE_DIRS=${JNI_INCLUDE_DIRS}")
    message (STATUS "JNI_LIBRARIES=${JNI_LIBRARIES}")
endif()

Upvotes: 37

Related Questions