|
| 1 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +# |
| 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, |
| 13 | +# software distributed under the License is distributed on an |
| 14 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | +# KIND, either express or implied. See the License for the |
| 16 | +# specific language governing permissions and limitations |
| 17 | +# under the License. |
| 18 | +# |
| 19 | +cmake_minimum_required(VERSION 3.0) |
| 20 | +PROJECT(hbaseclient CXX) |
| 21 | +set(PROJECT_NAME "hbaseclient") |
| 22 | +set(PROJECT_VERSION_MAJOR 0) |
| 23 | +set(PROJECT_VERSION_MINOR 1 ) |
| 24 | +set(PROJECT_VERSION_PATCH 0) |
| 25 | +set(BUILD_SHARED_LIBS ON) |
| 26 | +## set our cmake module path |
| 27 | +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") |
| 28 | +## include the Protobuf generation code |
| 29 | +include(ProtobufGen) |
| 30 | +if(COMPILER_SUPPORTS_CXX14) |
| 31 | + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14") |
| 32 | +else() |
| 33 | + message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++14 support. Please use a different C++ compiler.") |
| 34 | +endif() |
| 35 | +set(CMAKE_CXX_STANDARD 14) |
| 36 | +set(CMAKE_CXX_STANDARD_REQUIRED ON) |
| 37 | +set(HBASE_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src/hbase") |
| 38 | +set(HBASE_PROTO_GEN_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src/hbase/if") |
| 39 | +set(HBASE_PROTO_GEN_INC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include/hbase/if") |
| 40 | +# Set the right openssl root path |
| 41 | +if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") |
| 42 | + set(OPENSSL_ROOT_DIR "/usr/local/opt/openssl/") |
| 43 | +else() |
| 44 | + set(OPENSSL_ROOT_DIR "/usr/lib/x86_64-linux-gnu") |
| 45 | +endif() |
| 46 | +# Include OpenSSL |
| 47 | +find_package (OpenSSL REQUIRED) |
| 48 | +if (OPENSSL_FOUND) |
| 49 | + include_directories(${OPENSSL_INCLUDE_DIR}) |
| 50 | +else () |
| 51 | + message( FATAL_ERROR "OpenSSL was not found. Please install OpenSSL" ) |
| 52 | +endif (OPENSSL_FOUND) |
| 53 | +# ensure we have required dependencies |
| 54 | +find_package(Threads) |
| 55 | +find_package(Boost REQUIRED COMPONENTS thread system filesystem) |
| 56 | +find_package(Gflags REQUIRED) |
| 57 | +find_package(Folly REQUIRED) |
| 58 | +find_package(Krb5 REQUIRED) |
| 59 | +find_package(Sasl2 REQUIRED) |
| 60 | +find_package(Wangle REQUIRED) |
| 61 | +find_package(GTest) |
| 62 | +find_package(Glog) |
| 63 | +find_package(Java REQUIRED) |
| 64 | +find_package(JNI REQUIRED) |
| 65 | +find_package(Zookeeper REQUIRED) |
| 66 | +find_package(Protobuf REQUIRED) |
| 67 | +if (NOT FOLLY_FOUND) |
| 68 | + message(FATAL_ERROR "-- Folly not found") |
| 69 | +endif() |
| 70 | +if (NOT WANGLE_FOUND) |
| 71 | + message(FATAL_ERROR "-- Wangle not found") |
| 72 | +endif() |
| 73 | +if (NOT PROTOBUF_FOUND) |
| 74 | + message(FATAL_ERROR "-- Protocol buffer include directory not found ${PROTOBUF_INCLUDE_DIRS}") |
| 75 | +endif() |
| 76 | +if (NOT JNI_FOUND) |
| 77 | + message(FATAL_ERROR "-- JAVA include directory not found") |
| 78 | +endif() |
| 79 | +### provide the include directories, starting at the base |
| 80 | +### and including those from our |
| 81 | +include_directories(include) |
| 82 | +include_directories(${PROTOBUF_INCLUDE_DIRS}) |
| 83 | +include_directories(${Zookeeper_INCLUDE_DIRS}) |
| 84 | +include_directories(${Boost_INCLUDE_DIR}) |
| 85 | +include_directories(${KRB5_INCLUDE_DIRS}) |
| 86 | +include_directories(${JAVA_INCLUDE_DIRS}) |
| 87 | +include_directories(${FOLLY_INCLUDE_DIRS}) |
| 88 | +### create a directory for the hbase protobuf headers. |
| 89 | +### this is helpful so that when we include it, later, we can generate |
| 90 | +### the protocol buffer source/headers without polluting our tree. |
| 91 | +set(CMAKE_BINARY_DIR_GEN "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/hbase/if/") |
| 92 | +file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR_GEN}) |
| 93 | +## build a recursive list of sources |
| 94 | +file(GLOB_RECURSE CONNECTION_SRC "${HBASE_SRC_DIR}/connection/*.cc" ) |
| 95 | +file(GLOB_RECURSE EXCEPTION_SRC "${HBASE_SRC_DIR}/exceptions/*.cc" ) |
| 96 | +file(GLOB_RECURSE PROTO_SRC "${HBASE_SRC_DIR}/if/*.cc" ) |
| 97 | +file(GLOB_RECURSE UTILS_SRC "${HBASE_SRC_DIR}/utils/*.cc" ) |
| 98 | +file(GLOB_RECURSE CLIENT_SRC "${HBASE_SRC_DIR}/client/*.cc" ) |
| 99 | +file(GLOB_RECURSE SECURITY_SRC "${HBASE_SRC_DIR}/security/*.cc" ) |
| 100 | +file(GLOB_RECURSE SRDE_SRC "${HBASE_SRC_DIR}/serde/*.cc" ) |
| 101 | +file(GLOB_RECURSE TEST_UTIL "${HBASE_SRC_DIR}/test-util/*.cc" ) |
| 102 | +include_directories(${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}) |
| 103 | +include_directories(${SASL_INCLUDE_DIRS}) |
| 104 | +include_directories(${GFLAGS_INCLUDE_DIR}) |
| 105 | +file(GLOB_RECURSE PROTO_FILES "${HBASE_SRC_DIR}/if/*.proto" ) |
| 106 | +### generate the protocol buffers. |
| 107 | +generate_protobuf_src(PROTO_SOURCES PROTO_HEADERS ${PROTO_FILES}) |
| 108 | + |
| 109 | + |
| 110 | +add_library(hbaseclient-static STATIC ${PROTO_SOURCES} ${CLIENT_SRC} ${CONNECTION_SRC} ${EXCEPTION_SRC} ${PROTO_SRC} ${SECURITY_SRC} ${SRDE_SRC} ${UTILS_SRC}) |
| 111 | +set_target_properties(hbaseclient-static PROPERTIES LINKER_LANGUAGE CXX) |
| 112 | +SET_TARGET_PROPERTIES(hbaseclient-static PROPERTIES OUTPUT_NAME hbaseclient CLEAN_DIRECT_OUTPUT 1) |
| 113 | +target_link_libraries(hbaseclient-static ${PROTOBUF_LIBRARY}) |
| 114 | +target_link_libraries(hbaseclient-static ${FOLLY_LIBRARIES}) |
| 115 | +target_link_libraries(hbaseclient-static ${Boost_LIBRARIES}) |
| 116 | +target_link_libraries(hbaseclient-static ${SASL_LIBS}) |
| 117 | +target_link_libraries(hbaseclient-static ${GLOG_SHARED_LIB}) |
| 118 | +target_link_libraries(hbaseclient-static ${GFLAGS_SHARED_LIB}) |
| 119 | +target_link_libraries(hbaseclient-static ${KRB5_LIBRARIES}) |
| 120 | +target_link_libraries(hbaseclient-static ${WANGLE_LIBRARIES}) |
| 121 | +target_link_libraries(hbaseclient-static ${Zookeeper_LIBRARIES}) |
| 122 | +target_link_libraries(hbaseclient-static ${OPENSSL_LIBRARIES}) |
| 123 | +add_library(hbaseclient-shared SHARED ${PROTO_SOURCES} ${CLIENT_SRC} ${CONNECTION_SRC} ${EXCEPTION_SRC} ${PROTO_SRC} ${SECURITY_SRC} ${SRDE_SRC} ${UTILS_SRC}) |
| 124 | +set_target_properties(hbaseclient-shared PROPERTIES LINKER_LANGUAGE CXX) |
| 125 | +SET_TARGET_PROPERTIES(hbaseclient-shared PROPERTIES COMPILE_FLAGS " -fPIC") |
| 126 | +SET_TARGET_PROPERTIES(hbaseclient-shared PROPERTIES OUTPUT_NAME hbaseclient CLEAN_DIRECT_OUTPUT 1) |
| 127 | +target_link_libraries(hbaseclient-shared ${PROTOBUF_LIBRARY}) |
| 128 | +target_link_libraries(hbaseclient-shared ${FOLLY_LIBRARIES}) |
| 129 | +target_link_libraries(hbaseclient-shared ${Boost_LIBRARIES}) |
| 130 | +target_link_libraries(hbaseclient-shared ${SASL_LIBS}) |
| 131 | +target_link_libraries(hbaseclient-shared ${GLOG_SHARED_LIB}) |
| 132 | +target_link_libraries(hbaseclient-shared ${GFLAGS_SHARED_LIB}) |
| 133 | +target_link_libraries(hbaseclient-shared ${KRB5_LIBRARIES}) |
| 134 | +target_link_libraries(hbaseclient-shared ${WANGLE_LIBRARIES}) |
| 135 | +target_link_libraries(hbaseclient-shared ${Zookeeper_LIBRARIES}) |
| 136 | +add_executable(simple-client "${HBASE_SRC_DIR}/examples/simple-client.cc") |
| 137 | +SET_TARGET_PROPERTIES(simple-client PROPERTIES COMPILE_FLAGS " ") |
| 138 | +target_link_libraries(simple-client ${PROTOBUF_LIBRARY}) |
| 139 | +target_link_libraries(simple-client ${Boost_LIBRARIES}) |
| 140 | +target_link_libraries(simple-client ${SASL_LIBS}) |
| 141 | +target_link_libraries(simple-client ${GFLAGS_SHARED_LIB}) |
| 142 | +target_link_libraries(simple-client ${KRB5_LIBRARIES}) |
| 143 | +target_link_libraries(simple-client ${Zookeeper_LIBRARIES}) |
| 144 | +target_link_libraries(simple-client hbaseclient-static ${CMAKE_THREAD_LIBS_INIT}) |
| 145 | +add_executable(load-client "${HBASE_SRC_DIR}/examples/load-client.cc") |
| 146 | +SET_TARGET_PROPERTIES(load-client PROPERTIES COMPILE_FLAGS " ") |
| 147 | +target_link_libraries(load-client ${PROTOBUF_LIBRARY}) |
| 148 | +target_link_libraries(load-client ${Boost_LIBRARIES}) |
| 149 | +target_link_libraries(load-client ${SASL_LIBS}) |
| 150 | +target_link_libraries(load-client ${GFLAGS_SHARED_LIB}) |
| 151 | +target_link_libraries(load-client ${KRB5_LIBRARIES}) |
| 152 | +target_link_libraries(load-client ${Zookeeper_LIBRARIES}) |
| 153 | +target_link_libraries(load-client hbaseclient-static ${CMAKE_THREAD_LIBS_INIT}) |
| 154 | +if (JNI_FOUND) |
| 155 | + message (STATUS "JNI_INCLUDE_DIRS=${JNI_INCLUDE_DIRS}") |
| 156 | + message (STATUS "JNI_LIBRARIES=${JNI_LIBRARIES}") |
| 157 | +endif() |
| 158 | +if (NOT SKIP_TESTS) |
| 159 | + include(BuildTests) |
| 160 | +endif() |
| 161 | +## Create a custom target for our linter |
| 162 | +add_custom_target( |
| 163 | + linter |
| 164 | + COMMAND ${CMAKE_SOURCE_DIR}/bin/cpplint.sh) |
| 165 | + |
| 166 | +# Install library headers |
| 167 | +include(GNUInstallDirs) |
| 168 | +file(GLOB RECURSE HEADERS include/*.h) |
| 169 | +set_target_properties(hbaseclient-static PROPERTIES PUBLIC_HEADER "${HEADERS}") |
| 170 | +install(TARGETS hbaseclient-static |
| 171 | + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 172 | + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 173 | + PUBLIC_HEADER DESTINATION include/ |
| 174 | + COMPONENT LIBRARY ) |
| 175 | +install(TARGETS hbaseclient-shared |
| 176 | + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 177 | + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 178 | + PUBLIC_HEADER DESTINATION include/ |
| 179 | + COMPONENT LIBRARY ) |
| 180 | +INSTALL ( |
| 181 | + DIRECTORY ${CMAKE_SOURCE_DIR}/include/ |
| 182 | + DESTINATION include/ |
| 183 | + FILES_MATCHING PATTERN "*.h*") |
| 184 | +# Install pb-generated headers too |
| 185 | + INSTALL ( |
| 186 | + DIRECTORY "${CMAKE_BINARY_DIR_GEN}" |
| 187 | + DESTINATION include/hbase/if |
| 188 | + FILES_MATCHING PATTERN "hbase/if/*.h") |
0 commit comments