CMakeLists.txt 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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. # Linux builds traditionally ship a libhdfs.a (static linking) and libhdfs.so
  27. # (dynamic linking). On Windows, we cannot use the same base name for both
  28. # static and dynamic, because Windows does not use distinct file extensions
  29. # for a statically linked library vs. a DLL import library. Both use the
  30. # .lib extension. On Windows, we'll build the static library as
  31. # hdfs_static.lib.
  32. if (NOT WIN32)
  33. set_target_properties(${LIBNAME}_static PROPERTIES OUTPUT_NAME ${LIBNAME})
  34. endif (NOT WIN32)
  35. endfunction(add_dual_library)
  36. # Link both a static and a dynamic target against some libraries
  37. function(target_link_dual_libraries LIBNAME)
  38. target_link_libraries(${LIBNAME} ${ARGN})
  39. target_link_libraries(${LIBNAME}_static ${ARGN})
  40. endfunction(target_link_dual_libraries)
  41. function(output_directory TGT DIR)
  42. SET_TARGET_PROPERTIES(${TGT} PROPERTIES
  43. RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${DIR}")
  44. SET_TARGET_PROPERTIES(${TGT} PROPERTIES
  45. ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${DIR}")
  46. SET_TARGET_PROPERTIES(${TGT} PROPERTIES
  47. LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${DIR}")
  48. endfunction(output_directory TGT DIR)
  49. function(dual_output_directory TGT DIR)
  50. output_directory(${TGT} "${DIR}")
  51. output_directory(${TGT}_static "${DIR}")
  52. endfunction(dual_output_directory TGT DIR)
  53. # Flatten a list into a string.
  54. function(FLATTEN_LIST INPUT SEPARATOR OUTPUT)
  55. string (REPLACE ";" "${SEPARATOR}" _TMPS "${INPUT}")
  56. set (${OUTPUT} "${_TMPS}" PARENT_SCOPE)
  57. endfunction()
  58. # Check to see if our compiler and linker support the __thread attribute.
  59. # On Linux and some other operating systems, this is a more efficient
  60. # alternative to POSIX thread local storage.
  61. INCLUDE(CheckCSourceCompiles)
  62. CHECK_C_SOURCE_COMPILES("int main(void) { static __thread int i = 0; return 0; }" HAVE_BETTER_TLS)
  63. # Check to see if we have Intel SSE intrinsics.
  64. 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)
  65. # Check if we need to link dl library to get dlopen.
  66. # dlopen on Linux is in separate library but on FreeBSD its in libc
  67. INCLUDE(CheckLibraryExists)
  68. CHECK_LIBRARY_EXISTS(dl dlopen "" NEED_LINK_DL)
  69. find_package(JNI REQUIRED)
  70. if (NOT GENERATED_JAVAH)
  71. # Must identify where the generated headers have been placed
  72. MESSAGE(FATAL_ERROR "You must set the CMake variable GENERATED_JAVAH")
  73. endif (NOT GENERATED_JAVAH)
  74. if (WIN32)
  75. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /O2")
  76. # Set warning level 4.
  77. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4")
  78. # Skip "unreferenced formal parameter".
  79. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4100")
  80. # Skip "conditional expression is constant".
  81. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4127")
  82. # Skip deprecated POSIX function warnings.
  83. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_CRT_NONSTDC_NO_DEPRECATE")
  84. # Skip CRT non-secure function warnings. If we can convert usage of
  85. # strerror, getenv and ctime to their secure CRT equivalents, then we can
  86. # re-enable the CRT non-secure function warnings.
  87. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_CRT_SECURE_NO_WARNINGS")
  88. # Omit unneeded headers.
  89. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWIN32_LEAN_AND_MEAN")
  90. set(OS_DIR main/native/libhdfs/os/windows)
  91. set(OUT_DIR target/bin)
  92. else (WIN32)
  93. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -Wall -O2")
  94. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_REENTRANT -D_GNU_SOURCE")
  95. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64")
  96. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden")
  97. set(OS_DIR main/native/libhdfs/os/posix)
  98. set(OS_LINK_LIBRARIES pthread)
  99. set(OUT_DIR target/usr/local/lib)
  100. endif (WIN32)
  101. add_definitions(-DLIBHDFS_DLL_EXPORT)
  102. include_directories(
  103. ${GENERATED_JAVAH}
  104. ${CMAKE_CURRENT_SOURCE_DIR}
  105. ${CMAKE_BINARY_DIR}
  106. ${JNI_INCLUDE_DIRS}
  107. main/native
  108. main/native/libhdfs
  109. ${OS_DIR}
  110. )
  111. set(_FUSE_DFS_VERSION 0.1.0)
  112. CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/config.h.cmake ${CMAKE_BINARY_DIR}/config.h)
  113. add_dual_library(hdfs
  114. main/native/libhdfs/exception.c
  115. main/native/libhdfs/jni_helper.c
  116. main/native/libhdfs/hdfs.c
  117. main/native/libhdfs/common/htable.c
  118. ${OS_DIR}/mutexes.c
  119. ${OS_DIR}/thread_local_storage.c
  120. )
  121. if (NEED_LINK_DL)
  122. set(LIB_DL dl)
  123. endif(NEED_LINK_DL)
  124. target_link_dual_libraries(hdfs
  125. ${JAVA_JVM_LIBRARY}
  126. ${LIB_DL}
  127. ${OS_LINK_LIBRARIES}
  128. )
  129. dual_output_directory(hdfs ${OUT_DIR})
  130. set(LIBHDFS_VERSION "0.0.0")
  131. set_target_properties(hdfs PROPERTIES
  132. SOVERSION ${LIBHDFS_VERSION})
  133. add_executable(test_libhdfs_ops
  134. main/native/libhdfs/test/test_libhdfs_ops.c
  135. )
  136. target_link_libraries(test_libhdfs_ops
  137. hdfs_static
  138. ${JAVA_JVM_LIBRARY}
  139. )
  140. add_executable(test_libhdfs_read
  141. main/native/libhdfs/test/test_libhdfs_read.c
  142. )
  143. target_link_libraries(test_libhdfs_read
  144. hdfs_static
  145. ${JAVA_JVM_LIBRARY}
  146. )
  147. add_executable(test_libhdfs_write
  148. main/native/libhdfs/test/test_libhdfs_write.c
  149. )
  150. target_link_libraries(test_libhdfs_write
  151. hdfs_static
  152. ${JAVA_JVM_LIBRARY}
  153. )
  154. add_library(native_mini_dfs
  155. main/native/libhdfs/native_mini_dfs.c
  156. main/native/libhdfs/common/htable.c
  157. main/native/libhdfs/exception.c
  158. main/native/libhdfs/jni_helper.c
  159. ${OS_DIR}/mutexes.c
  160. ${OS_DIR}/thread_local_storage.c
  161. )
  162. target_link_libraries(native_mini_dfs
  163. ${JAVA_JVM_LIBRARY}
  164. ${OS_LINK_LIBRARIES}
  165. )
  166. add_executable(test_native_mini_dfs
  167. main/native/libhdfs/test_native_mini_dfs.c
  168. )
  169. target_link_libraries(test_native_mini_dfs
  170. native_mini_dfs
  171. )
  172. add_executable(test_libhdfs_threaded
  173. main/native/libhdfs/expect.c
  174. main/native/libhdfs/test_libhdfs_threaded.c
  175. ${OS_DIR}/thread.c
  176. )
  177. target_link_libraries(test_libhdfs_threaded
  178. hdfs_static
  179. native_mini_dfs
  180. ${OS_LINK_LIBRARIES}
  181. )
  182. add_executable(test_libhdfs_zerocopy
  183. main/native/libhdfs/expect.c
  184. main/native/libhdfs/test/test_libhdfs_zerocopy.c
  185. )
  186. target_link_libraries(test_libhdfs_zerocopy
  187. hdfs_static
  188. native_mini_dfs
  189. ${OS_LINK_LIBRARIES}
  190. )
  191. add_executable(test_htable
  192. main/native/libhdfs/common/htable.c
  193. main/native/libhdfs/test/test_htable.c
  194. )
  195. target_link_libraries(test_htable
  196. ${OS_LINK_LIBRARIES}
  197. )
  198. # Skip vecsum on Windows. This could be made to work in the future by
  199. # introducing an abstraction layer over the sys/mman.h functions.
  200. if (NOT WIN32)
  201. add_executable(test_libhdfs_vecsum
  202. main/native/libhdfs/test/vecsum.c
  203. )
  204. if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
  205. target_link_libraries(test_libhdfs_vecsum
  206. hdfs
  207. pthread
  208. )
  209. else (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
  210. target_link_libraries(test_libhdfs_vecsum
  211. hdfs
  212. pthread
  213. rt
  214. )
  215. endif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
  216. endif(NOT WIN32)
  217. IF(REQUIRE_LIBWEBHDFS)
  218. add_subdirectory(contrib/libwebhdfs)
  219. ENDIF(REQUIRE_LIBWEBHDFS)
  220. add_subdirectory(main/native/fuse-dfs)