CMakeLists.txt 7.3 KB

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