CMakeLists.txt 8.1 KB

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