MantisBT - CMake
View Issue Details
0014689CMakeCMakepublic2014-01-08 22:522016-06-10 14:31
Larry Shaffer 
Kitware Robot 
highmajoralways
closedmoved 
AppleMac OS X10.6-10.9
CMake 2.8.12 
 
0014689: Leaverage /usr/libexec/java_home to help FindJava and FindJNI modules on Mac 10.6-10.9
Mac has a utility, /usr/libexec/java_home, which returns the currently defined home for the system, similar to setting JAVA_HOME environment variable. Most users have always used the JavaVM.framework provided by Apple, but with Mac OS X 10.9 Apple no longer readily provides one (though a user may have a previous install lingering), but instead prompts users to download and install the latest from Oracle.

To get FindJava and FindJNI modules to work on Mac, you usually have to set JAVA_HOME in the environment first, if you want to use a non-Apple Java install, e.g. Oracle's, even though /usr/libexec/java_home now correctly points to the non-Apple install. Also, if a user installs the Oracle Java, but still has a lingering previous Apple install, FindJNI returns mixed results unless CMAKE_FIND_FRAMEWORK = LAST (FIRST by default).

It is not difficult to determine an Apple Java.framework install, when returned by /usr/libexec/java_home, since they all have a 'bundle' symlink in their root directory, while non-Apple installs do not.
Test project attached. Run on a Mac with a non-Apple Java install, without setting JAVA_HOME environment variable.

If you have a lingering Apple Java install, it overrides and the non-Apple Java is ignored.

If you have both an Apple JavaVM.framework and a non-Apple Java install, setting JAVA_HOME environment variable still does not fully work with Find modules, since CMAKE_FIND_FRAMEWORK defaults to FIRST and Apple's framework components are often found instead.
Will be setting up a github.com pull request with changes that fix these issues.
java, jni, macosx
txt CMakeLists.txt (5,064) 2014-01-08 22:52
https://public.kitware.com/Bug/file/5041/CMakeLists.txt
Issue History
2014-01-08 22:52Larry ShafferNew Issue
2014-01-08 22:52Larry ShafferFile Added: CMakeLists.txt
2014-01-08 22:54Larry ShafferTag Attached: macosx
2014-01-08 22:54Larry ShafferTag Attached: java
2014-01-08 22:54Larry ShafferTag Attached: jni
2014-01-08 23:00Larry ShafferNote Added: 0034917
2014-02-03 15:14Brad KingNote Added: 0035030
2016-06-10 14:29Kitware RobotNote Added: 0042461
2016-06-10 14:29Kitware RobotStatusnew => resolved
2016-06-10 14:29Kitware RobotResolutionopen => moved
2016-06-10 14:29Kitware RobotAssigned To => Kitware Robot
2016-06-10 14:31Kitware RobotStatusresolved => closed

Notes
(0034917)
Larry Shaffer   
2014-01-08 23:00   
github.com pull request:
https://github.com/Kitware/CMake/pull/80 [^]

as patch:
https://github.com/Kitware/CMake/pull/80.patch [^]
(0035030)
Brad King   
2014-02-03 15:14   
Changes made for this issue:

 Find{Java,JNI}: Use ENV{JAVA_HOME} first when set
 http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=4b3614b2 [^]

 Find{Java,JNI}: Consider JAVA_HOME before ENV{JAVA_HOME}
 http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=fcd66a7f [^]

 FindJNI: Overhaul finding JDK libraries and headers on OS X
 http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=70560ee1 [^]

 Find{Java,JNI}: Use /usr/libexec/java_home on OS X
 http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=dd72b19f [^]

Follow-up discussion on cmake-developer's list:

 http://thread.gmane.org/gmane.comp.programming.tools.cmake.devel/9226 [^]
(0042461)
Kitware Robot   
2016-06-10 14:29   
Resolving issue as `moved`.

This issue tracker is no longer used. Further discussion of this issue may take place in the current CMake Issues page linked in the banner at the top of this page.