CMakeLists.txt 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. # Default to release builds
  20. set(CMAKE_BUILD_TYPE, Release)
  21. # If JVM_ARCH_DATA_MODEL is 32, compile all binaries as 32-bit.
  22. # This variable is set by maven.
  23. if (JVM_ARCH_DATA_MODEL EQUAL 32)
  24. # force 32-bit code generation on amd64/x86_64, ppc64, sparc64
  25. if (CMAKE_COMPILER_IS_GNUCC AND CMAKE_SYSTEM_PROCESSOR MATCHES ".*64")
  26. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32")
  27. set(CMAKE_LD_FLAGS "${CMAKE_LD_FLAGS} -m32")
  28. endif ()
  29. if (CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "amd64")
  30. set(CMAKE_SYSTEM_PROCESSOR "i686")
  31. endif ()
  32. endif (JVM_ARCH_DATA_MODEL EQUAL 32)
  33. # Compile a library with both shared and static variants
  34. function(add_dual_library LIBNAME)
  35. add_library(${LIBNAME} SHARED ${ARGN})
  36. add_library(${LIBNAME}_static STATIC ${ARGN})
  37. set_target_properties(${LIBNAME}_static PROPERTIES OUTPUT_NAME ${LIBNAME})
  38. endfunction(add_dual_library)
  39. # Link both a static and a dynamic target against some libraries
  40. function(target_link_dual_libraries LIBNAME)
  41. target_link_libraries(${LIBNAME} ${ARGN})
  42. target_link_libraries(${LIBNAME}_static ${ARGN})
  43. endfunction(target_link_dual_libraries)
  44. function(output_directory TGT DIR)
  45. SET_TARGET_PROPERTIES(${TGT} PROPERTIES
  46. RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${DIR}")
  47. SET_TARGET_PROPERTIES(${TGT} PROPERTIES
  48. ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${DIR}")
  49. SET_TARGET_PROPERTIES(${TGT} PROPERTIES
  50. LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${DIR}")
  51. endfunction(output_directory TGT DIR)
  52. function(dual_output_directory TGT DIR)
  53. output_directory(${TGT} "${DIR}")
  54. output_directory(${TGT}_static "${DIR}")
  55. endfunction(dual_output_directory TGT DIR)
  56. # Flatten a list into a string.
  57. function(FLATTEN_LIST INPUT SEPARATOR OUTPUT)
  58. string (REPLACE ";" "${SEPARATOR}" _TMPS "${INPUT}")
  59. set (${OUTPUT} "${_TMPS}" PARENT_SCOPE)
  60. endfunction()
  61. find_package(JNI REQUIRED)
  62. if (NOT GENERATED_JAVAH)
  63. # Must identify where the generated headers have been placed
  64. MESSAGE(FATAL_ERROR "You must set the CMake variable GENERATED_JAVAH")
  65. endif (NOT GENERATED_JAVAH)
  66. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -Wall -O2 -D_GNU_SOURCE")
  67. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_REENTRANT -D_FILE_OFFSET_BITS=64")
  68. include_directories(
  69. ${GENERATED_JAVAH}
  70. ${CMAKE_CURRENT_SOURCE_DIR}
  71. ${CMAKE_BINARY_DIR}
  72. ${JNI_INCLUDE_DIRS}
  73. main/native/
  74. )
  75. set(_FUSE_DFS_VERSION 0.1.0)
  76. CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/config.h.cmake ${CMAKE_BINARY_DIR}/config.h)
  77. add_dual_library(hdfs
  78. main/native/hdfs.c
  79. main/native/hdfsJniHelper.c
  80. )
  81. target_link_dual_libraries(hdfs
  82. ${JAVA_JVM_LIBRARY}
  83. )
  84. dual_output_directory(hdfs target/usr/local/lib)
  85. set(LIBHDFS_VERSION "0.0.0")
  86. set_target_properties(hdfs PROPERTIES
  87. SOVERSION ${LIBHDFS_VERSION})
  88. add_executable(hdfs_test
  89. main/native/hdfs_test.c
  90. )
  91. target_link_libraries(hdfs_test
  92. hdfs
  93. ${JAVA_JVM_LIBRARY}
  94. )
  95. output_directory(hdfs_test target/usr/local/bin)
  96. add_executable(hdfs_read
  97. main/native/hdfs_read.c
  98. )
  99. target_link_libraries(hdfs_read
  100. hdfs
  101. ${JAVA_JVM_LIBRARY}
  102. )
  103. output_directory(hdfs_read target/usr/local/bin)
  104. add_executable(hdfs_write
  105. main/native/hdfs_write.c
  106. )
  107. target_link_libraries(hdfs_write
  108. hdfs
  109. ${JAVA_JVM_LIBRARY}
  110. )
  111. output_directory(hdfs_write target/usr/local/bin)
  112. add_subdirectory(contrib/fuse-dfs/src)