ENH: fix bug where sharedforward would not work if there was a space in the path...
[cmake.git] / Modules / FindJNI.cmake
blobbed0e1d0d21266592dbffe71756e999338dab752
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/i386
23   $ENV{JAVA_HOME}/jre/lib/amd64
24   $ENV{JAVA_HOME}/jre/lib/ppc
25   /usr/lib
26   /usr/local/lib
27   /usr/lib/jvm/java/lib
28   /usr/lib/java/jre/lib/i386
29   /usr/local/lib/java/jre/lib/i386
30   /usr/local/share/java/jre/lib/i386
31   /usr/lib/j2sdk1.4-sun/jre/lib/i386
32   /usr/lib/j2sdk1.5-sun/jre/lib/i386
33   /opt/sun-jdk-1.5.0.04/jre/lib/amd64
34   /usr/lib/jvm/java-6-sun-1.6.0.00/jre/lib/amd64
35   /usr/lib/java/jre/lib/amd64
36   /usr/local/lib/java/jre/lib/amd64
37   /usr/local/share/java/jre/lib/amd64
38   /usr/lib/j2sdk1.4-sun/jre/lib/amd64
39   /usr/lib/j2sdk1.5-sun/jre/lib/amd64
40   /usr/lib/java/jre/lib/ppc
41   /usr/local/lib/java/jre/lib/ppc
42   /usr/local/share/java/jre/lib/ppc
43   /usr/lib/j2sdk1.4-sun/jre/lib/ppc
44   /usr/lib/j2sdk1.5-sun/jre/lib/ppc
45   )
47 SET(JAVA_JVM_LIBRARY_DIRECTORIES)
48 FOREACH(dir ${JAVA_AWT_LIBRARY_DIRECTORIES})
49   SET(JAVA_JVM_LIBRARY_DIRECTORIES
50     ${JAVA_JVM_LIBRARY_DIRECTORIES}
51     "${dir}"
52     "${dir}/client"
53     "${dir}/server"
54     )
55 ENDFOREACH(dir)
58 SET(JAVA_AWT_INCLUDE_DIRECTORIES
59   "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.4;JavaHome]/include"
60   "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.3;JavaHome]/include"
61   "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\${java_install_version};JavaHome]/include"
62   $ENV{JAVA_HOME}/include
63   /usr/include 
64   /usr/local/include
65   /usr/lib/java/include
66   /usr/local/lib/java/include
67   /usr/lib/jvm/java/include
68   /usr/lib/jvm/java-6-sun-1.6.0.00/include
69   /usr/local/share/java/include
70   /usr/lib/j2sdk1.4-sun/include
71   /usr/lib/j2sdk1.5-sun/include
72   /opt/sun-jdk-1.5.0.04/include
73   )
75 FOREACH(JAVA_PROG "${JAVA_RUNTIME}" "${JAVA_COMPILE}" "${JAVA_ARCHIVE}")
76   GET_FILENAME_COMPONENT(jpath "${JAVA_PROG}" PATH)
77   FOREACH(JAVA_INC_PATH ../include ../java/include ../share/java/include)
78     IF(EXISTS ${jpath}/${JAVA_INC_PATH})
79       SET(JAVA_AWT_INCLUDE_DIRECTORIES ${JAVA_AWT_INCLUDE_DIRECTORIES} "${jpath}/${JAVA_INC_PATH}")
80     ENDIF(EXISTS ${jpath}/${JAVA_INC_PATH})
81   ENDFOREACH(JAVA_INC_PATH)
82   FOREACH(JAVA_LIB_PATH 
83     ../lib ../jre/lib ../jre/lib/i386 
84     ../java/lib ../java/jre/lib ../java/jre/lib/i386 
85     ../share/java/lib ../share/java/jre/lib ../share/java/jre/lib/i386)
86     IF(EXISTS ${jpath}/${JAVA_LIB_PATH})
87       SET(JAVA_AWT_LIBRARY_DIRECTORIES ${JAVA_AWT_LIBRARY_DIRECTORIES} "${jpath}/${JAVA_LIB_PATH}")
88     ENDIF(EXISTS ${jpath}/${JAVA_LIB_PATH})
89   ENDFOREACH(JAVA_LIB_PATH)
90 ENDFOREACH(JAVA_PROG)
92 IF(APPLE)
93   IF(EXISTS ~/Library/Frameworks/JavaVM.framework)
94     SET(JAVA_HAVE_FRAMEWORK 1)
95   ENDIF(EXISTS ~/Library/Frameworks/JavaVM.framework)
96   IF(EXISTS /Library/Frameworks/JavaVM.framework)
97     SET(JAVA_HAVE_FRAMEWORK 1)
98   ENDIF(EXISTS /Library/Frameworks/JavaVM.framework)
99   IF(EXISTS /System/Library/Frameworks/JavaVM.framework)
100     SET(JAVA_HAVE_FRAMEWORK 1)
101   ENDIF(EXISTS /System/Library/Frameworks/JavaVM.framework)
103   IF(JAVA_HAVE_FRAMEWORK)
104     IF(NOT JAVA_AWT_LIBRARY)
105       SET (JAVA_AWT_LIBRARY "-framework JavaVM" CACHE FILEPATH "Java Frameworks" FORCE)
106     ENDIF(NOT JAVA_AWT_LIBRARY)
108     IF(NOT JAVA_JVM_LIBRARY)
109       SET (JAVA_JVM_LIBRARY "-framework JavaVM" CACHE FILEPATH "Java Frameworks" FORCE)
110     ENDIF(NOT JAVA_JVM_LIBRARY)
112     IF(NOT JAVA_AWT_INCLUDE_PATH)
113       IF(EXISTS /System/Library/Frameworks/JavaVM.framework/Headers/jawt.h)
114         SET (JAVA_AWT_INCLUDE_PATH "/System/Library/Frameworks/JavaVM.framework/Headers" CACHE FILEPATH "jawt.h location" FORCE)
115       ENDIF(EXISTS /System/Library/Frameworks/JavaVM.framework/Headers/jawt.h)
116     ENDIF(NOT JAVA_AWT_INCLUDE_PATH)
118     # If using "-framework JavaVM", prefer its headers *before* the others in
119     # JAVA_AWT_INCLUDE_DIRECTORIES... (*prepend* to the list here)
120     #
121     SET(JAVA_AWT_INCLUDE_DIRECTORIES
122       ~/Library/Frameworks/JavaVM.framework/Headers
123       /Library/Frameworks/JavaVM.framework/Headers
124       /System/Library/Frameworks/JavaVM.framework/Headers
125       ${JAVA_AWT_INCLUDE_DIRECTORIES}
126       )
127   ENDIF(JAVA_HAVE_FRAMEWORK)
128 ELSE(APPLE)
129   FIND_LIBRARY(JAVA_AWT_LIBRARY jawt 
130     PATHS ${JAVA_AWT_LIBRARY_DIRECTORIES}
131   )
132   FIND_LIBRARY(JAVA_JVM_LIBRARY NAMES jvm JavaVM
133     PATHS ${JAVA_JVM_LIBRARY_DIRECTORIES}
134   )
135 ENDIF(APPLE)
137 # add in the include path    
138 FIND_PATH(JAVA_INCLUDE_PATH jni.h 
139   ${JAVA_AWT_INCLUDE_DIRECTORIES}
142 FIND_PATH(JAVA_INCLUDE_PATH2 jni_md.h 
143   ${JAVA_AWT_INCLUDE_DIRECTORIES}
144   ${JAVA_INCLUDE_PATH}/win32
145   ${JAVA_INCLUDE_PATH}/linux
146   ${JAVA_INCLUDE_PATH}/freebsd
149 FIND_PATH(JAVA_AWT_INCLUDE_PATH jawt.h
150   ${JAVA_AWT_INCLUDE_DIRECTORIES}
151   ${JAVA_INCLUDE_PATH}
154 MARK_AS_ADVANCED(
155   JAVA_AWT_LIBRARY
156   JAVA_JVM_LIBRARY
157   JAVA_AWT_INCLUDE_PATH
158   JAVA_INCLUDE_PATH
159   JAVA_INCLUDE_PATH2
162 SET(JNI_LIBRARIES
163   ${JAVA_AWT_LIBRARY}
164   ${JAVA_JVM_LIBRARY}
167 SET(JNI_INCLUDE_DIRS
168   ${JAVA_INCLUDE_PATH}
169   ${JAVA_INCLUDE_PATH2}
170   ${JAVA_AWT_INCLUDE_PATH}