CMakeLists.txt 10 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. #
  19. # CMake configuration.
  20. #
  21. cmake_minimum_required(VERSION 2.6 FATAL_ERROR)
  22. list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/..)
  23. include(HadoopCommon)
  24. # Source and test locations.
  25. set(SRC main/native/src/org/apache/hadoop)
  26. set(TST main/native/src/test/org/apache/hadoop)
  27. #
  28. # Main configuration.
  29. #
  30. # The caller must specify where the generated headers have been placed.
  31. if(NOT GENERATED_JAVAH)
  32. message(FATAL_ERROR "You must set the CMake variable GENERATED_JAVAH")
  33. endif()
  34. # Configure JNI.
  35. include(HadoopJNI)
  36. # Require zlib.
  37. set(STORED_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
  38. hadoop_set_find_shared_library_version("1")
  39. find_package(ZLIB REQUIRED)
  40. set(CMAKE_FIND_LIBRARY_SUFFIXES ${STORED_CMAKE_FIND_LIBRARY_SUFFIXES})
  41. get_filename_component(HADOOP_ZLIB_LIBRARY ${ZLIB_LIBRARIES} NAME)
  42. # Look for bzip2.
  43. set(STORED_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
  44. hadoop_set_find_shared_library_version("1")
  45. find_package(BZip2 QUIET)
  46. if(BZIP2_INCLUDE_DIR AND BZIP2_LIBRARIES)
  47. get_filename_component(HADOOP_BZIP2_LIBRARY ${BZIP2_LIBRARIES} NAME)
  48. set(BZIP2_SOURCE_FILES
  49. "${SRC}/io/compress/bzip2/Bzip2Compressor.c"
  50. "${SRC}/io/compress/bzip2/Bzip2Decompressor.c")
  51. set(REQUIRE_BZIP2 ${REQUIRE_BZIP2}) # Stop warning about unused variable.
  52. else()
  53. set(BZIP2_SOURCE_FILES "")
  54. set(BZIP2_INCLUDE_DIR "")
  55. if(REQUIRE_BZIP2)
  56. message(FATAL_ERROR "Required bzip2 library and/or header files could not be found.")
  57. endif()
  58. endif()
  59. set(CMAKE_FIND_LIBRARY_SUFFIXES ${STORED_CMAKE_FIND_LIBRARY_SUFFIXES})
  60. # Require snappy.
  61. set(STORED_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
  62. hadoop_set_find_shared_library_version("1")
  63. find_library(SNAPPY_LIBRARY
  64. NAMES snappy
  65. PATHS ${CUSTOM_SNAPPY_PREFIX} ${CUSTOM_SNAPPY_PREFIX}/lib
  66. ${CUSTOM_SNAPPY_PREFIX}/lib64 ${CUSTOM_SNAPPY_LIB})
  67. set(CMAKE_FIND_LIBRARY_SUFFIXES ${STORED_CMAKE_FIND_LIBRARY_SUFFIXES})
  68. find_path(SNAPPY_INCLUDE_DIR
  69. NAMES snappy.h
  70. PATHS ${CUSTOM_SNAPPY_PREFIX} ${CUSTOM_SNAPPY_PREFIX}/include
  71. ${CUSTOM_SNAPPY_INCLUDE})
  72. if(SNAPPY_LIBRARY AND SNAPPY_INCLUDE_DIR)
  73. get_filename_component(HADOOP_SNAPPY_LIBRARY ${SNAPPY_LIBRARY} NAME)
  74. set(SNAPPY_SOURCE_FILES
  75. "${SRC}/io/compress/snappy/SnappyCompressor.c"
  76. "${SRC}/io/compress/snappy/SnappyDecompressor.c")
  77. set(REQUIRE_SNAPPY ${REQUIRE_SNAPPY}) # Stop warning about unused variable.
  78. message(STATUS "Found Snappy: ${SNAPPY_LIBRARY}")
  79. else()
  80. set(SNAPPY_INCLUDE_DIR "")
  81. set(SNAPPY_SOURCE_FILES "")
  82. if(REQUIRE_SNAPPY)
  83. message(FATAL_ERROR "Required snappy library could not be found. SNAPPY_LIBRARY=${SNAPPY_LIBRARY}, SNAPPY_INCLUDE_DIR=${SNAPPY_INCLUDE_DIR}, CUSTOM_SNAPPY_INCLUDE_DIR=${CUSTOM_SNAPPY_INCLUDE_DIR}, CUSTOM_SNAPPY_PREFIX=${CUSTOM_SNAPPY_PREFIX}, CUSTOM_SNAPPY_INCLUDE=${CUSTOM_SNAPPY_INCLUDE}")
  84. endif()
  85. endif()
  86. # Require Zstandard
  87. SET(STORED_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
  88. hadoop_set_find_shared_library_version("1")
  89. find_library(ZSTD_LIBRARY
  90. NAMES zstd
  91. PATHS ${CUSTOM_ZSTD_PREFIX} ${CUSTOM_ZSTD_PREFIX}/lib
  92. ${CUSTOM_ZSTD_PREFIX}/lib64 ${CUSTOM_ZSTD_LIB})
  93. SET(CMAKE_FIND_LIBRARY_SUFFIXES ${STORED_CMAKE_FIND_LIBRARY_SUFFIXES})
  94. find_path(ZSTD_INCLUDE_DIR
  95. NAMES zstd.h
  96. PATHS ${CUSTOM_ZSTD_PREFIX} ${CUSTOM_ZSTD_PREFIX}/include
  97. ${CUSTOM_ZSTD_INCLUDE})
  98. if (ZSTD_LIBRARY AND ZSTD_INCLUDE_DIR)
  99. GET_FILENAME_COMPONENT(HADOOP_ZSTD_LIBRARY ${ZSTD_LIBRARY} NAME)
  100. set(ZSTD_SOURCE_FILES
  101. "${SRC}/io/compress/zstd/ZStandardCompressor.c"
  102. "${SRC}/io/compress/zstd/ZStandardDecompressor.c")
  103. else (ZSTD_LIBRARY AND ZSTD_INCLUDE_DIR)
  104. set(ZSTD_INCLUDE_DIR "")
  105. set(ZSTD_SOURCE_FILES "")
  106. IF(REQUIRE_ZSTD)
  107. MESSAGE(FATAL_ERROR "Required zstandard library could not be found. ZSTD_LIBRARY=${ZSTD_LIBRARY}, ZSTD_INCLUDE_DIR=${ZSTD_INCLUDE_DIR}, CUSTOM_ZSTD_INCLUDE_DIR=${CUSTOM_ZSTD_INCLUDE_DIR}, CUSTOM_ZSTD_PREFIX=${CUSTOM_ZSTD_PREFIX}, CUSTOM_ZSTD_INCLUDE=${CUSTOM_ZSTD_INCLUDE}")
  108. ENDIF(REQUIRE_ZSTD)
  109. endif (ZSTD_LIBRARY AND ZSTD_INCLUDE_DIR)
  110. # Build hardware CRC32 acceleration, if supported on the platform.
  111. if(CMAKE_SYSTEM_PROCESSOR MATCHES "^i.86$" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "amd64")
  112. set(BULK_CRC_ARCH_SOURCE_FIlE "${SRC}/util/bulk_crc32_x86.c")
  113. elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64")
  114. set(BULK_CRC_ARCH_SOURCE_FIlE "${SRC}/util/bulk_crc32_aarch64.c")
  115. else()
  116. message("No HW CRC acceleration for ${CMAKE_SYSTEM_PROCESSOR}, falling back to SW")
  117. endif()
  118. # Find the no-suffix version of libcrypto/openssl. See HADOOP-11216 for details.
  119. set(STORED_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
  120. hadoop_set_find_shared_library_without_version()
  121. set(OPENSSL_NAME "crypto")
  122. if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
  123. SET(OPENSSL_NAME "eay32")
  124. endif()
  125. message("CUSTOM_OPENSSL_PREFIX = ${CUSTOM_OPENSSL_PREFIX}")
  126. find_library(OPENSSL_LIBRARY
  127. NAMES ${OPENSSL_NAME}
  128. PATHS ${CUSTOM_OPENSSL_PREFIX} ${CUSTOM_OPENSSL_PREFIX}/lib
  129. ${CUSTOM_OPENSSL_PREFIX}/lib64 ${CUSTOM_OPENSSL_LIB} NO_DEFAULT_PATH)
  130. find_library(OPENSSL_LIBRARY NAMES ${OPENSSL_NAME})
  131. find_path(OPENSSL_INCLUDE_DIR
  132. NAMES openssl/evp.h
  133. PATHS ${CUSTOM_OPENSSL_PREFIX} ${CUSTOM_OPENSSL_PREFIX}/include
  134. ${CUSTOM_OPENSSL_INCLUDE} NO_DEFAULT_PATH)
  135. find_path(OPENSSL_INCLUDE_DIR NAMES openssl/evp.h)
  136. set(CMAKE_FIND_LIBRARY_SUFFIXES ${STORED_CMAKE_FIND_LIBRARY_SUFFIXES})
  137. set(USABLE_OPENSSL 0)
  138. if(OPENSSL_LIBRARY AND OPENSSL_INCLUDE_DIR)
  139. include(CheckCSourceCompiles)
  140. set(OLD_CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES})
  141. set(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIR})
  142. check_c_source_compiles("#include \"${OPENSSL_INCLUDE_DIR}/openssl/evp.h\"\nint main(int argc, char **argv) { return !EVP_aes_256_ctr; }" HAS_NEW_ENOUGH_OPENSSL)
  143. set(CMAKE_REQUIRED_INCLUDES ${OLD_CMAKE_REQUIRED_INCLUDES})
  144. if(NOT HAS_NEW_ENOUGH_OPENSSL)
  145. message("The OpenSSL library installed at ${OPENSSL_LIBRARY} is too old. You need a version at least new enough to have EVP_aes_256_ctr.")
  146. else()
  147. SET(USABLE_OPENSSL 1)
  148. endif()
  149. endif()
  150. if(USABLE_OPENSSL)
  151. get_filename_component(HADOOP_OPENSSL_LIBRARY ${OPENSSL_LIBRARY} NAME)
  152. set(OPENSSL_SOURCE_FILES
  153. "${SRC}/crypto/OpensslCipher.c"
  154. "${SRC}/crypto/random/OpensslSecureRandom.c")
  155. set(REQUIRE_OPENSSL ${REQUIRE_OPENSSL}) # Stop warning about unused variable.
  156. else()
  157. message("Cannot find a usable OpenSSL library. OPENSSL_LIBRARY=${OPENSSL_LIBRARY}, OPENSSL_INCLUDE_DIR=${OPENSSL_INCLUDE_DIR}, CUSTOM_OPENSSL_LIB=${CUSTOM_OPENSSL_LIB}, CUSTOM_OPENSSL_PREFIX=${CUSTOM_OPENSSL_PREFIX}, CUSTOM_OPENSSL_INCLUDE=${CUSTOM_OPENSSL_INCLUDE}")
  158. if(REQUIRE_OPENSSL)
  159. message(FATAL_ERROR "Terminating build because require.openssl was specified.")
  160. endif()
  161. set(OPENSSL_LIBRARY "")
  162. set(OPENSSL_INCLUDE_DIR "")
  163. set(OPENSSL_SOURCE_FILES "")
  164. endif()
  165. # Check for platform-specific functions and libraries.
  166. include(CheckFunctionExists)
  167. include(CheckLibraryExists)
  168. check_function_exists(sync_file_range HAVE_SYNC_FILE_RANGE)
  169. check_function_exists(posix_fadvise HAVE_POSIX_FADVISE)
  170. check_library_exists(dl dlopen "" NEED_LINK_DL)
  171. # Configure the build.
  172. include_directories(
  173. ${GENERATED_JAVAH}
  174. main/native/src
  175. ${CMAKE_CURRENT_SOURCE_DIR}
  176. ${CMAKE_CURRENT_SOURCE_DIR}/src
  177. ${CMAKE_BINARY_DIR}
  178. ${JNI_INCLUDE_DIRS}
  179. ${ZLIB_INCLUDE_DIRS}
  180. ${BZIP2_INCLUDE_DIR}
  181. ${SNAPPY_INCLUDE_DIR}
  182. ${ZSTD_INCLUDE_DIR}
  183. ${OPENSSL_INCLUDE_DIR}
  184. ${SRC}/util
  185. )
  186. configure_file(${CMAKE_SOURCE_DIR}/config.h.cmake ${CMAKE_BINARY_DIR}/config.h)
  187. set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
  188. hadoop_add_dual_library(hadoop
  189. main/native/src/exception.c
  190. ${SRC}/io/compress/lz4/Lz4Compressor.c
  191. ${SRC}/io/compress/lz4/Lz4Decompressor.c
  192. ${SRC}/io/compress/lz4/lz4.c
  193. ${SRC}/io/compress/lz4/lz4hc.c
  194. ${SNAPPY_SOURCE_FILES}
  195. ${ZSTD_SOURCE_FILES}
  196. ${OPENSSL_SOURCE_FILES}
  197. ${SRC}/io/compress/zlib/ZlibCompressor.c
  198. ${SRC}/io/compress/zlib/ZlibDecompressor.c
  199. ${BZIP2_SOURCE_FILES}
  200. ${SRC}/io/nativeio/NativeIO.c
  201. ${SRC}/io/nativeio/errno_enum.c
  202. ${SRC}/io/nativeio/file_descriptor.c
  203. ${SRC}/io/nativeio/SharedFileDescriptorFactory.c
  204. ${SRC}/net/unix/DomainSocket.c
  205. ${SRC}/net/unix/DomainSocketWatcher.c
  206. ${SRC}/security/JniBasedUnixGroupsMapping.c
  207. ${SRC}/security/JniBasedUnixGroupsNetgroupMapping.c
  208. ${SRC}/security/hadoop_group_info.c
  209. ${SRC}/security/hadoop_user_info.c
  210. ${SRC}/util/NativeCodeLoader.c
  211. ${SRC}/util/NativeCrc32.c
  212. ${SRC}/util/bulk_crc32.c
  213. ${BULK_CRC_ARCH_SOURCE_FIlE}
  214. )
  215. if(NEED_LINK_DL)
  216. set(LIB_DL dl)
  217. endif()
  218. hadoop_target_link_dual_libraries(hadoop ${LIB_DL} ${JAVA_JVM_LIBRARY})
  219. set(LIBHADOOP_VERSION "1.0.0")
  220. set_target_properties(hadoop PROPERTIES SOVERSION ${LIBHADOOP_VERSION})
  221. hadoop_dual_output_directory(hadoop target/usr/local/lib)
  222. # By embedding '$ORIGIN' into the RPATH of libhadoop.so, dlopen will look in
  223. # the directory containing libhadoop.so. However, $ORIGIN is not supported by
  224. # all operating systems.
  225. if(${CMAKE_SYSTEM_NAME} MATCHES "Linux|SunOS")
  226. set(RPATH "\$ORIGIN/")
  227. if(EXTRA_LIBHADOOP_RPATH)
  228. set(RPATH "${RPATH}:${EXTRA_LIBHADOOP_RPATH}/")
  229. endif()
  230. set_target_properties(hadoop PROPERTIES INSTALL_RPATH "${RPATH}")
  231. endif()
  232. # Build the CRC32 test executable.
  233. add_executable(test_bulk_crc32
  234. ${SRC}/util/bulk_crc32.c
  235. ${BULK_CRC_ARCH_SOURCE_FIlE}
  236. ${TST}/util/test_bulk_crc32.c
  237. )