CMakeLists.txt 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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. project (libhdfspp)
  19. cmake_minimum_required(VERSION 2.8)
  20. enable_testing()
  21. include (CTest)
  22. find_package(Doxygen)
  23. find_package(OpenSSL REQUIRED)
  24. find_package(Protobuf REQUIRED)
  25. find_package(Threads)
  26. find_program(MEMORYCHECK_COMMAND valgrind HINTS ${VALGRIND_DIR} )
  27. set(MEMORYCHECK_COMMAND_OPTIONS "--trace-children=yes --leak-check=full --error-exitcode=1")
  28. message(STATUS "valgrind location: ${MEMORYCHECK_COMMAND}")
  29. if (REQUIRE_VALGRIND AND MEMORYCHECK_COMMAND MATCHES "MEMORYCHECK_COMMAND-NOTFOUND" )
  30. message(FATAL_ERROR "valgrind was required but not found. "
  31. "The path can be included via a -DVALGRIND_DIR=... flag passed to CMake.")
  32. endif (REQUIRE_VALGRIND AND MEMORYCHECK_COMMAND MATCHES "MEMORYCHECK_COMMAND-NOTFOUND" )
  33. add_definitions(-DASIO_STANDALONE -DASIO_CPP11_DATE_TIME)
  34. # Disable optimizations if compiling debug
  35. set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0")
  36. set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0")
  37. if(UNIX)
  38. set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic -std=c++11 -g -fPIC -fno-strict-aliasing")
  39. set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -fPIC -fno-strict-aliasing")
  40. endif()
  41. # Mac OS 10.7 and later deprecates most of the methods in OpenSSL.
  42. # Add -Wno-deprecated-declarations to avoid the warnings.
  43. if(APPLE)
  44. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++ -Wno-deprecated-declarations -Wno-unused-local-typedef")
  45. endif()
  46. if(DOXYGEN_FOUND)
  47. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/doc/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/doc/Doxyfile @ONLY)
  48. add_custom_target(doc ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/doc/Doxyfile
  49. WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
  50. COMMENT "Generating API documentation with Doxygen" VERBATIM)
  51. endif(DOXYGEN_FOUND)
  52. # Copy files from the hadoop tree into the output/extern directory if
  53. # they've changed
  54. function (copy_on_demand input_src_glob input_dest_dir)
  55. get_filename_component(src_glob ${input_src_glob} REALPATH)
  56. get_filename_component(dest_dir ${input_dest_dir} REALPATH)
  57. get_filename_component(src_dir ${src_glob} PATH)
  58. message(STATUS "Syncing ${src_glob} to ${dest_dir}")
  59. file(GLOB_RECURSE src_files ${src_glob})
  60. foreach(src_path ${src_files})
  61. file(RELATIVE_PATH relative_src ${src_dir} ${src_path})
  62. set(dest_path "${dest_dir}/${relative_src}")
  63. add_custom_command(TARGET copy_hadoop_files
  64. COMMAND ${CMAKE_COMMAND} -E copy_if_different "${src_path}" "${dest_path}"
  65. )
  66. endforeach()
  67. endfunction()
  68. # If we're building in the hadoop tree, pull the Hadoop files that
  69. # libhdfspp depends on. This allows us to ensure that
  70. # the distribution will have a consistent set of headers and
  71. # .proto files
  72. if(HADOOP_BUILD)
  73. set(HADOOP_IMPORT_DIR ${PROJECT_BINARY_DIR}/extern)
  74. get_filename_component(HADOOP_IMPORT_DIR ${HADOOP_IMPORT_DIR} REALPATH)
  75. add_custom_target(copy_hadoop_files ALL)
  76. # Gather the Hadoop files and resources that libhdfs++ needs to build
  77. copy_on_demand(../libhdfs/include/*.h* ${HADOOP_IMPORT_DIR}/include)
  78. copy_on_demand(${CMAKE_CURRENT_LIST_DIR}/../../../../../hadoop-hdfs-client/src/main/proto/*.proto ${HADOOP_IMPORT_DIR}/proto/hdfs)
  79. copy_on_demand(${CMAKE_CURRENT_LIST_DIR}/../../../../../../hadoop-common-project/hadoop-common/src/main/proto/*.proto ${HADOOP_IMPORT_DIR}/proto/hadoop)
  80. copy_on_demand(${CMAKE_CURRENT_LIST_DIR}/../../../../../../hadoop-common-project/hadoop-common/src/test/proto/*.proto ${HADOOP_IMPORT_DIR}/proto/hadoop_test)
  81. else(HADOOP_BUILD)
  82. set(HADOOP_IMPORT_DIR ${CMAKE_CURRENT_LIST_DIR}/extern)
  83. endif(HADOOP_BUILD)
  84. # Paths to find the imported files
  85. set(PROTO_HDFS_DIR ${HADOOP_IMPORT_DIR}/proto/hdfs)
  86. set(PROTO_HADOOP_DIR ${HADOOP_IMPORT_DIR}/proto/hadoop)
  87. set(PROTO_HADOOP_TEST_DIR ${HADOOP_IMPORT_DIR}/proto/hadoop_test)
  88. include_directories(
  89. include
  90. lib
  91. ${HADOOP_IMPORT_DIR}/include
  92. )
  93. include_directories( SYSTEM
  94. ${PROJECT_BINARY_DIR}/lib/proto
  95. third_party/asio-1.10.2/include
  96. third_party/rapidxml-1.13
  97. third_party/gmock-1.7.0
  98. third_party/tr2
  99. third_party/protobuf
  100. third_party/uriparser2
  101. ${OPENSSL_INCLUDE_DIR}
  102. )
  103. add_subdirectory(third_party/gmock-1.7.0)
  104. add_subdirectory(third_party/uriparser2)
  105. add_subdirectory(lib)
  106. add_subdirectory(tests)
  107. add_subdirectory(examples)
  108. # create an empty file; hadoop_add_dual_library wraps add_library which
  109. # requires at least one file as an argument
  110. set(EMPTY_FILE_CC ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/empty.cc)
  111. file(WRITE ${EMPTY_FILE_CC} "")
  112. # Build the output libraries
  113. if(NEED_LINK_DL)
  114. set(LIB_DL dl)
  115. endif()
  116. set(LIBHDFSPP_ALL_OBJECTS $<TARGET_OBJECTS:bindings_c_obj> $<TARGET_OBJECTS:fs_obj> $<TARGET_OBJECTS:rpc_obj> $<TARGET_OBJECTS:reader_obj> $<TARGET_OBJECTS:proto_obj> $<TARGET_OBJECTS:connection_obj> $<TARGET_OBJECTS:common_obj> $<TARGET_OBJECTS:uriparser2_obj>)
  117. if (HADOOP_BUILD)
  118. hadoop_add_dual_library(hdfspp ${EMPTY_FILE_CC} ${LIBHDFSPP_ALL_OBJECTS})
  119. hadoop_target_link_dual_libraries(hdfspp
  120. ${LIB_DL}
  121. ${PROTOBUF_LIBRARY}
  122. ${OPENSSL_LIBRARIES}
  123. )
  124. else (HADOOP_BUILD)
  125. add_library(hdfspp_static STATIC ${EMPTY_FILE_CC} ${LIBHDFSPP_ALL_OBJECTS})
  126. target_link_libraries(hdfspp_static
  127. ${LIB_DL}
  128. ${PROTOBUF_LIBRARY}
  129. ${OPENSSL_LIBRARIES}
  130. )
  131. add_library(hdfspp SHARED ${EMPTY_FILE_CC} ${LIBHDFSPP_ALL_OBJECTS})
  132. target_link_libraries(hdfspp_static
  133. ${LIB_DL}
  134. ${PROTOBUF_LIBRARY}
  135. ${OPENSSL_LIBRARIES}
  136. )
  137. endif (HADOOP_BUILD)
  138. set(LIBHDFSPP_VERSION "0.1.0")
  139. set_target_properties(hdfspp PROPERTIES
  140. SOVERSION ${LIBHDFSPP_VERSION})
  141. # Set up make install targets
  142. # Can be installed to a particular location via "make DESTDIR=... install"
  143. file(GLOB_RECURSE LIBHDFSPP_HEADER_FILES "${CMAKE_CURRENT_LIST_DIR}/include/*.h*")
  144. file(GLOB_RECURSE LIBHDFS_HEADER_FILES "${HADOOP_IMPORT_DIR}/include/*.h*")
  145. install(FILES ${LIBHDFSPP_HEADER_FILES} DESTINATION /include/hdfspp)
  146. install(FILES ${LIBHDFS_HEADER_FILES} DESTINATION /include/hdfs)
  147. install(TARGETS hdfspp_static ARCHIVE DESTINATION /lib)
  148. install(TARGETS hdfspp LIBRARY DESTINATION /lib)
  149. add_custom_target(
  150. InstallToBuildDirectory
  151. COMMAND "${CMAKE_MAKE_PROGRAM}" install DESTDIR=${PROJECT_BINARY_DIR}/output
  152. )
  153. set(LIBHDFSPP_DIR ${PROJECT_BINARY_DIR}/output)