CMakeDetermineJavaCompiler.cmake 4.1 KB

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