summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Chevrier <marc.chevrier@gmail.com>2022-05-05 09:18:55 (GMT)
committerMarc Chevrier <marc.chevrier@gmail.com>2022-05-05 09:18:55 (GMT)
commitc80763c701a87eaeff2905791e511df1a3351fd7 (patch)
treecc93939dba1f6a85d0f10ad3291589f3b7d69481
parentd80c42668318617699ca1367a720de7215d1dadc (diff)
parent93e18a4eb6d57fe32e0272584ab9f70ebb4215e9 (diff)
downloadCMake-c80763c701a87eaeff2905791e511df1a3351fd7.zip
CMake-c80763c701a87eaeff2905791e511df1a3351fd7.tar.gz
CMake-c80763c701a87eaeff2905791e511df1a3351fd7.tar.bz2
Merge branch 'backport-3.23-Java-version-handling' into Java-version-handling
-rw-r--r--Modules/FindJNI.cmake75
-rw-r--r--Modules/FindJava.cmake49
2 files changed, 47 insertions, 77 deletions
diff --git a/Modules/FindJNI.cmake b/Modules/FindJNI.cmake
index 96f136a..e93b91e 100644
--- a/Modules/FindJNI.cmake
+++ b/Modules/FindJNI.cmake
@@ -234,46 +234,41 @@ endif()
if (WIN32)
set (_JNI_HINTS)
- execute_process(COMMAND REG QUERY HKLM\\SOFTWARE\\JavaSoft\\JDK
- RESULT_VARIABLE _JNI_RESULT
- OUTPUT_VARIABLE _JNI_VERSIONS
- ERROR_QUIET)
- if (NOT _JNI_RESULT)
- string (REGEX MATCHALL "HKEY_LOCAL_MACHINE\\\\SOFTWARE\\\\JavaSoft\\\\JDK\\\\[0-9.]+" _JNI_VERSIONS "${_JNI_VERSIONS}")
- if (_JNI_VERSIONS)
- # sort versions. Most recent first
- ## handle version 9 apart from other versions to get correct ordering
- set (_JNI_V9 ${_JNI_VERSIONS})
- list (FILTER _JNI_VERSIONS EXCLUDE REGEX "JDK\\\\9")
- list (SORT _JNI_VERSIONS)
- list (REVERSE _JNI_VERSIONS)
- list (FILTER _JNI_V9 INCLUDE REGEX "JDK\\\\9")
- list (SORT _JNI_V9)
- list (REVERSE _JNI_V9)
- list (APPEND _JNI_VERSIONS ${_JNI_V9})
- foreach (_JNI_HINT IN LISTS _JNI_VERSIONS)
- list(APPEND _JNI_HINTS "[${_JNI_HINT};JavaHome]")
- endforeach()
+ macro (_JNI_GET_INSTALLED_VERSIONS _KIND)
+ execute_process(COMMAND REG QUERY "HKLM\\SOFTWARE\\JavaSoft\\${_KIND}"
+ RESULT_VARIABLE _JAVA_RESULT
+ OUTPUT_VARIABLE _JAVA_VERSIONS
+ ERROR_QUIET)
+ if (NOT _JAVA_RESULT)
+ string (REGEX MATCHALL "HKEY_LOCAL_MACHINE\\\\SOFTWARE\\\\JavaSoft\\\\${_KIND}\\\\[0-9._]+" _JNI_VERSIONS "${_JAVA_VERSIONS}")
+ string (REGEX REPLACE "HKEY_LOCAL_MACHINE\\\\SOFTWARE\\\\JavaSoft\\\\${_KIND}\\\\([0-9._]+)" "\\1" _JNI_VERSIONS "${_JNI_VERSIONS}")
+ if (_JNI_VERSIONS)
+ # sort versions. Most recent first
+ list (SORT _JNI_VERSIONS COMPARE NATURAL ORDER DESCENDING)
+ foreach (_JNI_VERSION IN LISTS _JNI_VERSIONS)
+ string(REPLACE "_" "." _JNI_CMAKE_VERSION "${_JNI_VERSION}")
+ if (JNI_FIND_VERSION_EXACT
+ AND NOT _JNI_CMAKE_VERSION MATCHES "^${JNI_FIND_VERSION}")
+ continue()
+ endif()
+ if (DEFINED JNI_FIND_VERSION AND _JNI_CMAKE_VERSION VERSION_LESS JNI_FIND_VERSION)
+ break()
+ endif()
+ list(APPEND _JNI_HINTS "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\${_KIND}\\${_JNI_VERSION};JavaHome]")
+ endforeach()
+ endif()
endif()
- endif()
+ endmacro()
+
+ # for version 9 and upper
+ _JNI_GET_INSTALLED_VERSIONS("JDK")
+
+ # for versions older than 9
+ _JNI_GET_INSTALLED_VERSIONS("Java Development Kit")
foreach (_JNI_HINT IN LISTS _JNI_HINTS)
list(APPEND JAVA_AWT_LIBRARY_DIRECTORIES "${_JNI_HINT}/lib")
endforeach()
-
- get_filename_component(java_install_version
- "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit;CurrentVersion]" NAME)
-
- list(APPEND JAVA_AWT_LIBRARY_DIRECTORIES
- "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.9;JavaHome]/lib"
- "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.8;JavaHome]/lib"
- "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.7;JavaHome]/lib"
- "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.6;JavaHome]/lib"
- "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.5;JavaHome]/lib"
- "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.4;JavaHome]/lib"
- "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.3;JavaHome]/lib"
- "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\${java_install_version};JavaHome]/lib"
- )
endif()
set(_JNI_JAVA_DIRECTORIES_BASE
@@ -357,16 +352,6 @@ if (WIN32)
foreach (_JNI_HINT IN LISTS _JNI_HINTS)
list(APPEND JAVA_AWT_INCLUDE_DIRECTORIES "${_JNI_HINT}/include")
endforeach()
- list(APPEND JAVA_AWT_INCLUDE_DIRECTORIES
- "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.9;JavaHome]/include"
- "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.8;JavaHome]/include"
- "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.7;JavaHome]/include"
- "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.6;JavaHome]/include"
- "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.5;JavaHome]/include"
- "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.4;JavaHome]/include"
- "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.3;JavaHome]/include"
- "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\${java_install_version};JavaHome]/include"
- )
endif()
JAVA_APPEND_LIBRARY_DIRECTORIES(JAVA_AWT_INCLUDE_DIRECTORIES
diff --git a/Modules/FindJava.cmake b/Modules/FindJava.cmake
index 4f0e0fe..7a95ef5 100644
--- a/Modules/FindJava.cmake
+++ b/Modules/FindJava.cmake
@@ -90,50 +90,35 @@ if(_JAVA_HOME)
endif()
if (WIN32)
macro (_JAVA_GET_INSTALLED_VERSIONS _KIND)
- execute_process(COMMAND REG QUERY HKLM\\SOFTWARE\\JavaSoft\\${_KIND}
+ execute_process(COMMAND REG QUERY "HKLM\\SOFTWARE\\JavaSoft\\${_KIND}"
RESULT_VARIABLE _JAVA_RESULT
OUTPUT_VARIABLE _JAVA_VERSIONS
ERROR_QUIET)
if (NOT _JAVA_RESULT)
- string (REGEX MATCHALL "HKEY_LOCAL_MACHINE\\\\SOFTWARE\\\\JavaSoft\\\\${_KIND}\\\\[0-9.]+" _JAVA_VERSIONS "${_JAVA_VERSIONS}")
+ string (REGEX MATCHALL "HKEY_LOCAL_MACHINE\\\\SOFTWARE\\\\JavaSoft\\\\${_KIND}\\\\[0-9._]+" _JAVA_VERSIONS "${_JAVA_VERSIONS}")
+ string (REGEX REPLACE "HKEY_LOCAL_MACHINE\\\\SOFTWARE\\\\JavaSoft\\\\${_KIND}\\\\([0-9._]+)" "\\1" _JAVA_VERSIONS "${_JAVA_VERSIONS}")
if (_JAVA_VERSIONS)
# sort versions. Most recent first
- ## handle version 9 apart from other versions to get correct ordering
- set (_JAVA_V9 ${_JAVA_VERSIONS})
- list (FILTER _JAVA_VERSIONS EXCLUDE REGEX "${_KIND}\\\\9")
- list (SORT _JAVA_VERSIONS)
- list (REVERSE _JAVA_VERSIONS)
- list (FILTER _JAVA_V9 INCLUDE REGEX "${_KIND}\\\\9")
- list (SORT _JAVA_V9)
- list (REVERSE _JAVA_V9)
- list (APPEND _JAVA_VERSIONS ${_JAVA_V9})
- foreach (_JAVA_HINT IN LISTS _JAVA_VERSIONS)
- list(APPEND _JAVA_HINTS "[${_JAVA_HINT};JavaHome]/bin")
+ list (SORT _JAVA_VERSIONS COMPARE NATURAL ORDER DESCENDING)
+ foreach (_JAVA_VERSION IN LISTS _JAVA_VERSIONS)
+ string(REPLACE "_" "." _JAVA_CMAKE_VERSION "${_JAVA_VERSION}")
+ if (Java_FIND_VERSION_EXACT
+ AND NOT _JAVA_CMAKE_VERSION MATCHES "^${Java_FIND_VERSION}")
+ continue()
+ endif()
+ list(APPEND _JAVA_HINTS "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\${_KIND}\\${_JAVA_VERSION};JavaHome]/bin")
endforeach()
endif()
endif()
endmacro()
- # search for installed versions for version 9 and upper
+ # for version 9 and upper
_JAVA_GET_INSTALLED_VERSIONS("JDK")
_JAVA_GET_INSTALLED_VERSIONS("JRE")
- list(APPEND _JAVA_HINTS
- "[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"
- "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Runtime Environment\\1.9;JavaHome]/bin"
- "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Runtime Environment\\1.8;JavaHome]/bin"
- "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Runtime Environment\\1.7;JavaHome]/bin"
- "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Runtime Environment\\1.6;JavaHome]/bin"
- "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Runtime Environment\\1.5;JavaHome]/bin"
- "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Runtime Environment\\1.4;JavaHome]/bin"
- "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Runtime Environment\\1.3;JavaHome]/bin"
- )
+ # for versions older than 9
+ _JAVA_GET_INSTALLED_VERSIONS("Java Development Kit")
+ _JAVA_GET_INSTALLED_VERSIONS("Java Runtime Environment")
endif()
# Hard-coded guesses should still go in PATHS. This ensures that the user
@@ -336,13 +321,13 @@ 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_STRING
+ VERSION_VAR Java_VERSION
)
else()
find_package_handle_standard_args(Java
REQUIRED_VARS Java_JAVA_EXECUTABLE Java_JAR_EXECUTABLE Java_JAVAC_EXECUTABLE
Java_JAVADOC_EXECUTABLE
- VERSION_VAR Java_VERSION_STRING
+ VERSION_VAR Java_VERSION
)
endif()
endif()