KWSys Nightly Date Stamp
[cmake.git] / Modules / FindJNI.cmake
blobe072f211a6e5522836aff06ae5027a234d67be92
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:
5 #   
6 #  JNI_INCLUDE_DIRS      = the include dirs to use
7 #  JNI_LIBRARIES         = the libraries to use
8 #  JAVA_AWT_LIBRARY      = the path to the jawt library
9 #  JAVA_JVM_LIBRARY      = the path to the jvm library
10 #  JAVA_INCLUDE_PATH     = the include path to jni.h
11 #  JAVA_INCLUDE_PATH2    = the include path to jni_md.h
12 #  JAVA_AWT_INCLUDE_PATH = the include path to jawt.h
15 GET_FILENAME_COMPONENT(java_install_version
16   "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit;CurrentVersion]" NAME)
18 SET(JAVA_AWT_LIBRARY_DIRECTORIES
19   "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.4;JavaHome]/lib"
20   "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.3;JavaHome]/lib"
21   "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\${java_install_version};JavaHome]/lib"
22   $ENV{JAVA_HOME}/jre/lib/alpha
23   $ENV{JAVA_HOME}/jre/lib/amd64
24   $ENV{JAVA_HOME}/jre/lib/arm
25   $ENV{JAVA_HOME}/jre/lib/i386
26   $ENV{JAVA_HOME}/jre/lib/ia64
27   $ENV{JAVA_HOME}/jre/lib/m68k
28   $ENV{JAVA_HOME}/jre/lib/mips
29   $ENV{JAVA_HOME}/jre/lib/mipsel
30   $ENV{JAVA_HOME}/jre/lib/parisc
31   $ENV{JAVA_HOME}/jre/lib/powerpc
32   $ENV{JAVA_HOME}/jre/lib/ppc
33   $ENV{JAVA_HOME}/jre/lib/s390
34   $ENV{JAVA_HOME}/jre/lib/sparc
35   $ENV{JAVA_HOME}/jre/lib/x86_64
36   $ENV{JAVA_HOME}/lib
37   /usr/lib
38   /usr/local/lib
39   /usr/lib/jvm/java/lib
40   /usr/lib/java/jre/lib/i386
41   /usr/local/lib/java/jre/lib/i386
42   /usr/local/share/java/jre/lib/i386
43   /usr/lib/j2sdk1.4-sun/jre/lib/i386
44   /usr/lib/j2sdk1.5-sun/jre/lib/i386
45   /opt/sun-jdk-1.5.0.04/jre/lib/amd64
46   /usr/lib/jvm/java-6-sun/jre/lib/i386
47   /usr/lib/jvm/java-6-sun/jre/lib/amd64
48   /usr/lib/jvm/java-1.5.0-sun/jre/lib/i386
49   /usr/lib/jvm/java-1.5.0-sun/jre/lib/amd64
50   /usr/lib/jvm/java-6-sun-1.6.0.00/jre/lib/amd64       # can this one be removed according to #8821 ? Alex
51   /usr/lib/java/jre/lib/amd64
52   /usr/local/lib/java/jre/lib/amd64
53   /usr/local/share/java/jre/lib/amd64
54   /usr/lib/j2sdk1.4-sun/jre/lib/amd64
55   /usr/lib/j2sdk1.5-sun/jre/lib/amd64
56   /usr/lib/java/jre/lib/ppc
57   /usr/local/lib/java/jre/lib/ppc
58   /usr/local/share/java/jre/lib/ppc
59   /usr/lib/j2sdk1.4-sun/jre/lib/ppc
60   /usr/lib/j2sdk1.5-sun/jre/lib/ppc
61   )
63 SET(JAVA_JVM_LIBRARY_DIRECTORIES)
64 FOREACH(dir ${JAVA_AWT_LIBRARY_DIRECTORIES})
65   SET(JAVA_JVM_LIBRARY_DIRECTORIES
66     ${JAVA_JVM_LIBRARY_DIRECTORIES}
67     "${dir}"
68     "${dir}/client"
69     "${dir}/server"
70     )
71 ENDFOREACH(dir)
74 SET(JAVA_AWT_INCLUDE_DIRECTORIES
75   "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.4;JavaHome]/include"
76   "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.3;JavaHome]/include"
77   "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\${java_install_version};JavaHome]/include"
78   $ENV{JAVA_HOME}/include
79   /usr/include 
80   /usr/local/include
81   /usr/lib/java/include
82   /usr/local/lib/java/include
83   /usr/lib/jvm/java/include
84   /usr/lib/jvm/java-6-sun/include
85   /usr/lib/jvm/java-1.5.0-sun/include
86   /usr/lib/jvm/java-6-sun-1.6.0.00/include       # can this one be removed according to #8821 ? Alex
87   /usr/local/share/java/include
88   /usr/lib/j2sdk1.4-sun/include
89   /usr/lib/j2sdk1.5-sun/include
90   /opt/sun-jdk-1.5.0.04/include
91   )
93 FOREACH(JAVA_PROG "${JAVA_RUNTIME}" "${JAVA_COMPILE}" "${JAVA_ARCHIVE}")
94   GET_FILENAME_COMPONENT(jpath "${JAVA_PROG}" PATH)
95   FOREACH(JAVA_INC_PATH ../include ../java/include ../share/java/include)
96     IF(EXISTS ${jpath}/${JAVA_INC_PATH})
97       SET(JAVA_AWT_INCLUDE_DIRECTORIES ${JAVA_AWT_INCLUDE_DIRECTORIES} "${jpath}/${JAVA_INC_PATH}")
98     ENDIF(EXISTS ${jpath}/${JAVA_INC_PATH})
99   ENDFOREACH(JAVA_INC_PATH)
100   FOREACH(JAVA_LIB_PATH 
101     ../lib ../jre/lib ../jre/lib/i386 
102     ../java/lib ../java/jre/lib ../java/jre/lib/i386 
103     ../share/java/lib ../share/java/jre/lib ../share/java/jre/lib/i386)
104     IF(EXISTS ${jpath}/${JAVA_LIB_PATH})
105       SET(JAVA_AWT_LIBRARY_DIRECTORIES ${JAVA_AWT_LIBRARY_DIRECTORIES} "${jpath}/${JAVA_LIB_PATH}")
106     ENDIF(EXISTS ${jpath}/${JAVA_LIB_PATH})
107   ENDFOREACH(JAVA_LIB_PATH)
108 ENDFOREACH(JAVA_PROG)
110 IF(APPLE)
111   IF(EXISTS ~/Library/Frameworks/JavaVM.framework)
112     SET(JAVA_HAVE_FRAMEWORK 1)
113   ENDIF(EXISTS ~/Library/Frameworks/JavaVM.framework)
114   IF(EXISTS /Library/Frameworks/JavaVM.framework)
115     SET(JAVA_HAVE_FRAMEWORK 1)
116   ENDIF(EXISTS /Library/Frameworks/JavaVM.framework)
117   IF(EXISTS /System/Library/Frameworks/JavaVM.framework)
118     SET(JAVA_HAVE_FRAMEWORK 1)
119   ENDIF(EXISTS /System/Library/Frameworks/JavaVM.framework)
121   IF(JAVA_HAVE_FRAMEWORK)
122     IF(NOT JAVA_AWT_LIBRARY)
123       SET (JAVA_AWT_LIBRARY "-framework JavaVM" CACHE FILEPATH "Java Frameworks" FORCE)
124     ENDIF(NOT JAVA_AWT_LIBRARY)
126     IF(NOT JAVA_JVM_LIBRARY)
127       SET (JAVA_JVM_LIBRARY "-framework JavaVM" CACHE FILEPATH "Java Frameworks" FORCE)
128     ENDIF(NOT JAVA_JVM_LIBRARY)
130     IF(NOT JAVA_AWT_INCLUDE_PATH)
131       IF(EXISTS /System/Library/Frameworks/JavaVM.framework/Headers/jawt.h)
132         SET (JAVA_AWT_INCLUDE_PATH "/System/Library/Frameworks/JavaVM.framework/Headers" CACHE FILEPATH "jawt.h location" FORCE)
133       ENDIF(EXISTS /System/Library/Frameworks/JavaVM.framework/Headers/jawt.h)
134     ENDIF(NOT JAVA_AWT_INCLUDE_PATH)
136     # If using "-framework JavaVM", prefer its headers *before* the others in
137     # JAVA_AWT_INCLUDE_DIRECTORIES... (*prepend* to the list here)
138     #
139     SET(JAVA_AWT_INCLUDE_DIRECTORIES
140       ~/Library/Frameworks/JavaVM.framework/Headers
141       /Library/Frameworks/JavaVM.framework/Headers
142       /System/Library/Frameworks/JavaVM.framework/Headers
143       ${JAVA_AWT_INCLUDE_DIRECTORIES}
144       )
145   ENDIF(JAVA_HAVE_FRAMEWORK)
146 ELSE(APPLE)
147   FIND_LIBRARY(JAVA_AWT_LIBRARY jawt 
148     PATHS ${JAVA_AWT_LIBRARY_DIRECTORIES}
149   )
150   FIND_LIBRARY(JAVA_JVM_LIBRARY NAMES jvm JavaVM
151     PATHS ${JAVA_JVM_LIBRARY_DIRECTORIES}
152   )
153 ENDIF(APPLE)
155 # add in the include path    
156 FIND_PATH(JAVA_INCLUDE_PATH jni.h 
157   ${JAVA_AWT_INCLUDE_DIRECTORIES}
160 FIND_PATH(JAVA_INCLUDE_PATH2 jni_md.h 
161   ${JAVA_AWT_INCLUDE_DIRECTORIES}
162   ${JAVA_INCLUDE_PATH}/win32
163   ${JAVA_INCLUDE_PATH}/linux
164   ${JAVA_INCLUDE_PATH}/freebsd
167 FIND_PATH(JAVA_AWT_INCLUDE_PATH jawt.h
168   ${JAVA_AWT_INCLUDE_DIRECTORIES}
169   ${JAVA_INCLUDE_PATH}
172 MARK_AS_ADVANCED(
173   JAVA_AWT_LIBRARY
174   JAVA_JVM_LIBRARY
175   JAVA_AWT_INCLUDE_PATH
176   JAVA_INCLUDE_PATH
177   JAVA_INCLUDE_PATH2
180 SET(JNI_LIBRARIES
181   ${JAVA_AWT_LIBRARY}
182   ${JAVA_JVM_LIBRARY}
185 SET(JNI_INCLUDE_DIRS
186   ${JAVA_INCLUDE_PATH}
187   ${JAVA_INCLUDE_PATH2}
188   ${JAVA_AWT_INCLUDE_PATH}