CMakeDetermineJavaCompiler.cmake 4.12 KB
Newer Older
1

2 3 4 5 6 7 8 9 10 11
#=============================================================================
# Copyright 2002-2009 Kitware, Inc.
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
12
# (To distribute this file outside of CMake, substitute the full
13 14
#  License text for the above reference.)

Andy Cedilnik's avatar
Andy Cedilnik committed
15
# determine the compiler to use for Java programs
16
# NOTE, a generator may set CMAKE_Java_COMPILER before
Andy Cedilnik's avatar
Andy Cedilnik committed
17 18
# loading this file to force a compiler.

19
if(NOT CMAKE_Java_COMPILER)
Andy Cedilnik's avatar
Andy Cedilnik committed
20
  # prefer the environment variable CC
21 22 23 24
  if($ENV{JAVA_COMPILER} MATCHES ".+")
    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")
25
    endif()
26 27
    if(NOT EXISTS ${CMAKE_Java_COMPILER_INIT})
      message(SEND_ERROR "Could not find compiler set in environment variable JAVA_COMPILER:\n$ENV{JAVA_COMPILER}.")
28 29
    endif()
  endif()
Andy Cedilnik's avatar
Andy Cedilnik committed
30

31 32 33 34
  if($ENV{JAVA_RUNTIME} MATCHES ".+")
    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}.")
35 36
    endif()
  endif()
Andy Cedilnik's avatar
Andy Cedilnik committed
37

38 39 40 41
  if($ENV{JAVA_ARCHIVE} MATCHES ".+")
    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}.")
42 43
    endif()
  endif()
Andy Cedilnik's avatar
Andy Cedilnik committed
44

45
  set(Java_BIN_PATH
46 47 48 49 50 51
    "[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"
52 53
    "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.4;JavaHome]/bin"
    "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.3;JavaHome]/bin"
54
    $ENV{JAVA_HOME}/bin
Andy Cedilnik's avatar
Andy Cedilnik committed
55 56 57 58 59
    /usr/bin
    /usr/lib/java/bin
    /usr/share/java/bin
    /usr/local/bin
    /usr/local/java/bin
60
    /usr/local/java/share/bin
61
    /usr/java/j2sdk1.4.2_04
62
    /usr/lib/j2sdk1.4-sun/bin
63
    /usr/java/j2sdk1.4.2_09/bin
64
    /usr/lib/j2sdk1.5-sun/bin
65
    /opt/sun-jdk-1.5.0.04/bin
66 67
    /usr/local/jdk-1.7.0/bin
    /usr/local/jdk-1.6.0/bin
Andy Cedilnik's avatar
Andy Cedilnik committed
68 69
    )
  # if no compiler has been specified yet, then look for one
70 71
  if(CMAKE_Java_COMPILER_INIT)
    set(CMAKE_Java_COMPILER ${CMAKE_Java_COMPILER_INIT} CACHE PATH "Java Compiler")
72
  else()
73
    find_program(CMAKE_Java_COMPILER
Andy Cedilnik's avatar
Andy Cedilnik committed
74
      NAMES javac
75
      PATHS ${Java_BIN_PATH}
76
    )
77
  endif()
Andy Cedilnik's avatar
Andy Cedilnik committed
78 79

  # if no runtime has been specified yet, then look for one
80 81
  if(CMAKE_Java_RUNTIME_INIT)
    set(CMAKE_Java_RUNTIME ${CMAKE_Java_RUNTIME_INIT} CACHE PATH "Java Compiler")
82
  else()
83
    find_program(CMAKE_Java_RUNTIME
Andy Cedilnik's avatar
Andy Cedilnik committed
84
      NAMES java
85
      PATHS ${Java_BIN_PATH}
86
    )
87
  endif()
Andy Cedilnik's avatar
Andy Cedilnik committed
88 89

  # if no archive has been specified yet, then look for one
90 91
  if(CMAKE_Java_ARCHIVE_INIT)
    set(CMAKE_Java_ARCHIVE ${CMAKE_Java_ARCHIVE_INIT} CACHE PATH "Java Compiler")
92
  else()
93
    find_program(CMAKE_Java_ARCHIVE
Andy Cedilnik's avatar
Andy Cedilnik committed
94
      NAMES jar
95
      PATHS ${Java_BIN_PATH}
96
    )
97 98
  endif()
endif()
99
mark_as_advanced(CMAKE_Java_COMPILER)
Andy Cedilnik's avatar
Andy Cedilnik committed
100 101

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