summaryrefslogtreecommitdiffstats
path: root/config/cmake/CMakeFindJavaCommon.cmake
blob: 528791d273c747ddf8c883e83da49609bce655d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# Distributed under the OSI-approved BSD 3-Clause License.  See 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)
    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()