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
|
2011-02-10 23:09:29 +03:00
|
|
|
# Java_JAVAH_EXECUTABLE = the full path to the Java header generator
|
|
|
|
# Java_JAVADOC_EXECUTABLE = the full path to the Java documention generator
|
2009-10-30 18:22:41 +03:00
|
|
|
# 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
|
|
|
#
|
2010-08-08 00:29:08 +04:00
|
|
|
# The minimum required version of Java can be specified using the
|
|
|
|
# standard CMake syntax, e.g. FIND_PACKAGE(Java 1.5)
|
|
|
|
#
|
2009-11-04 17:49:58 +03:00
|
|
|
# NOTE: ${Java_VERSION} and ${Java_VERSION_STRING} are not guaranteed to be
|
|
|
|
# identical. For example some java version may return:
|
|
|
|
# Java_VERSION_STRING = 1.5.0_17
|
|
|
|
# and
|
|
|
|
# Java_VERSION = 1.5.0.17
|
|
|
|
#
|
|
|
|
# another example is the Java OEM, with:
|
|
|
|
# Java_VERSION_STRING = 1.6.0-oem
|
|
|
|
# and
|
|
|
|
# Java_VERSION = 1.6.0
|
|
|
|
#
|
2010-05-09 16:41:15 +04:00
|
|
|
# For these components the following variables are set:
|
|
|
|
#
|
|
|
|
# Java_FOUND - TRUE if all components are found.
|
|
|
|
# Java_INCLUDE_DIRS - Full paths to all include dirs.
|
|
|
|
# Java_LIBRARIES - Full paths to all libraries.
|
|
|
|
# Java_<component>_FOUND - TRUE if <component> is found.
|
|
|
|
#
|
|
|
|
# Example Usages:
|
|
|
|
# FIND_PACKAGE(Java)
|
|
|
|
# FIND_PACKAGE(Java COMPONENTS Runtime)
|
|
|
|
# FIND_PACKAGE(Java COMPONENTS Development)
|
|
|
|
#
|
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.
|
|
|
|
#=============================================================================
|
2010-08-07 04:48:47 +04:00
|
|
|
# (To distribute this file outside of CMake, substitute the full
|
2009-09-28 19:45:50 +04:00
|
|
|
# License text for the above reference.)
|
|
|
|
|
2009-11-02 19:37:16 +03:00
|
|
|
# The HINTS option should only be used for values computed from the system.
|
|
|
|
SET(_JAVA_HINTS
|
|
|
|
"[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
|
2009-11-02 19:37:16 +03:00
|
|
|
)
|
|
|
|
# Hard-coded guesses should still go in PATHS. This ensures that the user
|
|
|
|
# environment can always override hard guesses.
|
|
|
|
SET(_JAVA_PATHS
|
2002-11-14 17:38:45 +03:00
|
|
|
/usr/lib/java/bin
|
|
|
|
/usr/share/java/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
|
2009-11-02 19:37:16 +03:00
|
|
|
HINTS ${_JAVA_HINTS}
|
|
|
|
PATHS ${_JAVA_PATHS}
|
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 )
|
2010-04-26 00:05:21 +04:00
|
|
|
IF(${Java_FIND_REQUIRED})
|
|
|
|
MESSAGE( FATAL_ERROR "Error executing java -version" )
|
|
|
|
ELSE()
|
|
|
|
MESSAGE( STATUS "Warning, could not run java --version")
|
|
|
|
ENDIF()
|
2009-10-30 11:05:59 +03:00
|
|
|
ELSE()
|
2009-10-30 17:49:12 +03:00
|
|
|
# extract major/minor version and patch level from "java -version" output
|
|
|
|
# Tested on linux using
|
2009-11-04 13:17:46 +03:00
|
|
|
# 1. Sun / Sun OEM
|
2009-10-30 17:49:12 +03:00
|
|
|
# 2. OpenJDK 1.6
|
|
|
|
# 3. GCJ 1.5
|
|
|
|
# 4. Kaffe 1.4.2
|
2009-11-04 13:17:46 +03:00
|
|
|
IF(var MATCHES "java version \"[0-9]+\\.[0-9]+\\.[0-9_]+[oem-]*\".*")
|
2009-10-30 17:49:12 +03:00
|
|
|
# This is most likely Sun / OpenJDK, or maybe GCJ-java compat layer
|
2009-11-04 13:17:46 +03:00
|
|
|
STRING( REGEX REPLACE ".* version \"([0-9]+\\.[0-9]+\\.[0-9_]+)[oem-]*\".*"
|
2009-10-30 11:05:59 +03:00
|
|
|
"\\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()
|
2009-11-04 01:22:57 +03:00
|
|
|
IF(NOT Java_FIND_QUIETLY)
|
2009-11-04 13:17:46 +03:00
|
|
|
message(WARNING "regex not supported: ${var}. Please report")
|
2009-11-04 01:22:57 +03:00
|
|
|
ENDIF(NOT Java_FIND_QUIETLY)
|
2009-10-30 17:49:12 +03:00
|
|
|
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
|
2009-11-04 01:22:57 +03:00
|
|
|
IF(NOT Java_FIND_QUIETLY)
|
|
|
|
MESSAGE( STATUS "Java version ${Java_VERSION} configured successfully!" )
|
|
|
|
ENDIF(NOT Java_FIND_QUIETLY)
|
2009-10-30 11:05:59 +03:00
|
|
|
ENDIF()
|
|
|
|
|
|
|
|
ENDIF(Java_JAVA_EXECUTABLE)
|
|
|
|
|
|
|
|
|
|
|
|
FIND_PROGRAM(Java_JAR_EXECUTABLE
|
2002-07-08 17:30:02 +04:00
|
|
|
NAMES jar
|
2009-11-02 19:37:16 +03:00
|
|
|
HINTS ${_JAVA_HINTS}
|
|
|
|
PATHS ${_JAVA_PATHS}
|
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
|
2009-11-02 19:37:16 +03:00
|
|
|
HINTS ${_JAVA_HINTS}
|
|
|
|
PATHS ${_JAVA_PATHS}
|
2002-07-08 17:30:02 +04:00
|
|
|
)
|
|
|
|
|
2011-02-10 23:09:29 +03:00
|
|
|
FIND_PROGRAM(Java_JAVAH_EXECUTABLE
|
|
|
|
NAMES javah
|
|
|
|
HINTS ${_JAVA_HINTS}
|
|
|
|
PATHS ${_JAVA_PATHS}
|
|
|
|
)
|
|
|
|
|
|
|
|
FIND_PROGRAM(Java_JAVADOC_EXECUTABLE
|
|
|
|
NAMES javadoc
|
|
|
|
HINTS ${_JAVA_HINTS}
|
|
|
|
PATHS ${_JAVA_PATHS}
|
|
|
|
)
|
|
|
|
|
Modules: Include builtin FindPackageHandleStandardArgs directly
The FindPackageHandleStandardArgs module was originally created outside
of CMake. It was added for CMake 2.6.0 by commit e118a627 (add a macro
FIND_PACKAGE_HANDLE_STANDARD_ARGS..., 2007-07-18). However, it also
proliferated into a number of other projects that at the time required
only CMake 2.4 and thus could not depend on CMake to provide the module.
CMake's own find modules started using the module in commit b5f656e0
(use the new FIND_PACKAGE_HANDLE_STANDARD_ARGS in some of the FindXXX
modules..., 2007-07-18).
Then commit d358cf5c (add 2nd, more powerful mode to
find_package_handle_standard_args, 2010-07-29) added a new feature to
the interface of the module that was fully optional and backward
compatible with all existing users of the module. Later commit 5f183caa
(FindZLIB: use the FPHSA version mode, 2010-08-04) and others shortly
thereafter started using the new interface in CMake's own find modules.
This change was also backward compatible because it was only an
implementation detail within each module.
Unforutnately these changes introduced a problem for projects that still
have an old copy of FindPackageHandleStandardArgs in CMAKE_MODULE_PATH.
When any such project uses one of CMake's builtin find modules the line
include(FindPackageHandleStandardArgs)
loads the copy from the project which does not have the new interface!
Then the including find module tries to use the new interface with the
old module and fails.
Whether this breakage can be considered a backward incompatible change
in CMake is debatable. The situation is analagous to copying a standard
library header from one version of a compiler into a project and then
observing problems when the next version of the compiler reports errors
in its other headers that depend on its new version of the original
header. Nevertheless it is a change to CMake that causes problems for
projects that worked with previous versions.
This problem was discovered during the 2.8.3 release candidate cycle.
It is an instance of a more general problem with projects that provide
their own versions of CMake modules when other CMake modules depend on
them. At the time we resolved this instance of the problem with commit
b0118402 (Use absolute path to FindPackageHandleStandardArgs.cmake
everywhere, 2010-09-28) for the 2.8.3 release.
In order to address the more general problem we introduced policy
CMP0017 in commit db44848f (Prefer files from CMAKE_ROOT when including
from CMAKE_ROOT, 2010-11-17). That change was followed by commit
ce28737c (Remove usage of CMAKE_CURRENT_LIST_DIR now that we have
CMP0017, 2010-12-20) which reverted the original workaround in favor of
using the policy. However, existing project releases do not set the
policy behavior to NEW and therefore still exhibit the problem.
We introduced in commit a364daf1 (Allow users to specify defaults for
unset policies, 2011-01-03) an option for users to build existing
projects by adding -DCMAKE_POLICY_DEFAULT_CMP0017=NEW to the command
line. Unfortunately this solution still does not allow such projects to
build out of the box, and there is no good way to suggest the use of the
new option.
The only remaining solution to keep existing projects that exhibit this
problem building is to restore the change originally made in commit
b0118402 (Use absolute path to FindPackageHandleStandardArgs.cmake
everywhere, 2010-09-28). This also avoids policy CMP0017 warnings for
this particular instance of the problem the policy addresses.
2011-01-20 18:56:49 +03:00
|
|
|
include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
|
2010-05-09 16:41:15 +04:00
|
|
|
if(Java_FIND_COMPONENTS)
|
|
|
|
foreach(component ${Java_FIND_COMPONENTS})
|
|
|
|
# User just want to execute some Java byte-compiled
|
|
|
|
if(component STREQUAL "Runtime")
|
2010-08-08 00:29:08 +04:00
|
|
|
find_package_handle_standard_args(Java
|
|
|
|
REQUIRED_VARS Java_JAVA_EXECUTABLE
|
|
|
|
VERSION_VAR Java_VERSION
|
|
|
|
)
|
2010-05-09 16:41:15 +04:00
|
|
|
elseif(component STREQUAL "Development")
|
2010-08-08 00:29:08 +04:00
|
|
|
find_package_handle_standard_args(Java
|
|
|
|
REQUIRED_VARS Java_JAVA_EXECUTABLE Java_JAR_EXECUTABLE Java_JAVAC_EXECUTABLE
|
2011-02-10 23:09:29 +03:00
|
|
|
Java_JAVAH_EXECUTABLE Java_JAVADOC_EXECUTABLE
|
2010-08-08 00:29:08 +04:00
|
|
|
VERSION_VAR Java_VERSION
|
|
|
|
)
|
2010-05-09 16:41:15 +04:00
|
|
|
else()
|
|
|
|
message(FATAL_ERROR "Comp: ${component} is not handled")
|
|
|
|
endif()
|
|
|
|
set(Java_${component}_FOUND TRUE)
|
|
|
|
endforeach(component)
|
|
|
|
else()
|
|
|
|
# Check for everything
|
2010-08-08 00:29:08 +04:00
|
|
|
find_package_handle_standard_args(Java
|
|
|
|
REQUIRED_VARS Java_JAVA_EXECUTABLE Java_JAR_EXECUTABLE Java_JAVAC_EXECUTABLE
|
2011-02-10 23:09:29 +03:00
|
|
|
Java_JAVAH_EXECUTABLE Java_JAVADOC_EXECUTABLE
|
2010-08-08 00:29:08 +04:00
|
|
|
VERSION_VAR Java_VERSION
|
|
|
|
)
|
2010-05-09 16:41:15 +04:00
|
|
|
endif()
|
|
|
|
|
2009-10-30 11:05:59 +03:00
|
|
|
|
2009-11-02 17:15:04 +03:00
|
|
|
MARK_AS_ADVANCED(
|
|
|
|
Java_JAVA_EXECUTABLE
|
|
|
|
Java_JAR_EXECUTABLE
|
|
|
|
Java_JAVAC_EXECUTABLE
|
2011-02-10 23:09:29 +03:00
|
|
|
Java_JAVAH_EXECUTABLE
|
|
|
|
Java_JAVADOC_EXECUTABLE
|
2009-11-02 17:15:04 +03: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})
|
|
|
|
|