CMakeDetermineJavaCompiler.cmake 3.68 KB
Newer Older
1 2
# Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
3

4

Andy Cedilnik's avatar
Andy Cedilnik committed
5
# determine the compiler to use for Java programs
6
# NOTE, a generator may set CMAKE_Java_COMPILER before
Andy Cedilnik's avatar
Andy Cedilnik committed
7 8
# loading this file to force a compiler.

9
if(NOT CMAKE_Java_COMPILER)
Andy Cedilnik's avatar
Andy Cedilnik committed
10
  # prefer the environment variable CC
11
  if(NOT $ENV{JAVA_COMPILER} STREQUAL "")
12 13 14
    get_filename_component(CMAKE_Java_COMPILER_INIT $ENV{JAVA_COMPILER} PROGRAM PROGRAM_ARGS CMAKE_Java_FLAGS_ENV_INIT)
    if(CMAKE_Java_FLAGS_ENV_INIT)
      set(CMAKE_Java_COMPILER_ARG1 "${CMAKE_Java_FLAGS_ENV_INIT}" CACHE STRING "First argument to Java compiler")
15
    endif()
16 17
    if(NOT EXISTS ${CMAKE_Java_COMPILER_INIT})
      message(SEND_ERROR "Could not find compiler set in environment variable JAVA_COMPILER:\n$ENV{JAVA_COMPILER}.")
18 19
    endif()
  endif()
Andy Cedilnik's avatar
Andy Cedilnik committed
20

21
  if(NOT $ENV{JAVA_RUNTIME} STREQUAL "")
22 23 24
    get_filename_component(CMAKE_Java_RUNTIME_INIT $ENV{JAVA_RUNTIME} PROGRAM PROGRAM_ARGS CMAKE_Java_FLAGS_ENV_INIT)
    if(NOT EXISTS ${CMAKE_Java_RUNTIME_INIT})
      message(SEND_ERROR "Could not find compiler set in environment variable JAVA_RUNTIME:\n$ENV{JAVA_RUNTIME}.")
25 26
    endif()
  endif()
Andy Cedilnik's avatar
Andy Cedilnik committed
27

28
  if(NOT $ENV{JAVA_ARCHIVE} STREQUAL "")
29 30 31
    get_filename_component(CMAKE_Java_ARCHIVE_INIT $ENV{JAVA_ARCHIVE} PROGRAM PROGRAM_ARGS CMAKE_Java_FLAGS_ENV_INIT)
    if(NOT EXISTS ${CMAKE_Java_ARCHIVE_INIT})
      message(SEND_ERROR "Could not find compiler set in environment variable JAVA_ARCHIVE:\n$ENV{JAVA_ARCHIVE}.")
32 33
    endif()
  endif()
Andy Cedilnik's avatar
Andy Cedilnik committed
34

35
  set(Java_BIN_PATH
36 37 38 39 40 41
    "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\2.0;JavaHome]/bin"
    "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.9;JavaHome]/bin"
    "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.8;JavaHome]/bin"
    "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.7;JavaHome]/bin"
    "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.6;JavaHome]/bin"
    "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.5;JavaHome]/bin"
42 43
    "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.4;JavaHome]/bin"
    "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.3;JavaHome]/bin"
44
    $ENV{JAVA_HOME}/bin
Andy Cedilnik's avatar
Andy Cedilnik committed
45 46 47 48 49
    /usr/bin
    /usr/lib/java/bin
    /usr/share/java/bin
    /usr/local/bin
    /usr/local/java/bin
50
    /usr/local/java/share/bin
51
    /usr/java/j2sdk1.4.2_04
52
    /usr/lib/j2sdk1.4-sun/bin
53
    /usr/java/j2sdk1.4.2_09/bin
54
    /usr/lib/j2sdk1.5-sun/bin
55
    /opt/sun-jdk-1.5.0.04/bin
56 57
    /usr/local/jdk-1.7.0/bin
    /usr/local/jdk-1.6.0/bin
Andy Cedilnik's avatar
Andy Cedilnik committed
58 59
    )
  # if no compiler has been specified yet, then look for one
60 61
  if(CMAKE_Java_COMPILER_INIT)
    set(CMAKE_Java_COMPILER ${CMAKE_Java_COMPILER_INIT} CACHE PATH "Java Compiler")
62
  else()
63
    find_program(CMAKE_Java_COMPILER
Andy Cedilnik's avatar
Andy Cedilnik committed
64
      NAMES javac
65
      PATHS ${Java_BIN_PATH}
66
    )
67
  endif()
Andy Cedilnik's avatar
Andy Cedilnik committed
68 69

  # if no runtime has been specified yet, then look for one
70 71
  if(CMAKE_Java_RUNTIME_INIT)
    set(CMAKE_Java_RUNTIME ${CMAKE_Java_RUNTIME_INIT} CACHE PATH "Java Compiler")
72
  else()
73
    find_program(CMAKE_Java_RUNTIME
Andy Cedilnik's avatar
Andy Cedilnik committed
74
      NAMES java
75
      PATHS ${Java_BIN_PATH}
76
    )
77
  endif()
Andy Cedilnik's avatar
Andy Cedilnik committed
78 79

  # if no archive has been specified yet, then look for one
80 81
  if(CMAKE_Java_ARCHIVE_INIT)
    set(CMAKE_Java_ARCHIVE ${CMAKE_Java_ARCHIVE_INIT} CACHE PATH "Java Compiler")
82
  else()
83
    find_program(CMAKE_Java_ARCHIVE
Andy Cedilnik's avatar
Andy Cedilnik committed
84
      NAMES jar
85
      PATHS ${Java_BIN_PATH}
86
    )
87 88
  endif()
endif()
89
mark_as_advanced(CMAKE_Java_COMPILER)
Andy Cedilnik's avatar
Andy Cedilnik committed
90 91

# configure variables set in this file for fast reload later on
92
configure_file(${CMAKE_ROOT}/Modules/CMakeJavaCompiler.cmake.in
93
  ${CMAKE_PLATFORM_INFO_DIR}/CMakeJavaCompiler.cmake @ONLY)
94
set(CMAKE_Java_COMPILER_ENV_VAR "JAVA_COMPILER")