diff options
author | Brad King <brad.king@kitware.com> | 2017-10-06 11:30:07 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2017-10-06 11:30:07 (GMT) |
commit | 25510a09d5e8e3881c949d5fd7ba698dab7d144c (patch) | |
tree | b8d96c9f27391d69395b38d75d0263203dc4bef3 /Modules | |
parent | bd9451231cedef1ebf0e55706a9abb68f53b3a8e (diff) | |
parent | 6feb0c3318305c4347ac02a0c1d991b98802bd3e (diff) | |
download | CMake-25510a09d5e8e3881c949d5fd7ba698dab7d144c.zip CMake-25510a09d5e8e3881c949d5fd7ba698dab7d144c.tar.gz CMake-25510a09d5e8e3881c949d5fd7ba698dab7d144c.tar.bz2 |
Merge branch 'FindJava-tolerant-versions' into release-3.10
Merge-request: !1355
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/FindJava.cmake | 67 |
1 files changed, 42 insertions, 25 deletions
diff --git a/Modules/FindJava.cmake b/Modules/FindJava.cmake index eb2242b..b913e17 100644 --- a/Modules/FindJava.cmake +++ b/Modules/FindJava.cmake @@ -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() |