CMakeLists.txt 7.4 KB

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