summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2023-09-21 12:07:23 (GMT)
committerKitware Robot <kwrobot@kitware.com>2023-09-21 12:07:18 (GMT)
commit8030dd0986716df5368813b5792dbb28fb06ed82 (patch)
treedb3ad282ea0c5345b19a18301a743e5af72e0dd6
parent6a9a738e991ed3d92d4ad60fe59c5341a5a87449 (diff)
parentd95988c8c3eed40f36f0b39e326ec389f8a1ebc2 (diff)
downloadCMake-8030dd0986716df5368813b5792dbb28fb06ed82.zip
CMake-8030dd0986716df5368813b5792dbb28fb06ed82.tar.gz
CMake-8030dd0986716df5368813b5792dbb28fb06ed82.tar.bz2
Merge topic 'findjava'
d95988c8c3 FindJNI: use modern foreach() syntax 7e4fe71633 FindJNI: use 2-space indents 88411fd629 FindJNI: use cmake_host_system_info to query registry b56d4e041a FindJava: use cmake_host_system_info to query registry bab9a23724 FindJava: use modern foreach() syntax Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !8818
-rw-r--r--Modules/FindJNI.cmake153
-rw-r--r--Modules/FindJava.cmake19
2 files changed, 85 insertions, 87 deletions
diff --git a/Modules/FindJNI.cmake b/Modules/FindJNI.cmake
index e7050a3..abc76cf 100644
--- a/Modules/FindJNI.cmake
+++ b/Modules/FindJNI.cmake
@@ -136,76 +136,76 @@ endif()
# Expand {libarch} occurrences to java_libarch subdirectory(-ies) and set ${_var}
macro(java_append_library_directories _var)
- # Determine java arch-specific library subdir
- # Mostly based on openjdk/jdk/make/common/shared/Platform.gmk as of openjdk
- # 1.6.0_18 + icedtea patches. However, it would be much better to base the
- # guess on the first part of the GNU config.guess platform triplet.
- if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
- if(CMAKE_LIBRARY_ARCHITECTURE STREQUAL "x86_64-linux-gnux32")
- set(_java_libarch "x32" "amd64" "i386")
- else()
- set(_java_libarch "amd64" "i386")
- endif()
- elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^i.86$")
- set(_java_libarch "i386")
- elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^aarch64")
- set(_java_libarch "arm64" "aarch64")
- elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^alpha")
- set(_java_libarch "alpha")
- elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^arm")
- # Subdir is "arm" for both big-endian (arm) and little-endian (armel).
- set(_java_libarch "arm" "aarch32")
- elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^mips")
- # mips* machines are bi-endian mostly so processor does not tell
- # endianness of the underlying system.
- set(_java_libarch "${CMAKE_SYSTEM_PROCESSOR}"
- "mips" "mipsel" "mipseb" "mipsr6" "mipsr6el"
- "mips64" "mips64el" "mips64r6" "mips64r6el"
- "mipsn32" "mipsn32el" "mipsn32r6" "mipsn32r6el")
- elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(powerpc|ppc)64le")
- set(_java_libarch "ppc64" "ppc64le")
- elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(powerpc|ppc)64")
- set(_java_libarch "ppc64" "ppc")
- elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(powerpc|ppc)")
- set(_java_libarch "ppc" "ppc64")
- elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^sparc")
- # Both flavors can run on the same processor
- set(_java_libarch "${CMAKE_SYSTEM_PROCESSOR}" "sparc" "sparcv9")
- elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(parisc|hppa)")
- set(_java_libarch "parisc" "parisc64")
- elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^s390")
- # s390 binaries can run on s390x machines
- set(_java_libarch "${CMAKE_SYSTEM_PROCESSOR}" "s390" "s390x")
- elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^sh")
- set(_java_libarch "sh")
+ # Determine java arch-specific library subdir
+ # Mostly based on openjdk/jdk/make/common/shared/Platform.gmk as of openjdk
+ # 1.6.0_18 + icedtea patches. However, it would be much better to base the
+ # guess on the first part of the GNU config.guess platform triplet.
+ if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
+ if(CMAKE_LIBRARY_ARCHITECTURE STREQUAL "x86_64-linux-gnux32")
+ set(_java_libarch "x32" "amd64" "i386")
else()
- set(_java_libarch "${CMAKE_SYSTEM_PROCESSOR}")
+ set(_java_libarch "amd64" "i386")
endif()
+ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^i.86$")
+ set(_java_libarch "i386")
+ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^aarch64")
+ set(_java_libarch "arm64" "aarch64")
+ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^alpha")
+ set(_java_libarch "alpha")
+ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^arm")
+ # Subdir is "arm" for both big-endian (arm) and little-endian (armel).
+ set(_java_libarch "arm" "aarch32")
+ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^mips")
+ # mips* machines are bi-endian mostly so processor does not tell
+ # endianness of the underlying system.
+ set(_java_libarch "${CMAKE_SYSTEM_PROCESSOR}"
+ "mips" "mipsel" "mipseb" "mipsr6" "mipsr6el"
+ "mips64" "mips64el" "mips64r6" "mips64r6el"
+ "mipsn32" "mipsn32el" "mipsn32r6" "mipsn32r6el")
+ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(powerpc|ppc)64le")
+ set(_java_libarch "ppc64" "ppc64le")
+ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(powerpc|ppc)64")
+ set(_java_libarch "ppc64" "ppc")
+ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(powerpc|ppc)")
+ set(_java_libarch "ppc" "ppc64")
+ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^sparc")
+ # Both flavors can run on the same processor
+ set(_java_libarch "${CMAKE_SYSTEM_PROCESSOR}" "sparc" "sparcv9")
+ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(parisc|hppa)")
+ set(_java_libarch "parisc" "parisc64")
+ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^s390")
+ # s390 binaries can run on s390x machines
+ set(_java_libarch "${CMAKE_SYSTEM_PROCESSOR}" "s390" "s390x")
+ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^sh")
+ set(_java_libarch "sh")
+ else()
+ set(_java_libarch "${CMAKE_SYSTEM_PROCESSOR}")
+ endif()
- # Append default list architectures if CMAKE_SYSTEM_PROCESSOR was empty or
- # system is non-Linux (where the code above has not been well tested)
- if(NOT _java_libarch OR NOT (CMAKE_SYSTEM_NAME MATCHES "Linux"))
- list(APPEND _java_libarch "i386" "amd64" "ppc")
- endif()
+ # Append default list architectures if CMAKE_SYSTEM_PROCESSOR was empty or
+ # system is non-Linux (where the code above has not been well tested)
+ if(NOT _java_libarch OR NOT (CMAKE_SYSTEM_NAME MATCHES "Linux"))
+ list(APPEND _java_libarch "i386" "amd64" "ppc")
+ endif()
- # Sometimes ${CMAKE_SYSTEM_PROCESSOR} is added to the list to prefer
- # current value to a hardcoded list. Remove possible duplicates.
- list(REMOVE_DUPLICATES _java_libarch)
-
- foreach(_path ${ARGN})
- if(_path MATCHES "{libarch}")
- foreach(_libarch ${_java_libarch})
- string(REPLACE "{libarch}" "${_libarch}" _newpath "${_path}")
- if(EXISTS ${_newpath})
- list(APPEND ${_var} "${_newpath}")
- endif()
- endforeach()
- else()
- if(EXISTS ${_path})
- list(APPEND ${_var} "${_path}")
- endif()
+ # Sometimes ${CMAKE_SYSTEM_PROCESSOR} is added to the list to prefer
+ # current value to a hardcoded list. Remove possible duplicates.
+ list(REMOVE_DUPLICATES _java_libarch)
+
+ foreach(_path ${ARGN})
+ if(_path MATCHES "{libarch}")
+ foreach(_libarch IN LISTS _java_libarch)
+ string(REPLACE "{libarch}" "${_libarch}" _newpath "${_path}")
+ if(EXISTS ${_newpath})
+ list(APPEND ${_var} "${_newpath}")
endif()
- endforeach()
+ endforeach()
+ else()
+ if(EXISTS ${_path})
+ list(APPEND ${_var} "${_path}")
+ endif()
+ endif()
+ endforeach()
endmacro()
include(${CMAKE_CURRENT_LIST_DIR}/CMakeFindJavaCommon.cmake)
@@ -235,13 +235,12 @@ endif()
if (WIN32)
set (_JNI_HINTS)
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}")
+ cmake_host_system_information(RESULT _JNI_VERSIONS
+ QUERY WINDOWS_REGISTRY "HKLM/SOFTWARE/JavaSoft/${_KIND}"
+ SUBKEYS)
+ if (_JNI_VERSIONS)
+ string (REGEX MATCHALL "[0-9._]+" _JNI_VERSIONS "${_JNI_VERSIONS}")
+ string (REGEX REPLACE "([0-9._]+)" "\\1" _JNI_VERSIONS "${_JNI_VERSIONS}")
if (_JNI_VERSIONS)
# sort versions. Most recent first
list (SORT _JNI_VERSIONS COMPARE NATURAL ORDER DESCENDING)
@@ -340,7 +339,7 @@ JAVA_APPEND_LIBRARY_DIRECTORIES(JAVA_AWT_LIBRARY_DIRECTORIES
)
set(JAVA_JVM_LIBRARY_DIRECTORIES)
-foreach(dir ${JAVA_AWT_LIBRARY_DIRECTORIES})
+foreach(dir IN LISTS JAVA_AWT_LIBRARY_DIRECTORIES)
list(APPEND JAVA_JVM_LIBRARY_DIRECTORIES
"${dir}"
"${dir}/client"
@@ -365,14 +364,14 @@ JAVA_APPEND_LIBRARY_DIRECTORIES(JAVA_AWT_INCLUDE_DIRECTORIES
${_JNI_JAVA_INCLUDE_TRIES}
)
-foreach(JAVA_PROG "${JAVA_RUNTIME}" "${JAVA_COMPILE}" "${JAVA_ARCHIVE}")
+foreach(JAVA_PROG IN ITEMS "${JAVA_RUNTIME}" "${JAVA_COMPILE}" "${JAVA_ARCHIVE}")
get_filename_component(jpath "${JAVA_PROG}" PATH)
- foreach(JAVA_INC_PATH ../include ../java/include ../share/java/include)
+ foreach(JAVA_INC_PATH IN ITEMS ../include ../java/include ../share/java/include)
if(EXISTS ${jpath}/${JAVA_INC_PATH})
list(APPEND JAVA_AWT_INCLUDE_DIRECTORIES "${jpath}/${JAVA_INC_PATH}")
endif()
endforeach()
- foreach(JAVA_LIB_PATH
+ foreach(JAVA_LIB_PATH IN ITEMS
../lib ../jre/lib ../jre/lib/i386
../java/lib ../java/jre/lib ../java/jre/lib/i386
../share/java/lib ../share/java/jre/lib ../share/java/jre/lib/i386)
@@ -429,7 +428,7 @@ set(_JNI_NORMAL_JAWT
PATHS ${JAVA_AWT_LIBRARY_DIRECTORIES}
)
-foreach(search ${_JNI_SEARCHES})
+foreach(search IN LISTS _JNI_SEARCHES)
if(JVM IN_LIST JNI_FIND_COMPONENTS)
find_library(JAVA_JVM_LIBRARY ${_JNI_${search}_JVM}
DOC "Java Virtual Machine library"
diff --git a/Modules/FindJava.cmake b/Modules/FindJava.cmake
index e8fb120..74e424b 100644
--- a/Modules/FindJava.cmake
+++ b/Modules/FindJava.cmake
@@ -90,13 +90,12 @@ if(_JAVA_HOME)
endif()
if (WIN32)
macro (_JAVA_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._]+" _JAVA_VERSIONS "${_JAVA_VERSIONS}")
- string (REGEX REPLACE "HKEY_LOCAL_MACHINE\\\\SOFTWARE\\\\JavaSoft\\\\${_KIND}\\\\([0-9._]+)" "\\1" _JAVA_VERSIONS "${_JAVA_VERSIONS}")
+ cmake_host_system_information(RESULT _JAVA_VERSIONS
+ QUERY WINDOWS_REGISTRY "HKLM/SOFTWARE/JavaSoft/${_KIND}"
+ SUBKEYS)
+ if (_JAVA_VERSIONS)
+ string (REGEX MATCHALL "[0-9._]+" _JAVA_VERSIONS "${_JAVA_VERSIONS}")
+ string (REGEX REPLACE "([0-9._]+)" "\\1" _JAVA_VERSIONS "${_JAVA_VERSIONS}")
if (_JAVA_VERSIONS)
# sort versions. Most recent first
list (SORT _JAVA_VERSIONS COMPARE NATURAL ORDER DESCENDING)
@@ -221,7 +220,7 @@ if(Java_JAVA_EXECUTABLE)
unset(_java_var)
set(Java_VERSION "${Java_VERSION_MAJOR}")
if(NOT "x${Java_VERSION}" STREQUAL "x")
- foreach(_java_c MINOR PATCH TWEAK)
+ foreach(_java_c IN ITEMS "MINOR" "PATCH" "TWEAK")
if(NOT "x${Java_VERSION_${_java_c}}" STREQUAL "x")
string(APPEND Java_VERSION ".${Java_VERSION_${_java_c}}")
else()
@@ -274,7 +273,7 @@ find_program(Java_JARSIGNER_EXECUTABLE
include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
if(Java_FIND_COMPONENTS)
set(_JAVA_REQUIRED_VARS)
- foreach(component ${Java_FIND_COMPONENTS})
+ foreach(component IN LISTS Java_FIND_COMPONENTS)
# User just want to execute some Java byte-compiled
If(component STREQUAL "Runtime")
list(APPEND _JAVA_REQUIRED_VARS Java_JAVA_EXECUTABLE)
@@ -316,7 +315,7 @@ if(Java_FIND_COMPONENTS)
VERSION_VAR Java_VERSION
)
if(Java_FOUND)
- foreach(component ${Java_FIND_COMPONENTS})
+ foreach(component IN LISTS Java_FIND_COMPONENTS)
set(Java_${component}_FOUND TRUE)
endforeach()
endif()