Skip to content

Commit e8051b1

Browse files
committed
FindJava: Update check to avoid accepting macOS stub 'java' as Java
Since commit dd37825 (FindJava: Do not accept OS X stub 'java' as Java, 2014-10-24, v3.1.0-rc3~29^2) we try to avoid using the macOS `/usr/bin/java` stub if no underlying implementation of Java is actually installed. However, the message that `/usr/bin/java` prints when there is no Java available has changed since then. Update our check to also look for the new message. While at it, revise the way we suppress `Java_JAVA_EXECUTABLE`. Previously we set its cache entry to `Java_JAVA_EXECUTABLE-NOTFOUND`, but that would cause the same find-and-reject sequence to be followed every time CMake runs in a build tree. Instead, use the approach from commit 2c0db40 (FindSubversion: Do not accept macOS stub without Xcode implementation, 2020-05-28, v3.18.0-rc1~67^2). Leave the cache entry alone and just set a normal variable of the same name to hide it.
1 parent 1e26c84 commit e8051b1

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

Modules/FindJava.cmake

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,8 @@ if(Java_JAVA_EXECUTABLE)
160160
OUTPUT_STRIP_TRAILING_WHITESPACE
161161
ERROR_STRIP_TRAILING_WHITESPACE)
162162
if( res )
163-
if(var MATCHES "No Java runtime present, requesting install")
164-
set_property(CACHE Java_JAVA_EXECUTABLE
165-
PROPERTY VALUE "Java_JAVA_EXECUTABLE-NOTFOUND")
163+
if(var MATCHES "Unable to locate a Java Runtime to invoke|No Java runtime present, requesting install")
164+
set(Java_JAVA_EXECUTABLE Java_JAVA_EXECUTABLE-NOTFOUND)
166165
elseif(${Java_FIND_REQUIRED})
167166
message( FATAL_ERROR "Error executing java -version" )
168167
else()

0 commit comments

Comments
 (0)