MantisBT - CMake
View Issue Details
0014508CMakeModulespublic2013-10-24 11:002014-06-02 08:37
Joe Abbey 
Brad King 
normalminoralways
closedfixed 
Mac OS X 10.9 MavericksDarwin10.9
CMake 2.8.11.2 
CMake 3.0CMake 3.0 
0014508: FindJNI.cmake fails to set JAVA_INCLUDE_PATH2 for darwin
When using find_package(JNI) on Mavericks JAVA_INCLUDE_PATH2 fails to be set.

As far as I can tell, /System/Library/Frameworks/JavaVM.Framework/Headers no longer exists.

The JAVA_INCLUDE_PATH2 needs to also look for the "darwin" subdirectory.
On a Machine running Mac OS X Mavericks:

Create a CMakeLists.txt with the following contents:

find_package(JNI)

if(JNI_FOUND)
    message (STATUS "JAVA_INCLUDE_PATH2=${JAVA_INCLUDE_PATH2}")
else

endif()

END OF CMAKELISTS.TXT

export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_XX.jdk/Contents/Home/

mkdir build/
cd build/

cmake ..

If JAVA_HOME isn't set of course JNI isn't found at all:

-- The C compiler identification is Clang 5.0.0
-- The CXX compiler identification is Clang 5.0.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Could NOT find JNI (missing: JAVA_INCLUDE_PATH JAVA_INCLUDE_PATH2 JAVA_AWT_INCLUDE_PATH)
CMake Error at CMakeLists.txt:7 (message):
  I really need JNI like it's 1999.

After I set JAVA_HOME, I'm seeing the following in CMake 2.8.11.2:

-- The C compiler identification is Clang 5.0.0
-- The CXX compiler identification is Clang 5.0.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Could NOT find JNI (missing: JAVA_INCLUDE_PATH2)
CMake Error at CMakeLists.txt:7 (message):
  I really need JNI like it's 1999.

With my patch (against cmake git) I get the following:

-- JAVA_INCLUDE_PATH2=/Library/Java/JavaVirtualMachines/jdk1.7.0_XX.jdk/Contents/Home/include/darwin
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/jabbey/src/cmakebugs/build
The following patch addresses this issue.

diff --git a/Modules/FindJNI.cmake b/Modules/FindJNI.cmake
index 1780a8e..22823e5 100644
--- a/Modules/FindJNI.cmake
+++ b/Modules/FindJNI.cmake
@@ -238,6 +238,7 @@ find_path(JAVA_INCLUDE_PATH jni.h
 
 find_path(JAVA_INCLUDE_PATH2 jni_md.h
   ${JAVA_INCLUDE_PATH}
+ ${JAVA_INCLUDE_PATH}/darwin
   ${JAVA_INCLUDE_PATH}/win32
   ${JAVA_INCLUDE_PATH}/linux
   ${JAVA_INCLUDE_PATH}/freebsd
No tags attached.
Issue History
2013-10-24 11:00Joe AbbeyNew Issue
2013-10-24 11:01Joe AbbeyNote Added: 0034235
2013-10-29 05:55Rolf Eike BeerAssigned To => Mathieu Malaterre
2013-10-29 05:55Rolf Eike BeerStatusnew => assigned
2014-01-08 23:03Larry ShafferNote Added: 0034918
2014-01-08 23:04Larry ShafferNote Edited: 0034918bug_revision_view_page.php?bugnote_id=34918#r1364
2014-01-09 10:02Brad KingNote Added: 0034920
2014-01-09 10:02Brad KingAssigned ToMathieu Malaterre => Brad King
2014-01-09 10:02Brad KingStatusassigned => resolved
2014-01-09 10:02Brad KingResolutionopen => fixed
2014-01-09 10:02Brad KingFixed in Version => CMake 3.0
2014-01-09 10:02Brad KingTarget Version => CMake 3.0
2014-06-02 08:37Robert MaynardNote Added: 0036071
2014-06-02 08:37Robert MaynardStatusresolved => closed

Notes
(0034235)
Joe Abbey   
2013-10-24 11:01   
Oops, I forgot to update the sample CMakesLists.txt. Here you go!

cmake_minimum_required(VERSION 2.8)
find_package(JNI)

if(JNI_FOUND)
    message (STATUS "JAVA_INCLUDE_PATH2=${JAVA_INCLUDE_PATH2}")
else()
    message (FATAL_ERROR "I really need JNI like it's 1999.")
endif()
(0034918)
Larry Shaffer   
2014-01-08 23:03   
(edited on: 2014-01-08 23:04)
I have included this patch in a related github.com pull request:
https://github.com/Kitware/CMake/pull/80 [^]

as patch:
https://github.com/Kitware/CMake/pull/80.patch [^]

See issue 0014689.

(0034920)
Brad King   
2014-01-09 10:02   
Original patch applied as:

 FindJNI: Set JAVA_INCLUDE_PATH2 for darwin
 http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=519084cd [^]
(0036071)
Robert Maynard   
2014-06-02 08:37   
Closing resolved issues that have not been updated in more than 4 months.