New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Leverage java_home command to help FindJava and FindJNI modules on Mac #80
Conversation
dakcarto
commented
Jan 9, 2014
- See issue #14689 for full description
- Also includes related patch from issue #14508
I applied the issue 14508 patch as 519084c. Please rebase on that. Also please revise this patch to use the execute_process OUTPUT_STRIP_TRAILING_WHITESPACE option instead of separate string processing. |
Here's what I did:
This avoided the rebase in of For future reference, should I have merged my |
A topic -> master pull request as you did is correct. |
Fixed logical error when reverting back CMAKE_FIND_FRAMEWORK in FindJNI (added |
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. To choose any Java install (including an older Apple install) other than that returned by /usr/libexec/java_home, set the JAVA_HOME environment variable. Available versions can be listed with /usr/libexec/java_home -V.
Included suggested changes.
I added the following to the end of the commit message:
Since Apple has dropped Java support, things are a bit of a mess. Seems /usr/libexec/java_home mostly returns the 'latest' version installed, while setting JAVA_HOME is the general override for its results. There doesn't seem to be a way to influence /usr/libexec/java_home results other than uninstalling a newer versions. Since Apple's older JavaVM.framework is the only likely framework installed, temporarily setting CMAKE_FIND_FRAMEWORK=LAST seems to be the most reasonable workaround, since all other installs are likely to be lib-based. I think it unlikely that a newer framework version of JAVA will come along from a third-party for some time. Not sure of a better approach than temporarily setting CMAKE_FIND_FRAMEWORK=LAST. Any ideas? Here are the results when no JAVA_HOME is set, and a newer Oracle install, and older Apple install coexist:
Then defining JAVA_HOME to the older Apple install:
|
There is another scenario I have not yet tested. On Mac OS X 10.9, there exists no Java at all by default. Users are then prompted to install the Oracle JRE (not JDK, as tested above), which is now only distributed as a system-wide internet plugin (
If |
We must honor the user's choice for CMAKE_FIND_FRAMEWORKS. If it is set to ONLY then we should not find a non-framework or override it at all. If it is set to FIRST then we should search first for a framework and then for plain libraries. Etc. One approach to all this is to find the framework and the java_home result and choose whichever matches the user preference. More logic reorganization of the original code may be needed. |
I've refactored FindJNI on APPLE to honor CMAKE_FIND_FRAMEWORK while allowing JAVA_HOME to override it when set explicitly. See commit 4b3614b, commit fcd66a7, and commit 70560ee. Finally, commit dd72b19 introduces use of /usr/libexec/java_home as you suggest. With this you can add -DCMAKE_FIND_FRAMEWORKS=LAST and CMake will find the Java returned by /usr/libexec/java_home. |
@bradking Thank you for the work on this. Apologies for not getting back to this sooner. I will test this on Mac OS X 10.7 and 10.9, both with Apple frameworks and with Oracle installed/activated. |
Okay. Please subscribe and post to the cmake-developers mailing list for follow-up discussion if there are problems: http://www.cmake.org/mailman/listinfo/cmake-developers That will have wider visibility. |