CMakeFindJavaCommon.cmake 1.0 KB

12345678910111213141516171819202122232425262728293031
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file Copyright.txt or https://cmake.org/licensing for details.
  3. # Do not include this module directly from code outside CMake!
  4. set(_JAVA_HOME "")
  5. if(JAVA_HOME AND IS_DIRECTORY "${JAVA_HOME}")
  6. set(_JAVA_HOME "${JAVA_HOME}")
  7. set(_JAVA_HOME_EXPLICIT 1)
  8. else()
  9. set(_ENV_JAVA_HOME "")
  10. if(DEFINED ENV{JAVA_HOME})
  11. file(TO_CMAKE_PATH "$ENV{JAVA_HOME}" _ENV_JAVA_HOME)
  12. endif()
  13. if(_ENV_JAVA_HOME AND IS_DIRECTORY "${_ENV_JAVA_HOME}")
  14. set(_JAVA_HOME "${_ENV_JAVA_HOME}")
  15. set(_JAVA_HOME_EXPLICIT 1)
  16. else()
  17. set(_CMD_JAVA_HOME "")
  18. if(APPLE AND EXISTS /usr/libexec/java_home)
  19. execute_process(COMMAND /usr/libexec/java_home
  20. OUTPUT_VARIABLE _CMD_JAVA_HOME OUTPUT_STRIP_TRAILING_WHITESPACE)
  21. endif()
  22. if(_CMD_JAVA_HOME AND IS_DIRECTORY "${_CMD_JAVA_HOME}")
  23. set(_JAVA_HOME "${_CMD_JAVA_HOME}")
  24. set(_JAVA_HOME_EXPLICIT 0)
  25. endif()
  26. unset(_CMD_JAVA_HOME)
  27. endif()
  28. unset(_ENV_JAVA_HOME)
  29. endif()