CMakeLists.txt 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. endif()
  40. # Mac OS 10.7 and later deprecates most of the methods in OpenSSL.
  41. # Add -Wno-deprecated-declarations to avoid the warnings.
  42. if(APPLE)
  43. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++ -Wno-deprecated-declarations -Wno-unused-local-typedef")
  44. endif()
  45. if(DOXYGEN_FOUND)
  46. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/doc/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/doc/Doxyfile @ONLY)
  47. add_custom_target(doc ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/doc/Doxyfile
  48. WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
  49. COMMENT "Generating API documentation with Doxygen" VERBATIM)
  50. endif(DOXYGEN_FOUND)
  51. # Copy files from the hadoop tree into the output/extern directory if
  52. # they've changed
  53. function (copy_on_demand input_src_glob input_dest_dir)
  54. get_filename_component(src_glob ${input_src_glob} REALPATH)
  55. get_filename_component(dest_dir ${input_dest_dir} REALPATH)
  56. get_filename_component(src_dir ${src_glob} DIRECTORY)
  57. message(STATUS "Syncing ${src_glob} to ${dest_dir}")
  58. file(GLOB_RECURSE src_files ${src_glob})
  59. foreach(src_path ${src_files})
  60. file(RELATIVE_PATH relative_src ${src_dir} ${src_path})
  61. set(dest_path "${dest_dir}/${relative_src}")
  62. add_custom_command(TARGET copy_hadoop_files
  63. COMMAND ${CMAKE_COMMAND} -E copy_if_different "${src_path}" "${dest_path}"
  64. )
  65. endforeach()
  66. endfunction()
  67. # If we're building in the hadoop tree, pull the Hadoop files that
  68. # libhdfspp depends on. This allows us to ensure that
  69. # the distribution will have a consistent set of headers and
  70. # .proto files
  71. if(HADOOP_BUILD)
  72. set(HADOOP_IMPORT_DIR ${PROJECT_BINARY_DIR}/extern)
  73. get_filename_component(HADOOP_IMPORT_DIR ${HADOOP_IMPORT_DIR} REALPATH)
  74. add_custom_target(copy_hadoop_files ALL)
  75. # Gather the Hadoop files and resources that libhdfs++ needs to build
  76. copy_on_demand(../libhdfs/include/*.h* ${HADOOP_IMPORT_DIR}/include)
  77. copy_on_demand(${CMAKE_CURRENT_LIST_DIR}/../../../../../hadoop-hdfs-client/src/main/proto/*.proto ${HADOOP_IMPORT_DIR}/proto/hdfs)
  78. copy_on_demand(${CMAKE_CURRENT_LIST_DIR}/../../../../../../hadoop-common-project/hadoop-common/src/main/proto/*.proto ${HADOOP_IMPORT_DIR}/proto/hadoop)
  79. copy_on_demand(${CMAKE_CURRENT_LIST_DIR}/../../../../../../hadoop-common-project/hadoop-common/src/test/proto/*.proto ${HADOOP_IMPORT_DIR}/proto/hadoop_test)
  80. else(HADOOP_BUILD)
  81. set(HADOOP_IMPORT_DIR ${CMAKE_CURRENT_LIST_DIR}/extern)
  82. endif(HADOOP_BUILD)
  83. # Paths to find the imported files
  84. set(PROTO_HDFS_DIR ${HADOOP_IMPORT_DIR}/proto/hdfs)
  85. set(PROTO_HADOOP_DIR ${HADOOP_IMPORT_DIR}/proto/hadoop)
  86. set(PROTO_HADOOP_TEST_DIR ${HADOOP_IMPORT_DIR}/proto/hadoop_test)
  87. include_directories(
  88. include
  89. lib
  90. ${HADOOP_IMPORT_DIR}/include
  91. )
  92. include_directories( SYSTEM
  93. ${PROJECT_BINARY_DIR}/lib/proto
  94. third_party/asio-1.10.2/include
  95. third_party/rapidxml-1.13
  96. third_party/gmock-1.7.0
  97. third_party/tr2
  98. third_party/protobuf
  99. ${OPENSSL_INCLUDE_DIR}
  100. )
  101. add_subdirectory(third_party/gmock-1.7.0)
  102. add_subdirectory(lib)
  103. add_subdirectory(tests)
  104. # create an empty file; hadoop_add_dual_library wraps add_library which
  105. # requires at least one file as an argument
  106. set(EMPTY_FILE_CC ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/empty.cc)
  107. file(WRITE ${EMPTY_FILE_CC} "")
  108. # Build the output libraries
  109. if(NEED_LINK_DL)
  110. set(LIB_DL dl)
  111. endif()
  112. 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>)
  113. if (HADOOP_BUILD)
  114. hadoop_add_dual_library(hdfspp ${EMPTY_FILE_CC} ${LIBHDFSPP_ALL_OBJECTS})
  115. hadoop_target_link_dual_libraries(hdfspp
  116. ${LIB_DL}
  117. ${PROTOBUF_LIBRARY}
  118. ${OPENSSL_LIBRARIES}
  119. )
  120. else (HADOOP_BUILD)
  121. add_library(hdfspp_static STATIC ${EMPTY_FILE_CC} ${LIBHDFSPP_ALL_OBJECTS})
  122. target_link_libraries(hdfspp_static
  123. ${LIB_DL}
  124. ${PROTOBUF_LIBRARY}
  125. ${OPENSSL_LIBRARIES}
  126. )
  127. add_library(hdfspp SHARED ${EMPTY_FILE_CC} ${LIBHDFSPP_ALL_OBJECTS})
  128. target_link_libraries(hdfspp_static
  129. ${LIB_DL}
  130. ${PROTOBUF_LIBRARY}
  131. ${OPENSSL_LIBRARIES}
  132. )
  133. endif (HADOOP_BUILD)
  134. set(LIBHDFSPP_VERSION "0.1.0")
  135. set_target_properties(hdfspp PROPERTIES
  136. SOVERSION ${LIBHDFSPP_VERSION})
  137. # Set up make install targets
  138. # Can be installed to a particular location via "make DESTDIR=... install"
  139. file(GLOB_RECURSE LIBHDFSPP_HEADER_FILES "${CMAKE_CURRENT_LIST_DIR}/include/*.h*")
  140. file(GLOB_RECURSE LIBHDFS_HEADER_FILES "${HADOOP_IMPORT_DIR}/include/*.h*")
  141. install(FILES ${LIBHDFSPP_HEADER_FILES} DESTINATION /include/libhdfspp)
  142. install(FILES ${LIBHDFS_HEADER_FILES} DESTINATION /include/libhdfs)
  143. install(TARGETS hdfspp_static ARCHIVE DESTINATION /lib)
  144. install(TARGETS hdfspp LIBRARY DESTINATION /lib)