CMakeLists.txt 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/../../../hadoop-common-project/hadoop-common)
  20. include(HadoopCommon)
  21. # Check to see if our compiler and linker support the __thread attribute.
  22. # On Linux and some other operating systems, this is a more efficient
  23. # alternative to POSIX thread local storage.
  24. include(CheckCSourceCompiles)
  25. check_c_source_compiles("int main(void) { static __thread int i = 0; return 0; }" HAVE_BETTER_TLS)
  26. # Check to see if we have Intel SSE intrinsics.
  27. 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)
  28. set(_FUSE_DFS_VERSION 0.1.0)
  29. configure_file(${CMAKE_SOURCE_DIR}/config.h.cmake ${CMAKE_BINARY_DIR}/config.h)
  30. # Check if we need to link dl library to get dlopen.
  31. # dlopen on Linux is in separate library but on FreeBSD its in libc
  32. include(CheckLibraryExists)
  33. check_library_exists(dl dlopen "" NEED_LINK_DL)
  34. if(WIN32)
  35. # Set the optimizer level.
  36. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /O2")
  37. # Set warning level 4.
  38. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4")
  39. # Skip "unreferenced formal parameter".
  40. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4100")
  41. # Skip "conditional expression is constant".
  42. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4127")
  43. # Skip deprecated POSIX function warnings.
  44. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_CRT_NONSTDC_NO_DEPRECATE")
  45. # Skip CRT non-secure function warnings. If we can convert usage of
  46. # strerror, getenv and ctime to their secure CRT equivalents, then we can
  47. # re-enable the CRT non-secure function warnings.
  48. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_CRT_SECURE_NO_WARNINGS")
  49. # Omit unneeded headers.
  50. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWIN32_LEAN_AND_MEAN")
  51. set(OS_DIR ${CMAKE_SOURCE_DIR}/main/native/libhdfs/os/windows)
  52. set(OUT_DIR target/bin)
  53. else()
  54. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden")
  55. set(OS_DIR ${CMAKE_SOURCE_DIR}/main/native/libhdfs/os/posix)
  56. set(OUT_DIR target/usr/local/lib)
  57. endif()
  58. # Configure JNI.
  59. include(HadoopJNI)
  60. function(add_libhdfs_test NAME LIBRARY)
  61. set(FILES)
  62. foreach(FIL ${ARGN})
  63. if (IS_ABSOLUTE ${FIL})
  64. list(APPEND FILES ${FIL})
  65. else()
  66. list(APPEND FILES ${CMAKE_SOURCE_DIR}/main/native/libhdfs-tests/${FIL})
  67. endif()
  68. endforeach()
  69. add_executable("${NAME}_${LIBRARY}" ${FILES})
  70. endfunction()
  71. function(link_libhdfs_test NAME LIBRARY)
  72. target_link_libraries("${NAME}_${LIBRARY}" ${LIBRARY} ${ARGN})
  73. endfunction()
  74. add_subdirectory(main/native/libhdfs)
  75. add_subdirectory(main/native/libhdfs-tests)
  76. if(REQUIRE_LIBWEBHDFS)
  77. add_subdirectory(contrib/libwebhdfs)
  78. endif()
  79. # Find Linux FUSE
  80. if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
  81. find_package(PkgConfig REQUIRED)
  82. pkg_check_modules(FUSE fuse)
  83. if(FUSE_FOUND)
  84. add_subdirectory(main/native/fuse-dfs)
  85. else()
  86. message(STATUS "Failed to find Linux FUSE libraries or include files. Will not build FUSE client.")
  87. if(REQUIRE_FUSE)
  88. message(FATAL_ERROR "Required component fuse_dfs could not be built.")
  89. endif()
  90. endif(FUSE_FOUND)
  91. else()
  92. message(STATUS "Non-Linux system detected. Will not build FUSE client.")
  93. if(REQUIRE_FUSE)
  94. message(FATAL_ERROR "Required component fuse_dfs could not be built.")
  95. endif()
  96. endif()