CMakeLists.txt 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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 3.1 FATAL_ERROR)
  19. enable_testing()
  20. list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/../../../hadoop-common-project/hadoop-common)
  21. include(HadoopCommon)
  22. # Check to see if our compiler and linker support the __thread attribute.
  23. # On Linux and some other operating systems, this is a more efficient
  24. # alternative to POSIX thread local storage.
  25. include(CheckCSourceCompiles)
  26. check_c_source_compiles("int main(void) { static __thread int i = 0; return 0; }" HAVE_BETTER_TLS)
  27. # Check to see if we have Intel SSE intrinsics.
  28. 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)
  29. set(_FUSE_DFS_VERSION 0.1.0)
  30. configure_file(${CMAKE_SOURCE_DIR}/config.h.cmake ${CMAKE_BINARY_DIR}/config.h)
  31. # Check if we need to link dl library to get dlopen.
  32. # dlopen on Linux is in separate library but on FreeBSD its in libc
  33. include(CheckLibraryExists)
  34. check_library_exists(dl dlopen "" NEED_LINK_DL)
  35. if(WIN32)
  36. # Set the optimizer level.
  37. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /O2")
  38. # Set warning level 4.
  39. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4")
  40. # Skip "unreferenced formal parameter".
  41. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4100")
  42. # Skip "conditional expression is constant".
  43. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4127")
  44. # Skip deprecated POSIX function warnings.
  45. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_CRT_NONSTDC_NO_DEPRECATE")
  46. # Skip CRT non-secure function warnings. If we can convert usage of
  47. # strerror, getenv and ctime to their secure CRT equivalents, then we can
  48. # re-enable the CRT non-secure function warnings.
  49. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_CRT_SECURE_NO_WARNINGS")
  50. # Omit unneeded headers.
  51. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWIN32_LEAN_AND_MEAN")
  52. set(OS_DIR ${CMAKE_SOURCE_DIR}/main/native/libhdfs/os/windows)
  53. # IMPORTANT: OUT_DIR MUST be relative to maven's
  54. # project.build.directory (=target) and match dist-copynativelibs
  55. # in order to be in a release
  56. set(OUT_DIR bin)
  57. else()
  58. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden")
  59. set(OS_DIR ${CMAKE_SOURCE_DIR}/main/native/libhdfs/os/posix)
  60. # IMPORTANT: OUT_DIR MUST be relative to maven's
  61. # project.build.directory (=target) and match dist-copynativelibs
  62. # in order to be in a release
  63. set(OUT_DIR native/target/usr/local/lib)
  64. endif()
  65. # Configure JNI.
  66. include(HadoopJNI)
  67. function(build_libhdfs_test NAME LIBRARY)
  68. set(FILES)
  69. foreach(FIL ${ARGN})
  70. if (IS_ABSOLUTE ${FIL})
  71. list(APPEND FILES ${FIL})
  72. else()
  73. list(APPEND FILES ${CMAKE_SOURCE_DIR}/main/native/libhdfs-tests/${FIL})
  74. endif()
  75. endforeach()
  76. add_executable("${NAME}_${LIBRARY}" ${FILES})
  77. endfunction()
  78. function(add_libhdfs_test NAME LIBRARY)
  79. add_test("test_${NAME}_${LIBRARY}" "${NAME}_${LIBRARY}")
  80. endfunction()
  81. function(link_libhdfs_test NAME LIBRARY)
  82. target_link_libraries("${NAME}_${LIBRARY}" ${LIBRARY} ${ARGN})
  83. endfunction()
  84. set(STORED_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
  85. hadoop_set_find_shared_library_without_version()
  86. set(OPENSSL_NAME "crypto")
  87. if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
  88. SET(OPENSSL_NAME "eay32")
  89. endif()
  90. message("CUSTOM_OPENSSL_PREFIX = ${CUSTOM_OPENSSL_PREFIX}")
  91. find_library(OPENSSL_LIBRARY
  92. NAMES ${OPENSSL_NAME}
  93. PATHS ${CUSTOM_OPENSSL_PREFIX} ${CUSTOM_OPENSSL_PREFIX}/lib
  94. ${CUSTOM_OPENSSL_PREFIX}/lib64 ${CUSTOM_OPENSSL_LIB} NO_DEFAULT_PATH)
  95. find_library(OPENSSL_LIBRARY NAMES ${OPENSSL_NAME})
  96. find_path(OPENSSL_INCLUDE_DIR
  97. NAMES openssl/evp.h
  98. PATHS ${CUSTOM_OPENSSL_PREFIX} ${CUSTOM_OPENSSL_PREFIX}/include
  99. ${CUSTOM_OPENSSL_INCLUDE} NO_DEFAULT_PATH)
  100. find_path(OPENSSL_INCLUDE_DIR NAMES openssl/evp.h)
  101. set(CMAKE_FIND_LIBRARY_SUFFIXES ${STORED_CMAKE_FIND_LIBRARY_SUFFIXES})
  102. set(USABLE_OPENSSL 0)
  103. if(OPENSSL_LIBRARY AND OPENSSL_INCLUDE_DIR)
  104. include(CheckCSourceCompiles)
  105. set(OLD_CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES})
  106. set(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIR})
  107. 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)
  108. set(CMAKE_REQUIRED_INCLUDES ${OLD_CMAKE_REQUIRED_INCLUDES})
  109. if(NOT HAS_NEW_ENOUGH_OPENSSL)
  110. 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.")
  111. else()
  112. SET(USABLE_OPENSSL 1)
  113. endif()
  114. endif()
  115. if(USABLE_OPENSSL)
  116. get_filename_component(HADOOP_OPENSSL_LIBRARY ${OPENSSL_LIBRARY} NAME)
  117. set(OPENSSL_SOURCE_FILES
  118. "${SRC}/crypto/OpensslCipher.c"
  119. "${SRC}/crypto/random/OpensslSecureRandom.c")
  120. set(REQUIRE_OPENSSL ${REQUIRE_OPENSSL}) # Stop warning about unused variable.
  121. else()
  122. 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}")
  123. if(REQUIRE_OPENSSL)
  124. message(FATAL_ERROR "Terminating build because require.openssl was specified.")
  125. endif()
  126. set(OPENSSL_LIBRARY "")
  127. set(OPENSSL_INCLUDE_DIR "")
  128. set(OPENSSL_SOURCE_FILES "")
  129. endif()
  130. add_subdirectory(main/native/libhdfs)
  131. add_subdirectory(main/native/libhdfs-tests)
  132. add_subdirectory(main/native/libhdfs-examples)
  133. # Temporary fix to disable Libhdfs++ build on older systems that do not support thread_local
  134. include(CheckCXXSourceCompiles)
  135. unset (THREAD_LOCAL_SUPPORTED CACHE)
  136. set (CMAKE_REQUIRED_DEFINITIONS "-std=c++11")
  137. set (CMAKE_REQUIRED_LIBRARIES ${CMAKE_THREAD_LIBS_INIT})
  138. check_cxx_source_compiles(
  139. "#include <thread>
  140. int main(void) {
  141. thread_local int s;
  142. return 0;
  143. }"
  144. THREAD_LOCAL_SUPPORTED)
  145. if (THREAD_LOCAL_SUPPORTED)
  146. add_subdirectory(main/native/libhdfspp)
  147. else()
  148. message(WARNING
  149. "WARNING: Libhdfs++ library was not built because the required feature thread_local storage \
  150. is not supported by your compiler. Known compilers that support this feature: GCC 4.8+, Visual Studio 2015+, \
  151. Clang (community version 3.3+), Clang (version for Xcode 8+ and iOS 9+).")
  152. endif (THREAD_LOCAL_SUPPORTED)
  153. if(REQUIRE_LIBWEBHDFS)
  154. add_subdirectory(contrib/libwebhdfs)
  155. endif()
  156. # Find Linux FUSE
  157. if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
  158. find_package(PkgConfig REQUIRED)
  159. pkg_check_modules(FUSE fuse)
  160. if(FUSE_FOUND)
  161. add_subdirectory(main/native/fuse-dfs)
  162. else()
  163. message(STATUS "Failed to find Linux FUSE libraries or include files. Will not build FUSE client.")
  164. if(REQUIRE_FUSE)
  165. message(FATAL_ERROR "Required component fuse_dfs could not be built.")
  166. endif()
  167. endif(FUSE_FOUND)
  168. else()
  169. message(STATUS "Non-Linux system detected. Will not build FUSE client.")
  170. if(REQUIRE_FUSE)
  171. message(FATAL_ERROR "Required component fuse_dfs could not be built.")
  172. endif()
  173. endif()