FindJNI: Overhaul finding JDK libraries and headers on OS X
Drop the hard-coded framework paths and "-framework JavaJM" on APPLE. Save and restore the value of CMAKE_FIND_FRAMEWORK. Use its value to choose and order between a normal search for jvm&jawt and a framework search for JavaVM. When JAVA_HOME is set explicitly by the user then force a normal search by setting CMAKE_FIND_FRAMEWORK to NEVER. Once the library is found, set CMAKE_FIND_FRAMEWORK to help find_path locate the matching headers (framework v. normal).
This commit is contained in:
parent
fcd66a7f7b
commit
70560ee146
|
@ -96,6 +96,17 @@ endmacro()
|
|||
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/CMakeFindJavaCommon.cmake)
|
||||
|
||||
# Save CMAKE_FIND_FRAMEWORK
|
||||
if(DEFINED CMAKE_FIND_FRAMEWORK)
|
||||
set(_JNI_CMAKE_FIND_FRAMEWORK ${CMAKE_FIND_FRAMEWORK})
|
||||
else()
|
||||
unset(_JNI_CMAKE_FIND_FRAMEWORK)
|
||||
endif()
|
||||
|
||||
if(_JAVA_HOME_EXPLICIT)
|
||||
set(CMAKE_FIND_FRAMEWORK NEVER)
|
||||
endif()
|
||||
|
||||
set(JAVA_AWT_LIBRARY_DIRECTORIES)
|
||||
if(_JAVA_HOME)
|
||||
JAVA_APPEND_LIBRARY_DIRECTORIES(JAVA_AWT_LIBRARY_DIRECTORIES
|
||||
|
@ -195,48 +206,49 @@ foreach(JAVA_PROG "${JAVA_RUNTIME}" "${JAVA_COMPILE}" "${JAVA_ARCHIVE}")
|
|||
endforeach()
|
||||
|
||||
if(APPLE)
|
||||
if(EXISTS ~/Library/Frameworks/JavaVM.framework)
|
||||
set(JAVA_HAVE_FRAMEWORK 1)
|
||||
endif()
|
||||
if(EXISTS /Library/Frameworks/JavaVM.framework)
|
||||
set(JAVA_HAVE_FRAMEWORK 1)
|
||||
endif()
|
||||
if(EXISTS /System/Library/Frameworks/JavaVM.framework)
|
||||
set(JAVA_HAVE_FRAMEWORK 1)
|
||||
endif()
|
||||
|
||||
if(JAVA_HAVE_FRAMEWORK)
|
||||
if(NOT JAVA_AWT_LIBRARY)
|
||||
set (JAVA_AWT_LIBRARY "-framework JavaVM" CACHE FILEPATH "Java Frameworks" FORCE)
|
||||
endif()
|
||||
|
||||
if(NOT JAVA_JVM_LIBRARY)
|
||||
set (JAVA_JVM_LIBRARY "-framework JavaVM" CACHE FILEPATH "Java Frameworks" FORCE)
|
||||
endif()
|
||||
|
||||
if(NOT JAVA_AWT_INCLUDE_PATH)
|
||||
if(EXISTS /System/Library/Frameworks/JavaVM.framework/Headers/jawt.h)
|
||||
set (JAVA_AWT_INCLUDE_PATH "/System/Library/Frameworks/JavaVM.framework/Headers" CACHE FILEPATH "jawt.h location" FORCE)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# If using "-framework JavaVM", prefer its headers *before* the others in
|
||||
# JAVA_AWT_INCLUDE_DIRECTORIES... (*prepend* to the list here)
|
||||
#
|
||||
set(JAVA_AWT_INCLUDE_DIRECTORIES
|
||||
~/Library/Frameworks/JavaVM.framework/Headers
|
||||
/Library/Frameworks/JavaVM.framework/Headers
|
||||
/System/Library/Frameworks/JavaVM.framework/Headers
|
||||
${JAVA_AWT_INCLUDE_DIRECTORIES}
|
||||
)
|
||||
if(CMAKE_FIND_FRAMEWORK STREQUAL "ONLY")
|
||||
set(_JNI_SEARCHES FRAMEWORK)
|
||||
elseif(CMAKE_FIND_FRAMEWORK STREQUAL "NEVER")
|
||||
set(_JNI_SEARCHES NORMAL)
|
||||
elseif(CMAKE_FIND_FRAMEWORK STREQUAL "LAST")
|
||||
set(_JNI_SEARCHES NORMAL FRAMEWORK)
|
||||
else()
|
||||
set(_JNI_SEARCHES FRAMEWORK NORMAL)
|
||||
endif()
|
||||
set(_JNI_FRAMEWORK_JVM NAMES JavaVM)
|
||||
set(_JNI_FRAMEWORK_JAWT "${_JNI_FRAMEWORK_JVM}")
|
||||
else()
|
||||
find_library(JAVA_AWT_LIBRARY jawt
|
||||
PATHS ${JAVA_AWT_LIBRARY_DIRECTORIES}
|
||||
set(_JNI_SEARCHES NORMAL)
|
||||
endif()
|
||||
|
||||
set(_JNI_NORMAL_JVM
|
||||
NAMES jvm
|
||||
PATHS ${JAVA_JVM_LIBRARY_DIRECTORIES}
|
||||
)
|
||||
find_library(JAVA_JVM_LIBRARY NAMES jvm JavaVM
|
||||
PATHS ${JAVA_JVM_LIBRARY_DIRECTORIES}
|
||||
|
||||
set(_JNI_NORMAL_JAWT
|
||||
NAMES jawt
|
||||
PATHS ${JAVA_AWT_LIBRARY_DIRECTORIES}
|
||||
)
|
||||
|
||||
foreach(search ${_JNI_SEARCHES})
|
||||
find_library(JAVA_JVM_LIBRARY ${_JNI_${search}_JVM})
|
||||
find_library(JAVA_AWT_LIBRARY ${_JNI_${search}_JAWT})
|
||||
if(JAVA_JVM_LIBRARY)
|
||||
break()
|
||||
endif()
|
||||
endforeach()
|
||||
unset(_JNI_SEARCHES)
|
||||
unset(_JNI_FRAMEWORK_JVM)
|
||||
unset(_JNI_FRAMEWORK_JAWT)
|
||||
unset(_JNI_NORMAL_JVM)
|
||||
unset(_JNI_NORMAL_JAWT)
|
||||
|
||||
# Find headers matching the library.
|
||||
if("${JAVA_JVM_LIBRARY};${JAVA_AWT_LIBRARY};" MATCHES "(/JavaVM.framework|-framework JavaVM);")
|
||||
set(CMAKE_FIND_FRAMEWORK ONLY)
|
||||
else()
|
||||
set(CMAKE_FIND_FRAMEWORK NEVER)
|
||||
endif()
|
||||
|
||||
# add in the include path
|
||||
|
@ -260,6 +272,14 @@ find_path(JAVA_AWT_INCLUDE_PATH jawt.h
|
|||
${JAVA_INCLUDE_PATH}
|
||||
)
|
||||
|
||||
# Restore CMAKE_FIND_FRAMEWORK
|
||||
if(DEFINED _JNI_CMAKE_FIND_FRAMEWORK)
|
||||
set(CMAKE_FIND_FRAMEWORK ${_JNI_CMAKE_FIND_FRAMEWORK})
|
||||
unset(_JNI_CMAKE_FIND_FRAMEWORK)
|
||||
else()
|
||||
unset(CMAKE_FIND_FRAMEWORK)
|
||||
endif()
|
||||
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
|
||||
FIND_PACKAGE_HANDLE_STANDARD_ARGS(JNI DEFAULT_MSG JAVA_AWT_LIBRARY JAVA_JVM_LIBRARY
|
||||
JAVA_INCLUDE_PATH JAVA_INCLUDE_PATH2 JAVA_AWT_INCLUDE_PATH)
|
||||
|
|
Loading…
Reference in New Issue