Commit 25510a09 authored by Brad King's avatar Brad King
Browse files

Merge branch 'FindJava-tolerant-versions' into release-3.10

Merge-request: !1355
parents bd945123 6feb0c33
......@@ -39,7 +39,7 @@
# Java_VERSION_MINOR = The minor version of the package found.
# Java_VERSION_PATCH = The patch version of the package found.
# Java_VERSION_TWEAK = The tweak version of the package found (after '_')
# Java_VERSION = This is set to: $major.$minor.$patch(.$tweak)
# Java_VERSION = This is set to: $major[.$minor[.$patch[.$tweak]]]
#
#
#
......@@ -133,39 +133,56 @@ if(Java_JAVA_EXECUTABLE)
message( STATUS "Warning, could not run java -version")
endif()
else()
# extract major/minor version and patch level from "java -version" output
# Tested on linux using
# 1. Sun / Sun OEM
# 2. OpenJDK 1.6
# 3. GCJ 1.5
# 4. Kaffe 1.4.2
# 5. OpenJDK 1.7.x on OpenBSD
if(var MATCHES "java version \"([0-9]+\\.[0-9]+\\.[0-9_.]+.*)\"")
# This is most likely Sun / OpenJDK, or maybe GCJ-java compat layer
# Extract version components (up to 4 levels) from "java -version" output.
set(_java_version_regex [[(([0-9]+)(\.([0-9]+)(\.([0-9]+)(_([0-9]+))?)?)?.*)]])
if(var MATCHES "java version \"${_java_version_regex}\"")
# Sun, GCJ, older OpenJDK
set(Java_VERSION_STRING "${CMAKE_MATCH_1}")
set(Java_VERSION_MAJOR "${CMAKE_MATCH_2}")
set(Java_VERSION_MINOR "${CMAKE_MATCH_4}")
set(Java_VERSION_PATCH "${CMAKE_MATCH_6}")
set(Java_VERSION_TWEAK "${CMAKE_MATCH_8}")
elseif(var MATCHES "openjdk version \"${_java_version_regex}\"")
# OpenJDK
set(Java_VERSION_STRING "${CMAKE_MATCH_1}")
set(Java_VERSION_MAJOR "${CMAKE_MATCH_2}")
set(Java_VERSION_MINOR "${CMAKE_MATCH_4}")
set(Java_VERSION_PATCH "${CMAKE_MATCH_6}")
set(Java_VERSION_TWEAK "${CMAKE_MATCH_8}")
elseif(var MATCHES "openjdk version \"([0-9]+)-[A-Za-z]+\"")
# OpenJDK 9 early access builds or locally built
set(Java_VERSION_STRING "1.${CMAKE_MATCH_1}.0")
elseif(var MATCHES "java full version \"kaffe-([0-9]+\\.[0-9]+\\.[0-9_]+)\"")
set(Java_VERSION_MAJOR "1")
set(Java_VERSION_MINOR "${CMAKE_MATCH_1}")
set(Java_VERSION_PATCH "0")
set(Java_VERSION_TWEAK "")
elseif(var MATCHES "java full version \"kaffe-${_java_version_regex}\"")
# Kaffe style
set(Java_VERSION_STRING "${CMAKE_MATCH_1}")
elseif(var MATCHES "openjdk version \"([0-9]+\\.[0-9]+\\.[0-9_]+.*)\"")
# OpenJDK ver 1.7.x on OpenBSD
set(Java_VERSION_STRING "${CMAKE_MATCH_1}")
set(Java_VERSION_MAJOR "${CMAKE_MATCH_2}")
set(Java_VERSION_MINOR "${CMAKE_MATCH_4}")
set(Java_VERSION_PATCH "${CMAKE_MATCH_6}")
set(Java_VERSION_TWEAK "${CMAKE_MATCH_8}")
else()
if(NOT Java_FIND_QUIETLY)
message(WARNING "regex not supported: ${var}. Please report")
string(REPLACE "\n" "\n " ver_msg "\n${var}")
message(WARNING "Java version not recognized:${ver_msg}\nPlease report.")
endif()
set(Java_VERSION_STRING "")
set(Java_VERSION_MAJOR "")
set(Java_VERSION_MINOR "")
set(Java_VERSION_PATCH "")
set(Java_VERSION_TWEAK "")
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})
set(Java_VERSION "${Java_VERSION_MAJOR}")
if(NOT "x${Java_VERSION}" STREQUAL "x")
foreach(c MINOR PATCH TWEAK)
if(NOT "x${Java_VERSION_${c}}" STREQUAL "x")
string(APPEND Java_VERSION ".${Java_VERSION_${c}}")
else()
break()
endif()
endforeach()
endif()
endif()
......@@ -254,7 +271,7 @@ else()
find_package_handle_standard_args(Java
REQUIRED_VARS Java_JAVA_EXECUTABLE Java_JAR_EXECUTABLE Java_JAVAC_EXECUTABLE
Java_JAVAH_EXECUTABLE Java_JAVADOC_EXECUTABLE
VERSION_VAR Java_VERSION
VERSION_VAR Java_VERSION_STRING
)
endif()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment