diff options
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 e4f60b3..5182401 100644 --- a/Modules/FindJNI.cmake +++ b/Modules/FindJNI.cmake @@ -145,46 +145,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 @@ -268,16 +263,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 |