CMakeLists.txt 3.8 KB

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