Find{Java,JNI}: Use /usr/libexec/java_home on OS X

If no JAVA_HOME or ENV{JAVA_HOME} is set then try running this
tool to get the system default Java home.

Suggested-by: Larry Shaffer <larrys@dakotacarto.com>
This commit is contained in:
Brad King 2014-01-29 13:51:32 -05:00
parent 70560ee146
commit dd72b19f86
1 changed files with 11 additions and 0 deletions

View File

@ -25,6 +25,17 @@ else()
if(_ENV_JAVA_HOME AND IS_DIRECTORY "${_ENV_JAVA_HOME}")
set(_JAVA_HOME "${_ENV_JAVA_HOME}")
set(_JAVA_HOME_EXPLICIT 1)
else()
set(_CMD_JAVA_HOME "")
if(APPLE AND EXISTS /usr/libexec/java_home)
execute_process(COMMAND /usr/libexec/java_home
OUTPUT_VARIABLE _CMD_JAVA_HOME OUTPUT_STRIP_TRAILING_WHITESPACE)
endif()
if(_CMD_JAVA_HOME AND IS_DIRECTORY "${_CMD_JAVA_HOME}")
set(_JAVA_HOME "${_CMD_JAVA_HOME}")
set(_JAVA_HOME_EXPLICIT 0)
endif()
unset(_CMD_JAVA_HOME)
endif()
unset(_ENV_JAVA_HOME)
endif()