mirror of
https://github.com/Kitware/CMake.git
synced 2025-05-12 08:05:28 +08:00

On macOS monterey, `java -version` returns ``` The operation couldn’t be completed. Unable to locate a Java Runtime. Please visit http://www.java.com for information on installing Java. ``` which does not match the existing regex. Instead of hitting a fatal error if required, reset the variable and let FindPackage handle the result. If `QUIET` is requested, don't print anything if the version query fails. Otherwise, print the message. Additionally, clean up temporary variables set by the execute_process commands.
35 lines
1.0 KiB
CMake
35 lines
1.0 KiB
CMake
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
|
# file Copyright.txt or https://cmake.org/licensing for details.
|
|
|
|
|
|
# Do not include this module directly from code outside CMake!
|
|
set(_JAVA_HOME "")
|
|
if(JAVA_HOME AND IS_DIRECTORY "${JAVA_HOME}")
|
|
set(_JAVA_HOME "${JAVA_HOME}")
|
|
set(_JAVA_HOME_EXPLICIT 1)
|
|
else()
|
|
set(_ENV_JAVA_HOME "")
|
|
if(DEFINED ENV{JAVA_HOME})
|
|
file(TO_CMAKE_PATH "$ENV{JAVA_HOME}" _ENV_JAVA_HOME)
|
|
endif()
|
|
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
|
|
ERROR_QUIET
|
|
)
|
|
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()
|