diff options
author | Marc Chevrier <marc.chevrier@gmail.com> | 2022-05-05 09:18:55 (GMT) |
---|---|---|
committer | Marc Chevrier <marc.chevrier@gmail.com> | 2022-05-05 09:18:55 (GMT) |
commit | c80763c701a87eaeff2905791e511df1a3351fd7 (patch) | |
tree | cc93939dba1f6a85d0f10ad3291589f3b7d69481 /Modules/FindJNI.cmake | |
parent | d80c42668318617699ca1367a720de7215d1dadc (diff) | |
parent | 93e18a4eb6d57fe32e0272584ab9f70ebb4215e9 (diff) | |
download | CMake-c80763c701a87eaeff2905791e511df1a3351fd7.zip CMake-c80763c701a87eaeff2905791e511df1a3351fd7.tar.gz CMake-c80763c701a87eaeff2905791e511df1a3351fd7.tar.bz2 |
Merge branch 'backport-3.23-Java-version-handling' into Java-version-handling
Diffstat (limited to 'Modules/FindJNI.cmake')
-rw-r--r-- | Modules/FindJNI.cmake | 75 |
1 files changed, 30 insertions, 45 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 |