CMakeDetermineJavaCompiler.cmake 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file Copyright.txt or https://cmake.org/licensing for details.
  3. # determine the compiler to use for Java programs
  4. # NOTE, a generator may set CMAKE_Java_COMPILER before
  5. # loading this file to force a compiler.
  6. if(NOT CMAKE_Java_COMPILER)
  7. # prefer the environment variable CC
  8. if(NOT $ENV{JAVA_COMPILER} STREQUAL "")
  9. get_filename_component(CMAKE_Java_COMPILER_INIT $ENV{JAVA_COMPILER} PROGRAM PROGRAM_ARGS CMAKE_Java_FLAGS_ENV_INIT)
  10. if(CMAKE_Java_FLAGS_ENV_INIT)
  11. set(CMAKE_Java_COMPILER_ARG1 "${CMAKE_Java_FLAGS_ENV_INIT}" CACHE STRING "First argument to Java compiler")
  12. endif()
  13. if(NOT EXISTS ${CMAKE_Java_COMPILER_INIT})
  14. message(SEND_ERROR "Could not find compiler set in environment variable JAVA_COMPILER:\n$ENV{JAVA_COMPILER}.")
  15. endif()
  16. endif()
  17. if(NOT $ENV{JAVA_RUNTIME} STREQUAL "")
  18. get_filename_component(CMAKE_Java_RUNTIME_INIT $ENV{JAVA_RUNTIME} PROGRAM PROGRAM_ARGS CMAKE_Java_FLAGS_ENV_INIT)
  19. if(NOT EXISTS ${CMAKE_Java_RUNTIME_INIT})
  20. message(SEND_ERROR "Could not find compiler set in environment variable JAVA_RUNTIME:\n$ENV{JAVA_RUNTIME}.")
  21. endif()
  22. endif()
  23. if(NOT $ENV{JAVA_ARCHIVE} STREQUAL "")
  24. get_filename_component(CMAKE_Java_ARCHIVE_INIT $ENV{JAVA_ARCHIVE} PROGRAM PROGRAM_ARGS CMAKE_Java_FLAGS_ENV_INIT)
  25. if(NOT EXISTS ${CMAKE_Java_ARCHIVE_INIT})
  26. message(SEND_ERROR "Could not find compiler set in environment variable JAVA_ARCHIVE:\n$ENV{JAVA_ARCHIVE}.")
  27. endif()
  28. endif()
  29. set(Java_BIN_PATH
  30. "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\2.0;JavaHome]/bin"
  31. "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.9;JavaHome]/bin"
  32. "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.8;JavaHome]/bin"
  33. "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.7;JavaHome]/bin"
  34. "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.6;JavaHome]/bin"
  35. "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.5;JavaHome]/bin"
  36. "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.4;JavaHome]/bin"
  37. "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.3;JavaHome]/bin"
  38. $ENV{JAVA_HOME}/bin
  39. /usr/bin
  40. /usr/lib/java/bin
  41. /usr/share/java/bin
  42. /usr/local/bin
  43. /usr/local/java/bin
  44. /usr/local/java/share/bin
  45. /usr/java/j2sdk1.4.2_04
  46. /usr/lib/j2sdk1.4-sun/bin
  47. /usr/java/j2sdk1.4.2_09/bin
  48. /usr/lib/j2sdk1.5-sun/bin
  49. /opt/sun-jdk-1.5.0.04/bin
  50. /usr/local/jdk-1.7.0/bin
  51. /usr/local/jdk-1.6.0/bin
  52. )
  53. # if no compiler has been specified yet, then look for one
  54. if(CMAKE_Java_COMPILER_INIT)
  55. set(CMAKE_Java_COMPILER ${CMAKE_Java_COMPILER_INIT} CACHE PATH "Java Compiler")
  56. else()
  57. find_program(CMAKE_Java_COMPILER
  58. NAMES javac
  59. PATHS ${Java_BIN_PATH}
  60. )
  61. endif()
  62. # if no runtime has been specified yet, then look for one
  63. if(CMAKE_Java_RUNTIME_INIT)
  64. set(CMAKE_Java_RUNTIME ${CMAKE_Java_RUNTIME_INIT} CACHE PATH "Java Compiler")
  65. else()
  66. find_program(CMAKE_Java_RUNTIME
  67. NAMES java
  68. PATHS ${Java_BIN_PATH}
  69. )
  70. endif()
  71. # if no archive has been specified yet, then look for one
  72. if(CMAKE_Java_ARCHIVE_INIT)
  73. set(CMAKE_Java_ARCHIVE ${CMAKE_Java_ARCHIVE_INIT} CACHE PATH "Java Compiler")
  74. else()
  75. find_program(CMAKE_Java_ARCHIVE
  76. NAMES jar
  77. PATHS ${Java_BIN_PATH}
  78. )
  79. endif()
  80. endif()
  81. mark_as_advanced(CMAKE_Java_COMPILER)
  82. # configure variables set in this file for fast reload later on
  83. configure_file(${CMAKE_ROOT}/Modules/CMakeJavaCompiler.cmake.in
  84. ${CMAKE_PLATFORM_INFO_DIR}/CMakeJavaCompiler.cmake @ONLY)
  85. set(CMAKE_Java_COMPILER_ENV_VAR "JAVA_COMPILER")