CMakeLists.txt 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. 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. add_subdirectory(main/native/libhdfs)
  85. add_subdirectory(main/native/libhdfs-tests)
  86. # Find Linux FUSE
  87. if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
  88. find_package(PkgConfig REQUIRED)
  89. pkg_check_modules(FUSE fuse)
  90. if(FUSE_FOUND)
  91. add_subdirectory(main/native/fuse-dfs)
  92. else()
  93. message(STATUS "Failed to find Linux FUSE libraries or include files. Will not build FUSE client.")
  94. if(REQUIRE_FUSE)
  95. message(FATAL_ERROR "Required component fuse_dfs could not be built.")
  96. endif()
  97. endif(FUSE_FOUND)
  98. else()
  99. message(STATUS "Non-Linux system detected. Will not build FUSE client.")
  100. if(REQUIRE_FUSE)
  101. message(FATAL_ERROR "Required component fuse_dfs could not be built.")
  102. endif()
  103. endif()