JNIFlags.cmake 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. cmake_minimum_required(VERSION 2.6 FATAL_ERROR)
  19. # If JVM_ARCH_DATA_MODEL is 32, compile all binaries as 32-bit.
  20. # This variable is set by maven.
  21. if (JVM_ARCH_DATA_MODEL EQUAL 32)
  22. # Force 32-bit code generation on amd64/x86_64, ppc64, sparc64
  23. if (CMAKE_COMPILER_IS_GNUCC AND CMAKE_SYSTEM_PROCESSOR MATCHES ".*64")
  24. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32")
  25. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32")
  26. set(CMAKE_LD_FLAGS "${CMAKE_LD_FLAGS} -m32")
  27. endif ()
  28. if (CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "amd64")
  29. # Set CMAKE_SYSTEM_PROCESSOR to ensure that find_package(JNI) will use
  30. # the 32-bit version of libjvm.so.
  31. set(CMAKE_SYSTEM_PROCESSOR "i686")
  32. endif ()
  33. endif (JVM_ARCH_DATA_MODEL EQUAL 32)
  34. # Determine float ABI of JVM on ARM Linux
  35. if (CMAKE_SYSTEM_PROCESSOR MATCHES "^arm" AND CMAKE_SYSTEM_NAME STREQUAL "Linux")
  36. find_program(READELF readelf)
  37. if (READELF MATCHES "NOTFOUND")
  38. message(WARNING "readelf not found; JVM float ABI detection disabled")
  39. else (READELF MATCHES "NOTFOUND")
  40. execute_process(
  41. COMMAND ${READELF} -A ${JAVA_JVM_LIBRARY}
  42. OUTPUT_VARIABLE JVM_ELF_ARCH
  43. ERROR_QUIET)
  44. if (NOT JVM_ELF_ARCH MATCHES "Tag_ABI_VFP_args: VFP registers")
  45. message("Soft-float JVM detected")
  46. # Test compilation with -mfloat-abi=softfp using an arbitrary libc function
  47. # (typically fails with "fatal error: bits/predefs.h: No such file or directory"
  48. # if soft-float dev libraries are not installed)
  49. include(CMakePushCheckState)
  50. cmake_push_check_state()
  51. set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -mfloat-abi=softfp")
  52. include(CheckSymbolExists)
  53. check_symbol_exists(exit stdlib.h SOFTFP_AVAILABLE)
  54. if (NOT SOFTFP_AVAILABLE)
  55. message(FATAL_ERROR "Soft-float dev libraries required (e.g. 'apt-get install libc6-dev-armel' on Debian/Ubuntu)")
  56. endif (NOT SOFTFP_AVAILABLE)
  57. cmake_pop_check_state()
  58. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfloat-abi=softfp")
  59. endif ()
  60. endif (READELF MATCHES "NOTFOUND")
  61. endif (CMAKE_SYSTEM_PROCESSOR MATCHES "^arm" AND CMAKE_SYSTEM_NAME STREQUAL "Linux")
  62. find_package(JNI REQUIRED)