CMakeLists.txt 7.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 2.6 FATAL_ERROR)
  19. list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/../../../../hadoop-common-project/hadoop-common/)
  20. include(HadoopCommon)
  21. # Add extra compiler and linker flags.
  22. # -Wno-sign-compare
  23. hadoop_add_compiler_flags("-DNDEBUG -DSIMPLE_MEMCPY -fno-strict-aliasing")
  24. # Source location.
  25. set(SRC main/native)
  26. # The caller must specify where the generated headers have been placed.
  27. if(NOT GENERATED_JAVAH)
  28. message(FATAL_ERROR "You must set the CMake variable GENERATED_JAVAH")
  29. endif()
  30. # Configure JNI.
  31. include(HadoopJNI)
  32. # Probe for headers and functions.
  33. include(CheckFunctionExists)
  34. include(CheckIncludeFiles)
  35. check_include_files(fcntl.h HAVE_FCNTL_H)
  36. check_include_files(malloc.h HAVE_MALLOC_H)
  37. check_include_files(mach/mach.h HAVE_MACH_MACH_H)
  38. check_include_files(memory.h HAVE_MEMORY_H)
  39. check_include_files(stddef.h HAVE_STDDEF_H)
  40. check_include_files(stdint.h HAVE_STDINT_H)
  41. check_include_files(stdlib.h HAVE_STDLIB_H)
  42. Check_include_files(string.h HAVE_STRING_H)
  43. check_include_files(unistd.h HAVE_UNITSTD_H)
  44. check_function_exists(clock_gettime HAVE_CLOCK_GETTIME)
  45. check_function_exists(localtime_r HAVE_LOCALTIME_R)
  46. check_function_exists(memset HAVE_MEMSET)
  47. check_function_exists(strchr HAVE_STRCHR)
  48. check_function_exists(strtoul HAVE_STRTOUL)
  49. # Require snappy.
  50. set(STORED_CMAKE_FIND_LIBRARY_SUFFIXES CMAKE_FIND_LIBRARY_SUFFIXES)
  51. hadoop_set_find_shared_library_version("1")
  52. find_library(SNAPPY_LIBRARY
  53. NAMES snappy
  54. PATHS ${CUSTOM_SNAPPY_PREFIX} ${CUSTOM_SNAPPY_PREFIX}/lib
  55. ${CUSTOM_SNAPPY_PREFIX}/lib64 ${CUSTOM_SNAPPY_LIB})
  56. set(CMAKE_FIND_LIBRARY_SUFFIXES STORED_CMAKE_FIND_LIBRARY_SUFFIXES)
  57. find_path(SNAPPY_INCLUDE_DIR
  58. NAMES snappy.h
  59. PATHS ${CUSTOM_SNAPPY_PREFIX} ${CUSTOM_SNAPPY_PREFIX}/include
  60. ${CUSTOM_SNAPPY_INCLUDE})
  61. if(SNAPPY_LIBRARY AND SNAPPY_INCLUDE_DIR)
  62. GET_FILENAME_COMPONENT(HADOOP_SNAPPY_LIBRARY ${SNAPPY_LIBRARY} NAME)
  63. set(SNAPPY_SOURCE_FILES
  64. "${SRC}/src/codec/SnappyCodec.cc")
  65. set(REQUIRE_SNAPPY ${REQUIRE_SNAPPY}) # Stop warning about unused variable.
  66. message(STATUS "Found Snappy: ${SNAPPY_LIBRARY}")
  67. else()
  68. set(SNAPPY_LIBRARY "")
  69. set(SNAPPY_INCLUDE_DIR "")
  70. set(SNAPPY_SOURCE_FILES "")
  71. if(REQUIRE_SNAPPY)
  72. message(FATAL_ERROR "Required snappy library could not be found. SNAPPY_LIBRARY=${SNAPPY_LIBRARY}, SNAPPY_INCLUDE_DIR=${SNAPPY_INCLUDE_DIR}, CUSTOM_SNAPPY_INCLUDE_DIR=${CUSTOM_SNAPPY_INCLUDE_DIR}, CUSTOM_SNAPPY_PREFIX=${CUSTOM_SNAPPY_PREFIX}, CUSTOM_SNAPPY_INCLUDE=${CUSTOM_SNAPPY_INCLUDE}")
  73. endif()
  74. endif()
  75. configure_file(${CMAKE_SOURCE_DIR}/config.h.cmake ${CMAKE_BINARY_DIR}/config.h)
  76. include_directories(
  77. ${GENERATED_JAVAH}
  78. ${SRC}/src
  79. ${SRC}/src/util
  80. ${SRC}/src/lib
  81. ${SRC}/test
  82. ${CMAKE_CURRENT_SOURCE_DIR}
  83. ${CMAKE_BINARY_DIR}
  84. ${JNI_INCLUDE_DIRS}
  85. ${SNAPPY_INCLUDE_DIR}
  86. )
  87. # add gtest as system library to suppress gcc warnings
  88. include_directories(SYSTEM ${SRC}/gtest/include)
  89. set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
  90. if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
  91. # macosx does not have -lrt
  92. set(NT_DEPEND_LIBRARY dl pthread z ${SNAPPY_LIBRARY} ${JAVA_JVM_LIBRARY})
  93. set(SYSTEM_MAC TRUE)
  94. else()
  95. set(NT_DEPEND_LIBRARY dl rt pthread z ${SNAPPY_LIBRARY} ${JAVA_JVM_LIBRARY})
  96. set(SYSTEM_MAC FALSE)
  97. endif()
  98. configure_file(main/native/test.sh test/test.sh)
  99. hadoop_add_dual_library(nativetask
  100. ${CMAKE_BINARY_DIR}/lz4.c
  101. ${SRC}/src/codec/BlockCodec.cc
  102. ${SRC}/src/codec/GzipCodec.cc
  103. ${SRC}/src/codec/Lz4Codec.cc
  104. ${SNAPPY_SOURCE_FILES}
  105. ${SRC}/src/handler/BatchHandler.cc
  106. ${SRC}/src/handler/MCollectorOutputHandler.cc
  107. ${SRC}/src/handler/AbstractMapHandler.cc
  108. ${SRC}/src/handler/CombineHandler.cc
  109. ${SRC}/src/lib/Buffers.cc
  110. ${SRC}/src/lib/BufferStream.cc
  111. ${SRC}/src/lib/Compressions.cc
  112. ${SRC}/src/lib/PartitionBucket.cc
  113. ${SRC}/src/lib/PartitionBucketIterator.cc
  114. ${SRC}/src/lib/FileSystem.cc
  115. ${SRC}/src/lib/IFile.cc
  116. ${SRC}/src/lib/jniutils.cc
  117. ${SRC}/src/lib/Log.cc
  118. ${SRC}/src/lib/MapOutputCollector.cc
  119. ${SRC}/src/lib/MapOutputSpec.cc
  120. ${SRC}/src/lib/MemoryBlock.cc
  121. ${SRC}/src/lib/Merge.cc
  122. ${SRC}/src/lib/NativeLibrary.cc
  123. ${SRC}/src/lib/Iterator.cc
  124. ${SRC}/src/lib/NativeObjectFactory.cc
  125. ${SRC}/src/lib/NativeRuntimeJniImpl.cc
  126. ${SRC}/src/lib/NativeTask.cc
  127. ${SRC}/src/lib/SpillInfo.cc
  128. ${SRC}/src/lib/Path.cc
  129. ${SRC}/src/lib/Streams.cc
  130. ${SRC}/src/lib/TaskCounters.cc
  131. ${SRC}/src/util/Checksum.cc
  132. ${SRC}/src/util/Random.cc
  133. ${SRC}/src/util/StringUtil.cc
  134. ${SRC}/src/util/SyncUtils.cc
  135. ${SRC}/src/util/Timer.cc
  136. ${SRC}/src/util/WritableUtils.cc
  137. )
  138. target_link_libraries(nativetask ${NT_DEPEND_LIBRARY})
  139. add_library(gtest ${SRC}/gtest/gtest-all.cc)
  140. set_target_properties(gtest PROPERTIES COMPILE_FLAGS "-w")
  141. add_executable(nttest
  142. ${SRC}/test/lib/TestByteArray.cc
  143. ${SRC}/test/lib/TestByteBuffer.cc
  144. ${SRC}/test/lib/TestComparatorForDualPivotQuickSort.cc
  145. ${SRC}/test/lib/TestComparatorForStdSort.cc
  146. ${SRC}/test/lib/TestFixSizeContainer.cc
  147. ${SRC}/test/lib/TestMemoryPool.cc
  148. ${SRC}/test/lib/TestIterator.cc
  149. ${SRC}/test/lib/TestKVBuffer.cc
  150. ${SRC}/test/lib/TestMemBlockIterator.cc
  151. ${SRC}/test/lib/TestMemoryBlock.cc
  152. ${SRC}/test/lib/TestPartitionBucket.cc
  153. ${SRC}/test/lib/TestReadBuffer.cc
  154. ${SRC}/test/lib/TestReadWriteBuffer.cc
  155. ${SRC}/test/util/TestChecksum.cc
  156. ${SRC}/test/util/TestStringUtil.cc
  157. ${SRC}/test/util/TestWritableUtils.cc
  158. ${SRC}/test/TestCommand.cc
  159. ${SRC}/test/TestConfig.cc
  160. ${SRC}/test/TestCounter.cc
  161. ${SRC}/test/TestCompressions.cc
  162. ${SRC}/test/TestFileSystem.cc
  163. ${SRC}/test/TestIFile.cc
  164. ${SRC}/test/TestPrimitives.cc
  165. ${SRC}/test/TestSort.cc
  166. ${SRC}/test/TestMain.cc
  167. ${SRC}/test/test_commons.cc)
  168. target_link_libraries(nttest
  169. nativetask_static
  170. gtest
  171. ${NT_DEPEND_LIBRARY}
  172. )
  173. # By embedding '$ORIGIN' into the RPATH of libnativetask.so, dlopen will look in
  174. # the directory containing libnativetask.so. However, $ORIGIN is not supported by
  175. # all operating systems.
  176. if(CMAKE_SYSTEM_NAME MATCHES "Linux|SunOS")
  177. set_target_properties(nativetask PROPERTIES INSTALL_RPATH "\$ORIGIN/")
  178. endif()
  179. set(LIBNATIVETASK_VERSION "1.0.0")
  180. set_target_properties(nativetask PROPERTIES SOVERSION ${LIBNATIVETASK_VERSION})
  181. hadoop_dual_output_directory(nativetask target/usr/local/lib)
  182. hadoop_output_directory(nttest test)