HadoopJNI.cmake 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #
  2. # Licensed to the Apache Software Foundation (ASF) under one
  3. # or more contributor license agreements. See the NOTICE file
  4. # distributed with this work for additional information
  5. # regarding copyright ownership. The ASF licenses this file
  6. # to you under the Apache License, Version 2.0 (the
  7. # "License"); you may not use this file except in compliance
  8. # with the License. You may obtain a copy of the License at
  9. #
  10. # http://www.apache.org/licenses/LICENSE-2.0
  11. #
  12. # Unless required by applicable law or agreed to in writing, software
  13. # distributed under the License is distributed on an "AS IS" BASIS,
  14. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. # See the License for the specific language governing permissions and
  16. # limitations under the License.
  17. #
  18. #
  19. # Common JNI detection for CMake, shared by all Native components.
  20. #
  21. # Check the JVM_ARCH_DATA_MODEL variable as been set to 32 or 64 by maven.
  22. if(NOT DEFINED JVM_ARCH_DATA_MODEL)
  23. message(FATAL_ERROR "JVM_ARCH_DATA_MODEL is not defined")
  24. elseif(NOT (JVM_ARCH_DATA_MODEL EQUAL 32 OR JVM_ARCH_DATA_MODEL EQUAL 64))
  25. message(FATAL_ERROR "JVM_ARCH_DATA_MODEL is not 32 or 64")
  26. endif()
  27. #
  28. # Linux-specific JNI configuration.
  29. #
  30. if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
  31. # Locate JNI_INCLUDE_DIRS and JNI_LIBRARIES.
  32. # Since we were invoked from Maven, we know that the JAVA_HOME environment
  33. # variable is valid. So we ignore system paths here and just use JAVA_HOME.
  34. file(TO_CMAKE_PATH "$ENV{JAVA_HOME}" _java_home)
  35. if(CMAKE_SYSTEM_PROCESSOR MATCHES "^i.86$")
  36. set(_java_libarch "i386")
  37. elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "amd64")
  38. set(_java_libarch "amd64")
  39. elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^arm")
  40. set(_java_libarch "arm")
  41. elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(powerpc|ppc)64le")
  42. if(EXISTS "${_java_home}/jre/lib/ppc64le")
  43. set(_java_libarch "ppc64le")
  44. else()
  45. set(_java_libarch "ppc64")
  46. endif()
  47. else()
  48. set(_java_libarch ${CMAKE_SYSTEM_PROCESSOR})
  49. endif()
  50. set(_JDK_DIRS "${_java_home}/jre/lib/${_java_libarch}/*"
  51. "${_java_home}/jre/lib/${_java_libarch}"
  52. "${_java_home}/jre/lib/*"
  53. "${_java_home}/jre/lib"
  54. "${_java_home}/lib/*"
  55. "${_java_home}/lib"
  56. "${_java_home}/include/*"
  57. "${_java_home}/include"
  58. "${_java_home}"
  59. )
  60. find_path(JAVA_INCLUDE_PATH
  61. NAMES jni.h
  62. PATHS ${_JDK_DIRS}
  63. NO_DEFAULT_PATH)
  64. #In IBM java, it's jniport.h instead of jni_md.h
  65. find_path(JAVA_INCLUDE_PATH2
  66. NAMES jni_md.h jniport.h
  67. PATHS ${_JDK_DIRS}
  68. NO_DEFAULT_PATH)
  69. set(JNI_INCLUDE_DIRS ${JAVA_INCLUDE_PATH} ${JAVA_INCLUDE_PATH2})
  70. find_library(JAVA_JVM_LIBRARY
  71. NAMES jvm JavaVM
  72. PATHS ${_JDK_DIRS}
  73. NO_DEFAULT_PATH)
  74. set(JNI_LIBRARIES ${JAVA_JVM_LIBRARY})
  75. unset(_java_libarch)
  76. unset(_java_home)
  77. message("JAVA_HOME=${JAVA_HOME}, JAVA_JVM_LIBRARY=${JAVA_JVM_LIBRARY}")
  78. message("JAVA_INCLUDE_PATH=${JAVA_INCLUDE_PATH}, JAVA_INCLUDE_PATH2=${JAVA_INCLUDE_PATH2}")
  79. if(JAVA_JVM_LIBRARY AND JAVA_INCLUDE_PATH AND JAVA_INCLUDE_PATH2)
  80. message("Located all JNI components successfully.")
  81. else()
  82. message(FATAL_ERROR "Failed to find a viable JVM installation under JAVA_HOME.")
  83. endif()
  84. # Use the standard FindJNI module to locate the JNI components.
  85. find_package(JNI REQUIRED)
  86. #
  87. # Otherwise, use the standard FindJNI module to locate the JNI components.
  88. #
  89. else()
  90. find_package(JNI REQUIRED)
  91. endif()