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.3;JavaHome]/lib"
93 "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\${java_install_version};JavaHome]/lib"
96 file(TO_CMAKE_PATH "$ENV{JAVA_HOME}" _JAVA_HOME)
98 JAVA_APPEND_LIBRARY_DIRECTORIES(JAVA_AWT_LIBRARY_DIRECTORIES
99 ${_JAVA_HOME}/jre/lib/{libarch}
100 ${_JAVA_HOME}/jre/lib
101 ${_JAVA_HOME}/jre/bin
102 ${_JAVA_HOME}/jre/bin/classic
107 /usr/lib/jvm/java/lib
108 /usr/lib/java/jre/lib/{libarch}
109 /usr/lib/jvm/jre/lib/{libarch}
110 /usr/local/lib/java/jre/lib/{libarch}
111 /usr/local/share/java/jre/lib/{libarch}
112 /usr/lib/j2sdk1.4-sun/jre/lib/{libarch}
113 /usr/lib/j2sdk1.5-sun/jre/lib/{libarch}
114 /opt/sun-jdk-1.5.0.04/jre/lib/{libarch}
115 /usr/lib/jvm/java-6-sun/jre/lib/{libarch}
116 /usr/lib/jvm/java-1.5.0-sun/jre/lib/{libarch}
117 /usr/lib/jvm/java-6-sun-1.6.0.00/jre/lib/{libarch} # can this one be removed according to #8821 ? Alex
118 /usr/lib/jvm/java-6-openjdk/jre/lib/{libarch}
119 /usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0/jre/lib/{libarch} # fedora
120 # Debian specific paths for default JVM
121 /usr/lib/jvm/default-java/jre/lib/{libarch}
122 /usr/lib/jvm/default-java/jre/lib
123 /usr/lib/jvm/default-java/lib
124 # OpenBSD specific paths for default JVM
125 /usr/local/jdk-1.7.0/jre/lib/{libarch}
126 /usr/local/jre-1.7.0/lib/{libarch}
127 /usr/local/jdk-1.6.0/jre/lib/{libarch}
128 /usr/local/jre-1.6.0/lib/{libarch}
131 set(JAVA_JVM_LIBRARY_DIRECTORIES)
132 foreach(dir ${JAVA_AWT_LIBRARY_DIRECTORIES})
133 set(JAVA_JVM_LIBRARY_DIRECTORIES
134 ${JAVA_JVM_LIBRARY_DIRECTORIES}
142 set(JAVA_AWT_INCLUDE_DIRECTORIES
143 #"[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.4;JavaHome]/include"
144 "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.3;JavaHome]/include"
145 "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\${java_install_version};JavaHome]/include"
146 ${_JAVA_HOME}/include
149 /usr/lib/java/include
150 /usr/local/lib/java/include
151 /usr/lib/jvm/java/include
152 /usr/lib/jvm/java-6-sun/include
153 /usr/lib/jvm/java-1.5.0-sun/include
154 /usr/lib/jvm/java-6-sun-1.6.0.00/include # can this one be removed according to #8821 ? Alex
155 /usr/lib/jvm/java-6-openjdk/include
156 /usr/local/share/java/include
157 /usr/lib/j2sdk1.4-sun/include
158 /usr/lib/j2sdk1.5-sun/include
159 /opt/sun-jdk-1.5.0.04/include
160 # Debian specific path for default JVM
161 /usr/lib/jvm/default-java/include
162 # OpenBSD specific path for default JVM
163 /usr/local/jdk-1.7.0/include
164 /usr/local/jdk-1.6.0/include
167 foreach(JAVA_PROG "${JAVA_RUNTIME}" "${JAVA_COMPILE}" "${JAVA_ARCHIVE}")
168 get_filename_component(jpath "${JAVA_PROG}" PATH)
169 foreach(JAVA_INC_PATH ../include ../java/include ../share/java/include)
170 if(EXISTS ${jpath}/${JAVA_INC_PATH})
171 set(JAVA_AWT_INCLUDE_DIRECTORIES ${JAVA_AWT_INCLUDE_DIRECTORIES} "${jpath}/${JAVA_INC_PATH}")
174 foreach(JAVA_LIB_PATH
175 ../lib ../jre/lib ../jre/lib/i386
176 ../java/lib ../java/jre/lib ../java/jre/lib/i386
177 ../share/java/lib ../share/java/jre/lib ../share/java/jre/lib/i386)
178 if(EXISTS ${jpath}/${JAVA_LIB_PATH})
179 set(JAVA_AWT_LIBRARY_DIRECTORIES ${JAVA_AWT_LIBRARY_DIRECTORIES} "${jpath}/${JAVA_LIB_PATH}")
185 if(EXISTS ~/Library/Frameworks/JavaVM.framework)
186 set(JAVA_HAVE_FRAMEWORK 1)
188 if(EXISTS /Library/Frameworks/JavaVM.framework)
189 set(JAVA_HAVE_FRAMEWORK 1)
191 if(EXISTS /System/Library/Frameworks/JavaVM.framework)
192 set(JAVA_HAVE_FRAMEWORK 1)
195 if(JAVA_HAVE_FRAMEWORK)
196 if(NOT JAVA_AWT_LIBRARY)
197 set (JAVA_AWT_LIBRARY "-framework JavaVM" CACHE FILEPATH "Java Frameworks" FORCE)
200 if(NOT JAVA_JVM_LIBRARY)
201 set (JAVA_JVM_LIBRARY "-framework JavaVM" CACHE FILEPATH "Java Frameworks" FORCE)
204 if(NOT JAVA_AWT_INCLUDE_PATH)
205 if(EXISTS /System/Library/Frameworks/JavaVM.framework/Headers/jawt.h)
206 set (JAVA_AWT_INCLUDE_PATH "/System/Library/Frameworks/JavaVM.framework/Headers" CACHE FILEPATH "jawt.h location" FORCE)
210 # If using "-framework JavaVM", prefer its headers *before* the others in
211 # JAVA_AWT_INCLUDE_DIRECTORIES... (*prepend* to the list here)
213 set(JAVA_AWT_INCLUDE_DIRECTORIES
214 ~/Library/Frameworks/JavaVM.framework/Headers
215 /Library/Frameworks/JavaVM.framework/Headers
216 /System/Library/Frameworks/JavaVM.framework/Headers
217 ${JAVA_AWT_INCLUDE_DIRECTORIES}
221 find_library(JAVA_AWT_LIBRARY jawt
222 PATHS ${JAVA_AWT_LIBRARY_DIRECTORIES}
224 find_library(JAVA_JVM_LIBRARY NAMES jvm JavaVM
225 PATHS ${JAVA_JVM_LIBRARY_DIRECTORIES}
229 # add in the include path
230 find_path(JAVA_INCLUDE_PATH jni.h
231 ${JAVA_AWT_INCLUDE_DIRECTORIES}
234 find_path(JAVA_INCLUDE_PATH2 jni_md.h
236 ${JAVA_INCLUDE_PATH}/win32
237 ${JAVA_INCLUDE_PATH}/linux
238 ${JAVA_INCLUDE_PATH}/freebsd
239 ${JAVA_INCLUDE_PATH}/openbsd
240 ${JAVA_INCLUDE_PATH}/solaris
241 ${JAVA_INCLUDE_PATH}/hp-ux
242 ${JAVA_INCLUDE_PATH}/alpha
245 find_path(JAVA_AWT_INCLUDE_PATH jawt.h
249 include(FindPackageHandleStandardArgs)
250 FIND_PACKAGE_HANDLE_STANDARD_ARGS(JNI DEFAULT_MSG JAVA_AWT_LIBRARY JAVA_JVM_LIBRARY
251 JAVA_INCLUDE_PATH JAVA_INCLUDE_PATH2 JAVA_AWT_INCLUDE_PATH)
256 JAVA_AWT_INCLUDE_PATH
268 ${JAVA_INCLUDE_PATH2}
269 ${JAVA_AWT_INCLUDE_PATH}