summaryrefslogtreecommitdiffstats
path: root/Modules/FindJava.cmake
diff options
context:
space:
mode:
authorMathieu Malaterre <mathieu.malaterre@gmail.com>2009-10-30 08:05:59 (GMT)
committerMathieu Malaterre <mathieu.malaterre@gmail.com>2009-10-30 08:05:59 (GMT)
commit5c594b6f3a76542de13dcae1974689b21e7f25c2 (patch)
tree66386f86bad9cd9dd0524d552b174490f3c33147 /Modules/FindJava.cmake
parent4e26159ec274414ee3d3c244bef896e1cffb3f41 (diff)
downloadCMake-5c594b6f3a76542de13dcae1974689b21e7f25c2.zip
CMake-5c594b6f3a76542de13dcae1974689b21e7f25c2.tar.gz
CMake-5c594b6f3a76542de13dcae1974689b21e7f25c2.tar.bz2
FIX: BUG: 0009795 FindJava now respect naming convention and handle VERSION/EXACT.
Diffstat (limited to 'Modules/FindJava.cmake')
-rw-r--r--Modules/FindJava.cmake101
1 files changed, 91 insertions, 10 deletions
diff --git a/Modules/FindJava.cmake b/Modules/FindJava.cmake
index 4fddfee..befa0d5 100644
--- a/Modules/FindJava.cmake
+++ b/Modules/FindJava.cmake
@@ -3,13 +3,19 @@
# include files and libraries are. This code sets the following
# variables:
#
-# JAVA_RUNTIME = the full path to the Java runtime
-# JAVA_COMPILE = the full path to the Java compiler
-# JAVA_ARCHIVE = the full path to the Java archiver
+# Java_JAVA_EXECUTABLE = the full path to the Java runtime
+# Java_JAVA_EXECUTABLE = the full path to the Java compiler
+# Java_JAVA_EXECUTABLE = the full path to the Java archiver
+# Java_VERSION_STRING = Version of the package found (java version)
+# 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.
+# The patch version may contains underscore '_'
#
#=============================================================================
# Copyright 2002-2009 Kitware, Inc.
+# Copyright 2009 Mathieu Malaterre <mathieu.malaterre@gmail.com>
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
@@ -43,23 +49,98 @@ SET(JAVA_BIN_PATH
/usr/lib/j2sdk1.5-sun/bin
/opt/sun-jdk-1.5.0.04/bin
)
-FIND_PROGRAM(JAVA_RUNTIME
+FIND_PROGRAM(Java_JAVA_EXECUTABLE
NAMES java
PATHS ${JAVA_BIN_PATH}
+ NO_DEFAULT_PATH
)
-FIND_PROGRAM(JAVA_ARCHIVE
+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()
+ # 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
+ STRING( REGEX REPLACE ".* version \"([0-9]+\\.[0-9]+\\.[0-9_]+).*"
+ "\\1" Java_VERSION_STRING "${var}" )
+ STRING( REGEX REPLACE ".* version \"([0-9]+)\\.[0-9]+\\.[0-9_]+.*"
+ "\\1" Java_VERSION_MAJOR "${var}" )
+ STRING( REGEX REPLACE ".* version \"[0-9]+\\.([0-9]+)\\.[0-9_]+.*"
+ "\\1" Java_VERSION_MINOR "${var}" )
+ STRING( REGEX REPLACE ".* version \"[0-9]+\\.[0-9]+\\.([0-9_]+).*"
+ "\\1" Java_VERSION_PATCH "${var}" )
+ # display info
+ MESSAGE( STATUS "Java version ${Java_VERSION_STRING} configured successfully!" )
+ MESSAGE( STATUS "Java version ${Java_VERSION_MAJOR}.${Java_VERSION_MINOR} configured successfully!" )
+ ENDIF()
+
+ # If any version numbers are given to the command it will set the
+ # following variables before loading the module:
+ #
+ # XXX_FIND_VERSION = full requested version string
+ # XXX_FIND_VERSION_MAJOR = major version if requested, else 0
+ # XXX_FIND_VERSION_MINOR = minor version if requested, else 0
+ # XXX_FIND_VERSION_PATCH = patch version if requested, else 0
+ # XXX_FIND_VERSION_TWEAK = tweak version if requested, else 0
+ # XXX_FIND_VERSION_COUNT = number of version components, 0 to 4
+ # XXX_FIND_VERSION_EXACT = true if EXACT option was given
+ set(_java_version_acceptable TRUE)
+ if( Java_FIND_VERSION )
+ if( Java_FIND_VERSION_MAJOR GREATER Java_VERSION_MAJOR )
+ set(_java_version_acceptable FALSE)
+ endif( Java_FIND_VERSION_MAJOR GREATER Java_VERSION_MAJOR )
+ if( Java_FIND_VERSION_MINOR GREATER Java_VERSION_MINOR )
+ set(_java_version_acceptable FALSE)
+ endif( Java_FIND_VERSION_MINOR GREATER Java_VERSION_MINOR )
+ # Is it exact ?
+ if( Java_FIND_VERSION_EXACT )
+ # since GREATER operation worked ok, simply check LESS operation
+ if( Java_FIND_VERSION_MAJOR LESS Java_VERSION_MAJOR )
+ set(_java_version_acceptable FALSE)
+ endif( Java_FIND_VERSION_MAJOR LESS Java_VERSION_MAJOR )
+ if( Java_FIND_VERSION_MINOR LESS Java_VERSION_MINOR )
+ set(_java_version_acceptable FALSE)
+ endif( Java_FIND_VERSION_MINOR LESS Java_VERSION_MINOR )
+ endif( Java_FIND_VERSION_EXACT )
+ else( Java_FIND_VERSION )
+ # no version requested we are all set
+ endif( Java_FIND_VERSION )
+
+ENDIF(Java_JAVA_EXECUTABLE)
+
+
+FIND_PROGRAM(Java_JAR_EXECUTABLE
NAMES jar
PATHS ${JAVA_BIN_PATH}
+ NO_DEFAULT_PATH
)
-FIND_PROGRAM(JAVA_COMPILE
+FIND_PROGRAM(Java_JAVAC_EXECUTABLE
NAMES javac
PATHS ${JAVA_BIN_PATH}
+ NO_DEFAULT_PATH
)
-MARK_AS_ADVANCED(
-JAVA_RUNTIME
-JAVA_ARCHIVE
-JAVA_COMPILE
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(Java DEFAULT_MSG
+ Java_JAVA_EXECUTABLE
+ Java_JAR_EXECUTABLE
+ Java_JAVAC_EXECUTABLE
+ _java_version_acceptable
)
+
+
+# LEGACY
+SET(JAVA_RUNTIME ${Java_JAVA_EXECUTABLE})
+SET(JAVA_ARCHIVE ${Java_JAR_EXECUTABLE})
+SET(JAVA_COMPILE ${Java_JAVAC_EXECUTABLE})
+