1 # - Find JNI java libraries.
2 # This module finds if Java is installed and determines where the
3 # include files and libraries are. It also determines what the name of
4 # the library is. This code sets the following variables:
6 # JNI_INCLUDE_DIRS = the include dirs to use
7 # JNI_LIBRARIES = the libraries to use
8 # JNI_FOUND = TRUE if JNI headers and libraries were found.
9 # JAVA_AWT_LIBRARY = the path to the jawt library
10 # JAVA_JVM_LIBRARY = the path to the jvm library
11 # JAVA_INCLUDE_PATH = the include path to jni.h
12 # JAVA_INCLUDE_PATH2 = the include path to jni_md.h
13 # JAVA_AWT_INCLUDE_PATH = the include path to jawt.h
16 #=============================================================================
17 # Copyright 2001-2009 Kitware, Inc.
19 # Distributed under the OSI-approved BSD License (the "License");
20 # see accompanying file Copyright.txt for details.
22 # This software is distributed WITHOUT ANY WARRANTY; without even the
23 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
24 # See the License for more information.
25 #=============================================================================
26 # (To distribute this file outside of CMake, substitute the full
27 # License text for the above reference.)
29 # Expand {libarch} occurences to java_libarch subdirectory(-ies) and set ${_var}
30 macro(java_append_library_directories _var)
31 # Determine java arch-specific library subdir
32 # Mostly based on openjdk/jdk/make/common/shared/Platform.gmk as of openjdk
33 # 1.6.0_18 + icedtea patches. However, it would be much better to base the
34 # guess on the first part of the GNU config.guess platform triplet.
35 if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
36 set(_java_libarch "amd64")
37 elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^i.86$")
38 set(_java_libarch "i386")
39 elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^alpha")
40 set(_java_libarch "alpha")
41 elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^arm")
42 # Subdir is "arm" for both big-endian (arm) and little-endian (armel).
43 set(_java_libarch "arm")
44 elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^mips")
45 # mips* machines are bi-endian mostly so processor does not tell
46 # endianess of the underlying system.
47 set(_java_libarch "${CMAKE_SYSTEM_PROCESSOR}" "mips" "mipsel" "mipseb")
48 elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(powerpc|ppc)64")
49 set(_java_libarch "ppc64")
50 elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(powerpc|ppc)")
51 set(_java_libarch "ppc")
52 elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^sparc")
53 # Both flavours can run on the same processor
54 set(_java_libarch "${CMAKE_SYSTEM_PROCESSOR}" "sparc" "sparcv9")
55 elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(parisc|hppa)")
56 set(_java_libarch "parisc" "parisc64")
57 elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^s390")
58 # s390 binaries can run on s390x machines
59 set(_java_libarch "${CMAKE_SYSTEM_PROCESSOR}" "s390" "s390x")
60 elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^sh")
61 set(_java_libarch "sh")
63 set(_java_libarch "${CMAKE_SYSTEM_PROCESSOR}")
66 # Append default list architectures if CMAKE_SYSTEM_PROCESSOR was empty or
67 # system is non-Linux (where the code above has not been well tested)
68 if(NOT _java_libarch OR NOT (CMAKE_SYSTEM_NAME MATCHES "Linux"))
69 list(APPEND _java_libarch "i386" "amd64" "ppc")
72 # Sometimes ${CMAKE_SYSTEM_PROCESSOR} is added to the list to prefer
73 # current value to a hardcoded list. Remove possible duplicates.
74 list(REMOVE_DUPLICATES _java_libarch)
76 foreach(_path ${ARGN})
77 if(_path MATCHES "{libarch}")
78 foreach(_libarch ${_java_libarch})
79 string(REPLACE "{libarch}" "${_libarch}" _newpath "${_path}")
80 list(APPEND ${_var} "${_newpath}")
83 list(APPEND ${_var} "${_path}")
88 get_filename_component(java_install_version
89 "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit;CurrentVersion]" NAME)
91 set(JAVA_AWT_LIBRARY_DIRECTORIES
92 "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.4;JavaHome]/lib"
93 "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.3;JavaHome]/lib"
94 "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\${java_install_version};JavaHome]/lib"
97 file(TO_CMAKE_PATH "$ENV{JAVA_HOME}" _JAVA_HOME)
99 JAVA_APPEND_LIBRARY_DIRECTORIES(JAVA_AWT_LIBRARY_DIRECTORIES
100 ${_JAVA_HOME}/jre/lib/{libarch}
101 ${_JAVA_HOME}/jre/lib
106 /usr/lib/jvm/java/lib
107 /usr/lib/java/jre/lib/{libarch}
108 /usr/lib/jvm/jre/lib/{libarch}
109 /usr/local/lib/java/jre/lib/{libarch}
110 /usr/local/share/java/jre/lib/{libarch}
111 /usr/lib/j2sdk1.4-sun/jre/lib/{libarch}
112 /usr/lib/j2sdk1.5-sun/jre/lib/{libarch}
113 /opt/sun-jdk-1.5.0.04/jre/lib/{libarch}
114 /usr/lib/jvm/java-6-sun/jre/lib/{libarch}
115 /usr/lib/jvm/java-1.5.0-sun/jre/lib/{libarch}
116 /usr/lib/jvm/java-6-sun-1.6.0.00/jre/lib/{libarch} # can this one be removed according to #8821 ? Alex
117 /usr/lib/jvm/java-6-openjdk/jre/lib/{libarch}
118 /usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0/jre/lib/{libarch} # fedora
119 # Debian specific paths for default JVM
120 /usr/lib/jvm/default-java/jre/lib/{libarch}
121 /usr/lib/jvm/default-java/jre/lib
122 /usr/lib/jvm/default-java/lib
125 set(JAVA_JVM_LIBRARY_DIRECTORIES)
126 foreach(dir ${JAVA_AWT_LIBRARY_DIRECTORIES})
127 set(JAVA_JVM_LIBRARY_DIRECTORIES
128 ${JAVA_JVM_LIBRARY_DIRECTORIES}
136 set(JAVA_AWT_INCLUDE_DIRECTORIES
137 "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.4;JavaHome]/include"
138 "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.3;JavaHome]/include"
139 "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\${java_install_version};JavaHome]/include"
140 ${_JAVA_HOME}/include
143 /usr/lib/java/include
144 /usr/local/lib/java/include
145 /usr/lib/jvm/java/include
146 /usr/lib/jvm/java-6-sun/include
147 /usr/lib/jvm/java-1.5.0-sun/include
148 /usr/lib/jvm/java-6-sun-1.6.0.00/include # can this one be removed according to #8821 ? Alex
149 /usr/lib/jvm/java-6-openjdk/include
150 /usr/local/share/java/include
151 /usr/lib/j2sdk1.4-sun/include
152 /usr/lib/j2sdk1.5-sun/include
153 /opt/sun-jdk-1.5.0.04/include
154 # Debian specific path for default JVM
155 /usr/lib/jvm/default-java/include
158 foreach(JAVA_PROG "${JAVA_RUNTIME}" "${JAVA_COMPILE}" "${JAVA_ARCHIVE}")
159 get_filename_component(jpath "${JAVA_PROG}" PATH)
160 foreach(JAVA_INC_PATH ../include ../java/include ../share/java/include)
161 if(EXISTS ${jpath}/${JAVA_INC_PATH})
162 set(JAVA_AWT_INCLUDE_DIRECTORIES ${JAVA_AWT_INCLUDE_DIRECTORIES} "${jpath}/${JAVA_INC_PATH}")
165 foreach(JAVA_LIB_PATH
166 ../lib ../jre/lib ../jre/lib/i386
167 ../java/lib ../java/jre/lib ../java/jre/lib/i386
168 ../share/java/lib ../share/java/jre/lib ../share/java/jre/lib/i386)
169 if(EXISTS ${jpath}/${JAVA_LIB_PATH})
170 set(JAVA_AWT_LIBRARY_DIRECTORIES ${JAVA_AWT_LIBRARY_DIRECTORIES} "${jpath}/${JAVA_LIB_PATH}")
176 if(EXISTS ~/Library/Frameworks/JavaVM.framework)
177 set(JAVA_HAVE_FRAMEWORK 1)
179 if(EXISTS /Library/Frameworks/JavaVM.framework)
180 set(JAVA_HAVE_FRAMEWORK 1)
182 if(EXISTS /System/Library/Frameworks/JavaVM.framework)
183 set(JAVA_HAVE_FRAMEWORK 1)
186 if(JAVA_HAVE_FRAMEWORK)
187 if(NOT JAVA_AWT_LIBRARY)
188 set (JAVA_AWT_LIBRARY "-framework JavaVM" CACHE FILEPATH "Java Frameworks" FORCE)
191 if(NOT JAVA_JVM_LIBRARY)
192 set (JAVA_JVM_LIBRARY "-framework JavaVM" CACHE FILEPATH "Java Frameworks" FORCE)
195 if(NOT JAVA_AWT_INCLUDE_PATH)
196 if(EXISTS /System/Library/Frameworks/JavaVM.framework/Headers/jawt.h)
197 set (JAVA_AWT_INCLUDE_PATH "/System/Library/Frameworks/JavaVM.framework/Headers" CACHE FILEPATH "jawt.h location" FORCE)
201 # If using "-framework JavaVM", prefer its headers *before* the others in
202 # JAVA_AWT_INCLUDE_DIRECTORIES... (*prepend* to the list here)
204 set(JAVA_AWT_INCLUDE_DIRECTORIES
205 ~/Library/Frameworks/JavaVM.framework/Headers
206 /Library/Frameworks/JavaVM.framework/Headers
207 /System/Library/Frameworks/JavaVM.framework/Headers
208 ${JAVA_AWT_INCLUDE_DIRECTORIES}
212 find_library(JAVA_AWT_LIBRARY jawt
213 PATHS ${JAVA_AWT_LIBRARY_DIRECTORIES}
215 find_library(JAVA_JVM_LIBRARY NAMES jvm JavaVM
216 PATHS ${JAVA_JVM_LIBRARY_DIRECTORIES}
220 # add in the include path
221 find_path(JAVA_INCLUDE_PATH jni.h
222 ${JAVA_AWT_INCLUDE_DIRECTORIES}
225 find_path(JAVA_INCLUDE_PATH2 jni_md.h
227 ${JAVA_INCLUDE_PATH}/win32
228 ${JAVA_INCLUDE_PATH}/linux
229 ${JAVA_INCLUDE_PATH}/freebsd
230 ${JAVA_INCLUDE_PATH}/solaris
231 ${JAVA_INCLUDE_PATH}/hp-ux
232 ${JAVA_INCLUDE_PATH}/alpha
235 find_path(JAVA_AWT_INCLUDE_PATH jawt.h
239 include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
240 FIND_PACKAGE_HANDLE_STANDARD_ARGS(JNI DEFAULT_MSG JAVA_AWT_LIBRARY JAVA_JVM_LIBRARY
241 JAVA_INCLUDE_PATH JAVA_INCLUDE_PATH2 JAVA_AWT_INCLUDE_PATH)
246 JAVA_AWT_INCLUDE_PATH
258 ${JAVA_INCLUDE_PATH2}
259 ${JAVA_AWT_INCLUDE_PATH}