2005-12-14 21:51:08 +03:00
|
|
|
# - Find Java
|
2002-07-08 17:30:02 +04:00
|
|
|
# This module finds if Java is installed and determines where the
|
|
|
|
# include files and libraries are. This code sets the following
|
|
|
|
# variables:
|
|
|
|
#
|
2009-10-30 11:05:59 +03:00
|
|
|
# Java_JAVA_EXECUTABLE = the full path to the Java runtime
|
2009-10-30 18:22:41 +03:00
|
|
|
# Java_JAVAC_EXECUTABLE = the full path to the Java compiler
|
|
|
|
# Java_JAR_EXECUTABLE = the full path to the Java archiver
|
|
|
|
# Java_VERSION_STRING = Version of the package found (java version), eg. 1.6.0_12
|
2009-10-30 11:05:59 +03:00
|
|
|
# Java_VERSION_MAJOR = The major version of the package found.
|
|
|
|
# Java_VERSION_MINOR = The minor version of the package found.
|
|
|
|
# Java_VERSION_PATCH = The patch version of the package found.
|
2009-10-30 17:49:12 +03:00
|
|
|
# Java_VERSION_TWEAK = The tweak version of the package found (after '_')
|
2009-10-30 18:22:41 +03:00
|
|
|
# Java_VERSION = This is set to: $major.$minor.$patch(.$tweak)
|
2002-07-08 17:30:02 +04:00
|
|
|
#
|
2009-09-28 19:45:50 +04:00
|
|
|
|
|
|
|
#=============================================================================
|
|
|
|
# Copyright 2002-2009 Kitware, Inc.
|
2009-10-30 11:05:59 +03:00
|
|
|
# Copyright 2009 Mathieu Malaterre <mathieu.malaterre@gmail.com>
|
2009-09-28 19:45:50 +04:00
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
#=============================================================================
|
|
|
|
# (To distributed this file outside of CMake, substitute the full
|
|
|
|
# License text for the above reference.)
|
|
|
|
|
2002-11-14 17:38:45 +03:00
|
|
|
SET(JAVA_BIN_PATH
|
2004-09-20 22:39:44 +04:00
|
|
|
"[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"
|
|
|
|
"[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.4;JavaHome]/bin"
|
|
|
|
"[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.3;JavaHome]/bin"
|
2005-09-23 22:38:51 +04:00
|
|
|
$ENV{JAVA_HOME}/bin
|
2002-11-14 17:38:45 +03:00
|
|
|
/usr/bin
|
|
|
|
/usr/lib/java/bin
|
|
|
|
/usr/share/java/bin
|
|
|
|
/usr/local/bin
|
|
|
|
/usr/local/java/bin
|
2006-10-12 21:12:37 +04:00
|
|
|
/usr/local/java/share/bin
|
2004-08-23 19:33:35 +04:00
|
|
|
/usr/java/j2sdk1.4.2_04
|
2005-02-10 06:46:33 +03:00
|
|
|
/usr/lib/j2sdk1.4-sun/bin
|
2005-08-27 01:02:10 +04:00
|
|
|
/usr/java/j2sdk1.4.2_09/bin
|
2005-09-08 18:03:51 +04:00
|
|
|
/usr/lib/j2sdk1.5-sun/bin
|
2005-09-23 22:38:51 +04:00
|
|
|
/opt/sun-jdk-1.5.0.04/bin
|
2002-11-14 17:38:45 +03:00
|
|
|
)
|
2009-10-30 11:05:59 +03:00
|
|
|
FIND_PROGRAM(Java_JAVA_EXECUTABLE
|
2002-07-08 17:30:02 +04:00
|
|
|
NAMES java
|
2002-11-14 17:38:45 +03:00
|
|
|
PATHS ${JAVA_BIN_PATH}
|
2009-10-30 11:05:59 +03:00
|
|
|
NO_DEFAULT_PATH
|
2002-07-08 17:30:02 +04:00
|
|
|
)
|
|
|
|
|
2009-10-30 11:05:59 +03:00
|
|
|
IF(Java_JAVA_EXECUTABLE)
|
|
|
|
EXECUTE_PROCESS(COMMAND ${Java_JAVA_EXECUTABLE} -version
|
|
|
|
RESULT_VARIABLE res
|
|
|
|
OUTPUT_VARIABLE var
|
|
|
|
ERROR_VARIABLE var # sun-java output to stderr
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
|
|
ERROR_STRIP_TRAILING_WHITESPACE)
|
|
|
|
IF( res )
|
|
|
|
MESSAGE( FATAL_ERROR "Error executing java -version" )
|
|
|
|
ELSE()
|
2009-10-30 17:49:12 +03:00
|
|
|
# extract major/minor version and patch level from "java -version" output
|
|
|
|
# Tested on linux using
|
|
|
|
# 1. Sun
|
|
|
|
# 2. OpenJDK 1.6
|
|
|
|
# 3. GCJ 1.5
|
|
|
|
# 4. Kaffe 1.4.2
|
|
|
|
IF(var MATCHES "java version \"[0-9]+\\.[0-9]+\\.[0-9_]+\".*")
|
|
|
|
# This is most likely Sun / OpenJDK, or maybe GCJ-java compat layer
|
2009-10-30 11:05:59 +03:00
|
|
|
STRING( REGEX REPLACE ".* version \"([0-9]+\\.[0-9]+\\.[0-9_]+).*"
|
|
|
|
"\\1" Java_VERSION_STRING "${var}" )
|
2009-10-30 17:49:12 +03:00
|
|
|
ELSEIF(var MATCHES "java full version \"kaffe-[0-9]+\\.[0-9]+\\.[0-9_]+\".*")
|
|
|
|
# Kaffe style
|
|
|
|
STRING( REGEX REPLACE "java full version \"kaffe-([0-9]+\\.[0-9]+\\.[0-9_]+).*"
|
|
|
|
"\\1" Java_VERSION_STRING "${var}" )
|
|
|
|
ELSE()
|
|
|
|
message(FATAL_ERROR "regex not supported: ${var}. Please report")
|
|
|
|
ENDIF()
|
|
|
|
STRING( REGEX REPLACE "([0-9]+).*" "\\1" Java_VERSION_MAJOR "${Java_VERSION_STRING}" )
|
|
|
|
STRING( REGEX REPLACE "[0-9]+\\.([0-9]+).*" "\\1" Java_VERSION_MINOR "${Java_VERSION_STRING}" )
|
|
|
|
STRING( REGEX REPLACE "[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" Java_VERSION_PATCH "${Java_VERSION_STRING}" )
|
|
|
|
# warning tweak version can be empty:
|
|
|
|
STRING( REGEX REPLACE "[0-9]+\\.[0-9]+\\.[0-9]+\\_?([0-9]*)$" "\\1" Java_VERSION_TWEAK "${Java_VERSION_STRING}" )
|
|
|
|
if( Java_VERSION_TWEAK STREQUAL "" ) # check case where tweak is not defined
|
|
|
|
set(Java_VERSION ${Java_VERSION_MAJOR}.${Java_VERSION_MINOR}.${Java_VERSION_PATCH})
|
|
|
|
else( )
|
|
|
|
set(Java_VERSION ${Java_VERSION_MAJOR}.${Java_VERSION_MINOR}.${Java_VERSION_PATCH}.${Java_VERSION_TWEAK})
|
|
|
|
endif( )
|
|
|
|
# display info
|
|
|
|
#MESSAGE( STATUS "Java version ${Java_VERSION_STRING} configured successfully!" ) # keep me, used for debug
|
|
|
|
MESSAGE( STATUS "Java version ${Java_VERSION} configured successfully!" )
|
2009-10-30 11:05:59 +03:00
|
|
|
ENDIF()
|
|
|
|
|
2009-10-30 17:49:12 +03:00
|
|
|
# check version if requested:
|
2009-10-30 11:05:59 +03:00
|
|
|
set(_java_version_acceptable TRUE)
|
|
|
|
if( Java_FIND_VERSION )
|
2009-10-30 17:49:12 +03:00
|
|
|
if("${Java_VERSION}" VERSION_LESS "${Java_FIND_VERSION}")
|
2009-10-30 11:05:59 +03:00
|
|
|
set(_java_version_acceptable FALSE)
|
2009-10-30 17:49:12 +03:00
|
|
|
endif("${Java_VERSION}" VERSION_LESS "${Java_FIND_VERSION}")
|
2009-10-30 11:05:59 +03:00
|
|
|
if( Java_FIND_VERSION_EXACT )
|
2009-10-30 17:49:12 +03:00
|
|
|
if("${Java_VERSION}" VERSION_GREATER "${Java_FIND_VERSION}")
|
2009-10-30 11:05:59 +03:00
|
|
|
set(_java_version_acceptable FALSE)
|
2009-10-30 17:49:12 +03:00
|
|
|
endif("${Java_VERSION}" VERSION_GREATER "${Java_FIND_VERSION}")
|
2009-10-30 11:05:59 +03:00
|
|
|
endif( Java_FIND_VERSION_EXACT )
|
|
|
|
endif( Java_FIND_VERSION )
|
|
|
|
ENDIF(Java_JAVA_EXECUTABLE)
|
|
|
|
|
|
|
|
|
|
|
|
FIND_PROGRAM(Java_JAR_EXECUTABLE
|
2002-07-08 17:30:02 +04:00
|
|
|
NAMES jar
|
2002-11-14 17:38:45 +03:00
|
|
|
PATHS ${JAVA_BIN_PATH}
|
2009-10-30 11:05:59 +03:00
|
|
|
NO_DEFAULT_PATH
|
2002-07-08 17:30:02 +04:00
|
|
|
)
|
|
|
|
|
2009-10-30 11:05:59 +03:00
|
|
|
FIND_PROGRAM(Java_JAVAC_EXECUTABLE
|
2002-07-08 17:30:02 +04:00
|
|
|
NAMES javac
|
2002-11-14 17:38:45 +03:00
|
|
|
PATHS ${JAVA_BIN_PATH}
|
2009-10-30 11:05:59 +03:00
|
|
|
NO_DEFAULT_PATH
|
2002-07-08 17:30:02 +04:00
|
|
|
)
|
|
|
|
|
2009-10-30 11:05:59 +03:00
|
|
|
include(FindPackageHandleStandardArgs)
|
|
|
|
find_package_handle_standard_args(Java DEFAULT_MSG
|
|
|
|
Java_JAVA_EXECUTABLE
|
|
|
|
Java_JAR_EXECUTABLE
|
|
|
|
Java_JAVAC_EXECUTABLE
|
|
|
|
_java_version_acceptable
|
2002-10-10 18:45:34 +04:00
|
|
|
)
|
2009-10-30 11:05:59 +03:00
|
|
|
|
|
|
|
|
|
|
|
# LEGACY
|
|
|
|
SET(JAVA_RUNTIME ${Java_JAVA_EXECUTABLE})
|
|
|
|
SET(JAVA_ARCHIVE ${Java_JAR_EXECUTABLE})
|
|
|
|
SET(JAVA_COMPILE ${Java_JAVAC_EXECUTABLE})
|
|
|
|
|