CMakeLists.txt 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. # Default to release builds
  20. set(CMAKE_BUILD_TYPE, Release)
  21. # If JVM_ARCH_DATA_MODEL is 32, compile all binaries as 32-bit.
  22. # This variable is set by maven.
  23. if (JVM_ARCH_DATA_MODEL EQUAL 32)
  24. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32")
  25. set(CMAKE_LD_FLAGS "${CMAKE_LD_FLAGS} -m32")
  26. endif (JVM_ARCH_DATA_MODEL EQUAL 32)
  27. # Compile a library with both shared and static variants
  28. function(add_dual_library LIBNAME)
  29. add_library(${LIBNAME} SHARED ${ARGN})
  30. add_library(${LIBNAME}_static STATIC ${ARGN})
  31. set_target_properties(${LIBNAME}_static PROPERTIES OUTPUT_NAME ${LIBNAME})
  32. endfunction(add_dual_library)
  33. # Link both a static and a dynamic target against some libraries
  34. function(target_link_dual_libraries LIBNAME)
  35. target_link_libraries(${LIBNAME} ${ARGN})
  36. target_link_libraries(${LIBNAME}_static ${ARGN})
  37. endfunction(target_link_dual_libraries)
  38. function(output_directory TGT DIR)
  39. SET_TARGET_PROPERTIES(${TGT} PROPERTIES
  40. RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${DIR}")
  41. SET_TARGET_PROPERTIES(${TGT} PROPERTIES
  42. ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${DIR}")
  43. SET_TARGET_PROPERTIES(${TGT} PROPERTIES
  44. LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${DIR}")
  45. endfunction(output_directory TGT DIR)
  46. function(dual_output_directory TGT DIR)
  47. output_directory(${TGT} "${DIR}")
  48. output_directory(${TGT}_static "${DIR}")
  49. endfunction(dual_output_directory TGT DIR)
  50. if (NOT GENERATED_JAVAH)
  51. # Must identify where the generated headers have been placed
  52. MESSAGE(FATAL_ERROR "You must set the cmake variable GENERATED_JAVAH")
  53. endif (NOT GENERATED_JAVAH)
  54. find_package(JNI REQUIRED)
  55. find_package(ZLIB REQUIRED)
  56. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -Wall -O2")
  57. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_REENTRANT -D_FILE_OFFSET_BITS=64")
  58. set(D main/native/src/org/apache/hadoop)
  59. GET_FILENAME_COMPONENT(HADOOP_ZLIB_LIBRARY ${ZLIB_LIBRARIES} NAME)
  60. INCLUDE(CheckFunctionExists)
  61. INCLUDE(CheckCSourceCompiles)
  62. CHECK_FUNCTION_EXISTS(sync_file_range HAVE_SYNC_FILE_RANGE)
  63. CHECK_FUNCTION_EXISTS(posix_fadvise HAVE_POSIX_FADVISE)
  64. find_library(SNAPPY_LIBRARY NAMES snappy PATHS)
  65. find_path(SNAPPY_INCLUDE_DIR NAMES snappy.h PATHS)
  66. if (SNAPPY_LIBRARY)
  67. GET_FILENAME_COMPONENT(HADOOP_SNAPPY_LIBRARY ${SNAPPY_LIBRARY} NAME)
  68. set(SNAPPY_SOURCE_FILES
  69. "${D}/io/compress/snappy/SnappyCompressor.c"
  70. "${D}/io/compress/snappy/SnappyDecompressor.c")
  71. else (${SNAPPY_LIBRARY})
  72. set(SNAPPY_INCLUDE_DIR "")
  73. set(SNAPPY_SOURCE_FILES "")
  74. endif (SNAPPY_LIBRARY)
  75. include_directories(
  76. ${GENERATED_JAVAH}
  77. main/native/src
  78. ${CMAKE_CURRENT_SOURCE_DIR}
  79. ${CMAKE_CURRENT_SOURCE_DIR}/src
  80. ${CMAKE_BINARY_DIR}
  81. ${JNI_INCLUDE_DIRS}
  82. ${ZLIB_INCLUDE_DIRS}
  83. ${SNAPPY_INCLUDE_DIR}
  84. )
  85. CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/config.h.cmake ${CMAKE_BINARY_DIR}/config.h)
  86. add_dual_library(hadoop
  87. ${D}/io/compress/lz4/Lz4Compressor.c
  88. ${D}/io/compress/lz4/Lz4Decompressor.c
  89. ${D}/io/compress/lz4/lz4.c
  90. ${SNAPPY_SOURCE_FILES}
  91. ${D}/io/compress/zlib/ZlibCompressor.c
  92. ${D}/io/compress/zlib/ZlibDecompressor.c
  93. ${D}/io/nativeio/NativeIO.c
  94. ${D}/io/nativeio/errno_enum.c
  95. ${D}/io/nativeio/file_descriptor.c
  96. ${D}/security/JniBasedUnixGroupsMapping.c
  97. ${D}/security/JniBasedUnixGroupsNetgroupMapping.c
  98. ${D}/security/getGroup.c
  99. ${D}/util/NativeCrc32.c
  100. ${D}/util/bulk_crc32.c
  101. )
  102. target_link_dual_libraries(hadoop
  103. dl
  104. ${JAVA_JVM_LIBRARY}
  105. )
  106. SET(LIBHADOOP_VERSION "1.0.0")
  107. SET_TARGET_PROPERTIES(hadoop PROPERTIES
  108. SOVERSION ${LIBHADOOP_VERSION})
  109. dual_output_directory(hadoop target/usr/local/lib)
  110. if (HADOOP_RUNAS_HOME)
  111. add_executable(runAs
  112. test/system/c++/runAs/runAs.c
  113. test/system/c++/runAs/main.c
  114. )
  115. output_directory(runAs target/usr/local/bin)
  116. endif (HADOOP_RUNAS_HOME)