CMakeLists.txt 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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. include(../../../hadoop-common-project/hadoop-common/src/JNIFlags.cmake NO_POLICY_SCOPE)
  22. # Compile a library with both shared and static variants
  23. function(add_dual_library LIBNAME)
  24. add_library(${LIBNAME} SHARED ${ARGN})
  25. add_library(${LIBNAME}_static STATIC ${ARGN})
  26. set_target_properties(${LIBNAME}_static PROPERTIES OUTPUT_NAME ${LIBNAME})
  27. endfunction(add_dual_library)
  28. # Link both a static and a dynamic target against some libraries
  29. function(target_link_dual_libraries LIBNAME)
  30. target_link_libraries(${LIBNAME} ${ARGN})
  31. target_link_libraries(${LIBNAME}_static ${ARGN})
  32. endfunction(target_link_dual_libraries)
  33. function(output_directory TGT DIR)
  34. SET_TARGET_PROPERTIES(${TGT} PROPERTIES
  35. RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${DIR}")
  36. SET_TARGET_PROPERTIES(${TGT} PROPERTIES
  37. ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${DIR}")
  38. SET_TARGET_PROPERTIES(${TGT} PROPERTIES
  39. LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${DIR}")
  40. endfunction(output_directory TGT DIR)
  41. function(dual_output_directory TGT DIR)
  42. output_directory(${TGT} "${DIR}")
  43. output_directory(${TGT}_static "${DIR}")
  44. endfunction(dual_output_directory TGT DIR)
  45. # Flatten a list into a string.
  46. function(FLATTEN_LIST INPUT SEPARATOR OUTPUT)
  47. string (REPLACE ";" "${SEPARATOR}" _TMPS "${INPUT}")
  48. set (${OUTPUT} "${_TMPS}" PARENT_SCOPE)
  49. endfunction()
  50. # Check to see if our compiler and linker support the __thread attribute.
  51. # On Linux and some other operating systems, this is a more efficient
  52. # alternative to POSIX thread local storage.
  53. INCLUDE(CheckCSourceCompiles)
  54. CHECK_C_SOURCE_COMPILES("int main(void) { static __thread int i = 0; return 0; }" HAVE_BETTER_TLS)
  55. # Check to see if we have Intel SSE intrinsics.
  56. CHECK_C_SOURCE_COMPILES("#include <emmintrin.h>\nint main(void) { __m128d sum0 = _mm_set_pd(0.0,0.0); return 0; }" HAVE_INTEL_SSE_INTRINSICS)
  57. # Check if we need to link dl library to get dlopen.
  58. # dlopen on Linux is in separate library but on FreeBSD its in libc
  59. INCLUDE(CheckLibraryExists)
  60. CHECK_LIBRARY_EXISTS(dl dlopen "" NEED_LINK_DL)
  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")
  67. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_REENTRANT -D_GNU_SOURCE")
  68. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64")
  69. include_directories(
  70. ${GENERATED_JAVAH}
  71. ${CMAKE_CURRENT_SOURCE_DIR}
  72. ${CMAKE_BINARY_DIR}
  73. ${JNI_INCLUDE_DIRS}
  74. main/native
  75. main/native/libhdfs
  76. )
  77. set(_FUSE_DFS_VERSION 0.1.0)
  78. CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/config.h.cmake ${CMAKE_BINARY_DIR}/config.h)
  79. add_dual_library(hdfs
  80. main/native/libhdfs/exception.c
  81. main/native/libhdfs/jni_helper.c
  82. main/native/libhdfs/hdfs.c
  83. )
  84. if (NEED_LINK_DL)
  85. set(LIB_DL dl)
  86. endif(NEED_LINK_DL)
  87. target_link_dual_libraries(hdfs
  88. ${JAVA_JVM_LIBRARY}
  89. ${LIB_DL}
  90. pthread
  91. )
  92. dual_output_directory(hdfs target/usr/local/lib)
  93. set(LIBHDFS_VERSION "0.0.0")
  94. set_target_properties(hdfs PROPERTIES
  95. SOVERSION ${LIBHDFS_VERSION})
  96. add_library(posix_util
  97. main/native/util/posix_util.c
  98. )
  99. add_executable(test_libhdfs_ops
  100. main/native/libhdfs/test/test_libhdfs_ops.c
  101. )
  102. target_link_libraries(test_libhdfs_ops
  103. hdfs
  104. ${JAVA_JVM_LIBRARY}
  105. )
  106. add_executable(test_libhdfs_read
  107. main/native/libhdfs/test/test_libhdfs_read.c
  108. )
  109. target_link_libraries(test_libhdfs_read
  110. hdfs
  111. ${JAVA_JVM_LIBRARY}
  112. )
  113. add_executable(test_libhdfs_write
  114. main/native/libhdfs/test/test_libhdfs_write.c
  115. )
  116. target_link_libraries(test_libhdfs_write
  117. hdfs
  118. ${JAVA_JVM_LIBRARY}
  119. )
  120. add_library(native_mini_dfs
  121. main/native/libhdfs/native_mini_dfs.c
  122. )
  123. target_link_libraries(native_mini_dfs
  124. hdfs
  125. )
  126. add_executable(test_native_mini_dfs
  127. main/native/libhdfs/test_native_mini_dfs.c
  128. )
  129. target_link_libraries(test_native_mini_dfs
  130. native_mini_dfs
  131. )
  132. add_executable(test_libhdfs_threaded
  133. main/native/libhdfs/expect.c
  134. main/native/libhdfs/test_libhdfs_threaded.c
  135. )
  136. target_link_libraries(test_libhdfs_threaded
  137. hdfs
  138. native_mini_dfs
  139. pthread
  140. )
  141. add_executable(test_libhdfs_zerocopy
  142. main/native/libhdfs/expect.c
  143. main/native/libhdfs/test/test_libhdfs_zerocopy.c
  144. )
  145. target_link_libraries(test_libhdfs_zerocopy
  146. hdfs
  147. native_mini_dfs
  148. pthread
  149. )
  150. add_executable(test_libhdfs_vecsum
  151. main/native/libhdfs/test/vecsum.c
  152. )
  153. target_link_libraries(test_libhdfs_vecsum
  154. hdfs
  155. pthread
  156. rt
  157. )
  158. IF(REQUIRE_LIBWEBHDFS)
  159. add_subdirectory(contrib/libwebhdfs)
  160. ENDIF(REQUIRE_LIBWEBHDFS)
  161. add_subdirectory(main/native/fuse-dfs)