FindJNI.cmake will not respect JAVA_HOME when setting JAVA_INCLUDE_PATH if jni.h exists in CMAKE_SYSTEM_PREFIX_PATH
This issue was created automatically from an original Mantis Issue. Further discussion may take place here.
I have multiple JDKs installed on my machine. Also, I have gcc and its java support installed. So, to instruct CMake which java to use, I set the environment variable JAVA_HOME=/opt/java6
before running cmake. CMake set most of the java-related variables correctly except JAVA_INCLUDE_PATH
which it set to /usr/local/include
.
- touch
/usr/local/include/jni.h
# or install libgcj using the SMCgcc package from sunfreeware - install java6 in
/opt/java6
JAVA_HOME=/opt/java6
export JAVA_HOME
- construct a
CMakeLists.txt
file which uses cmake /path/to/sources
grep JAVA_INCLUDE_PATH: CMakeCache.txt
-
- actual>
JAVA_INCLUDE_PATH:PATH=/usr/local/include
- actual>
-
- expected>
JAVA_INCLUDE_PATH:PATH=/opt/java6/include
- expected>
- We didn't notice it until we went to make something that builds against
jni.h
-
"/usr/local/include/jni.h", line 81: Error: #error jni.h not ported to this platform.
- The above error happens because the c++ compiler finds
/usr/local/include/jni.h
instead of/opt/java6/include/jni.h
A minimalist fix might be to just add HINTS
right after find_path(JAVA_INCLUDE_PATH jni.h)
in FindJNI.cmake
. That is, add HINTS
right before ${JAVA_AWT_INCLUDE_DIRECTORIES}
so these directories are searched before each path in CMAKE_SYSTEM_PREFIX_PATH
.
However, CMake users such as myself would love to see FindJNI.cmake test the variables to make sure that all the JAVA and JNI-related variables point to the same JVM (like how CMake smartly checks to make sure the C compiler works).
Thanks,
-Carl