Skip to content

Commit

Permalink
HBASE-18901 [C++] Provide CMAKE infrastructure
Browse files Browse the repository at this point in the history
* Provided cmake files for packages in which a default module
did not exist.
* Moved tests to a location where we could automatically build
the test suite.
* Resolved minor issues with tests
* Tested across OSX, RHEL7, and Ubuntu16

HBASE-18901 [C++] Cleanup CMAKE

JJELSER: A hack to get the protobuf-gen headers installed too.

Admittedly, not sure if there is a better way to do it.

HBASE-18901 [C++] Fix PROTOBUF_LIBRARY by removing static override
in FindZookeeper

HBASE-18901 [C++] Remove white space lines and clean up CMAKE
  • Loading branch information
phrocker committed Oct 12, 2017
1 parent e2bb10a commit 5ed5927
Show file tree
Hide file tree
Showing 51 changed files with 623 additions and 9 deletions.
188 changes: 188 additions & 0 deletions hbase-native-client/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
# Licensed to the Apache Software Foundation (ASF) under one
#
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
cmake_minimum_required(VERSION 3.0)
PROJECT(hbaseclient CXX)
set(PROJECT_NAME "hbaseclient")
set(PROJECT_VERSION_MAJOR 0)
set(PROJECT_VERSION_MINOR 1 )
set(PROJECT_VERSION_PATCH 0)
set(BUILD_SHARED_LIBS ON)
## set our cmake module path
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
## include the Protobuf generation code
include(ProtobufGen)
if(COMPILER_SUPPORTS_CXX14)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
else()
message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++14 support. Please use a different C++ compiler.")
endif()
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(HBASE_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src/hbase")
set(HBASE_PROTO_GEN_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src/hbase/if")
set(HBASE_PROTO_GEN_INC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include/hbase/if")
# Set the right openssl root path
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(OPENSSL_ROOT_DIR "/usr/local/opt/openssl/")
else()
set(OPENSSL_ROOT_DIR "/usr/lib/x86_64-linux-gnu")
endif()
# Include OpenSSL
find_package (OpenSSL REQUIRED)
if (OPENSSL_FOUND)
include_directories(${OPENSSL_INCLUDE_DIR})
else ()
message( FATAL_ERROR "OpenSSL was not found. Please install OpenSSL" )
endif (OPENSSL_FOUND)
# ensure we have required dependencies
find_package(Threads)
find_package(Boost REQUIRED COMPONENTS thread system filesystem)
find_package(Gflags REQUIRED)
find_package(Folly REQUIRED)
find_package(Krb5 REQUIRED)
find_package(Sasl2 REQUIRED)
find_package(Wangle REQUIRED)
find_package(GTest)
find_package(Glog)
find_package(Java REQUIRED)
find_package(JNI REQUIRED)
find_package(Zookeeper REQUIRED)
find_package(Protobuf REQUIRED)
if (NOT FOLLY_FOUND)
message(FATAL_ERROR "-- Folly not found")
endif()
if (NOT WANGLE_FOUND)
message(FATAL_ERROR "-- Wangle not found")
endif()
if (NOT PROTOBUF_FOUND)
message(FATAL_ERROR "-- Protocol buffer include directory not found ${PROTOBUF_INCLUDE_DIRS}")
endif()
if (NOT JNI_FOUND)
message(FATAL_ERROR "-- JAVA include directory not found")
endif()
### provide the include directories, starting at the base
### and including those from our
include_directories(include)
include_directories(${PROTOBUF_INCLUDE_DIRS})
include_directories(${Zookeeper_INCLUDE_DIRS})
include_directories(${Boost_INCLUDE_DIR})
include_directories(${KRB5_INCLUDE_DIRS})
include_directories(${JAVA_INCLUDE_DIRS})
include_directories(${FOLLY_INCLUDE_DIRS})
### create a directory for the hbase protobuf headers.
### this is helpful so that when we include it, later, we can generate
### the protocol buffer source/headers without polluting our tree.
set(CMAKE_BINARY_DIR_GEN "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/hbase/if/")
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR_GEN})
## build a recursive list of sources
file(GLOB_RECURSE CONNECTION_SRC "${HBASE_SRC_DIR}/connection/*.cc" )
file(GLOB_RECURSE EXCEPTION_SRC "${HBASE_SRC_DIR}/exceptions/*.cc" )
file(GLOB_RECURSE PROTO_SRC "${HBASE_SRC_DIR}/if/*.cc" )
file(GLOB_RECURSE UTILS_SRC "${HBASE_SRC_DIR}/utils/*.cc" )
file(GLOB_RECURSE CLIENT_SRC "${HBASE_SRC_DIR}/client/*.cc" )
file(GLOB_RECURSE SECURITY_SRC "${HBASE_SRC_DIR}/security/*.cc" )
file(GLOB_RECURSE SRDE_SRC "${HBASE_SRC_DIR}/serde/*.cc" )
file(GLOB_RECURSE TEST_UTIL "${HBASE_SRC_DIR}/test-util/*.cc" )
include_directories(${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_FILES_DIRECTORY})
include_directories(${SASL_INCLUDE_DIRS})
include_directories(${GFLAGS_INCLUDE_DIR})
file(GLOB_RECURSE PROTO_FILES "${HBASE_SRC_DIR}/if/*.proto" )
### generate the protocol buffers.
generate_protobuf_src(PROTO_SOURCES PROTO_HEADERS ${PROTO_FILES})


add_library(hbaseclient-static STATIC ${PROTO_SOURCES} ${CLIENT_SRC} ${CONNECTION_SRC} ${EXCEPTION_SRC} ${PROTO_SRC} ${SECURITY_SRC} ${SRDE_SRC} ${UTILS_SRC})
set_target_properties(hbaseclient-static PROPERTIES LINKER_LANGUAGE CXX)
SET_TARGET_PROPERTIES(hbaseclient-static PROPERTIES OUTPUT_NAME hbaseclient CLEAN_DIRECT_OUTPUT 1)
target_link_libraries(hbaseclient-static ${PROTOBUF_LIBRARY})
target_link_libraries(hbaseclient-static ${FOLLY_LIBRARIES})
target_link_libraries(hbaseclient-static ${Boost_LIBRARIES})
target_link_libraries(hbaseclient-static ${SASL_LIBS})
target_link_libraries(hbaseclient-static ${GLOG_SHARED_LIB})
target_link_libraries(hbaseclient-static ${GFLAGS_SHARED_LIB})
target_link_libraries(hbaseclient-static ${KRB5_LIBRARIES})
target_link_libraries(hbaseclient-static ${WANGLE_LIBRARIES})
target_link_libraries(hbaseclient-static ${Zookeeper_LIBRARIES})
target_link_libraries(hbaseclient-static ${OPENSSL_LIBRARIES})
add_library(hbaseclient-shared SHARED ${PROTO_SOURCES} ${CLIENT_SRC} ${CONNECTION_SRC} ${EXCEPTION_SRC} ${PROTO_SRC} ${SECURITY_SRC} ${SRDE_SRC} ${UTILS_SRC})
set_target_properties(hbaseclient-shared PROPERTIES LINKER_LANGUAGE CXX)
SET_TARGET_PROPERTIES(hbaseclient-shared PROPERTIES COMPILE_FLAGS " -fPIC")
SET_TARGET_PROPERTIES(hbaseclient-shared PROPERTIES OUTPUT_NAME hbaseclient CLEAN_DIRECT_OUTPUT 1)
target_link_libraries(hbaseclient-shared ${PROTOBUF_LIBRARY})
target_link_libraries(hbaseclient-shared ${FOLLY_LIBRARIES})
target_link_libraries(hbaseclient-shared ${Boost_LIBRARIES})
target_link_libraries(hbaseclient-shared ${SASL_LIBS})
target_link_libraries(hbaseclient-shared ${GLOG_SHARED_LIB})
target_link_libraries(hbaseclient-shared ${GFLAGS_SHARED_LIB})
target_link_libraries(hbaseclient-shared ${KRB5_LIBRARIES})
target_link_libraries(hbaseclient-shared ${WANGLE_LIBRARIES})
target_link_libraries(hbaseclient-shared ${Zookeeper_LIBRARIES})
add_executable(simple-client "${HBASE_SRC_DIR}/examples/simple-client.cc")
SET_TARGET_PROPERTIES(simple-client PROPERTIES COMPILE_FLAGS " ")
target_link_libraries(simple-client ${PROTOBUF_LIBRARY})
target_link_libraries(simple-client ${Boost_LIBRARIES})
target_link_libraries(simple-client ${SASL_LIBS})
target_link_libraries(simple-client ${GFLAGS_SHARED_LIB})
target_link_libraries(simple-client ${KRB5_LIBRARIES})
target_link_libraries(simple-client ${Zookeeper_LIBRARIES})
target_link_libraries(simple-client hbaseclient-static ${CMAKE_THREAD_LIBS_INIT})
add_executable(load-client "${HBASE_SRC_DIR}/examples/load-client.cc")
SET_TARGET_PROPERTIES(load-client PROPERTIES COMPILE_FLAGS " ")
target_link_libraries(load-client ${PROTOBUF_LIBRARY})
target_link_libraries(load-client ${Boost_LIBRARIES})
target_link_libraries(load-client ${SASL_LIBS})
target_link_libraries(load-client ${GFLAGS_SHARED_LIB})
target_link_libraries(load-client ${KRB5_LIBRARIES})
target_link_libraries(load-client ${Zookeeper_LIBRARIES})
target_link_libraries(load-client hbaseclient-static ${CMAKE_THREAD_LIBS_INIT})
if (JNI_FOUND)
message (STATUS "JNI_INCLUDE_DIRS=${JNI_INCLUDE_DIRS}")
message (STATUS "JNI_LIBRARIES=${JNI_LIBRARIES}")
endif()
if (NOT SKIP_TESTS)
include(BuildTests)
endif()
## Create a custom target for our linter
add_custom_target(
linter
COMMAND ${CMAKE_SOURCE_DIR}/bin/cpplint.sh)

# Install library headers
include(GNUInstallDirs)
file(GLOB RECURSE HEADERS include/*.h)
set_target_properties(hbaseclient-static PROPERTIES PUBLIC_HEADER "${HEADERS}")
install(TARGETS hbaseclient-static
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION include/
COMPONENT LIBRARY )
install(TARGETS hbaseclient-shared
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION include/
COMPONENT LIBRARY )
INSTALL (
DIRECTORY ${CMAKE_SOURCE_DIR}/include/
DESTINATION include/
FILES_MATCHING PATTERN "*.h*")
# Install pb-generated headers too
INSTALL (
DIRECTORY "${CMAKE_BINARY_DIR_GEN}"
DESTINATION include/hbase/if
FILES_MATCHING PATTERN "hbase/if/*.h")
9 changes: 5 additions & 4 deletions hbase-native-client/bin/cpplint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.
IFS=$'\n\t'

OUTPUT_DIR=$1
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
CPPLINT_LOC=https://raw.githubusercontent.com/google/styleguide/gh-pages/cpplint/cpplint.py
OUTPUT=build/cpplint.py
OUTPUT=$OUTPUT_DIR/cpplint.py

declare -a MODULES=( client connection exceptions security serde utils test-util )

Expand All @@ -31,9 +32,9 @@ wget -nc $CPPLINT_LOC -O $OUTPUT
# build/c++11 (We are building with c++14)
for m in ${MODULES[@]}; do
if [ $m != "security" ]; then #These are empty
exec find src/hbase/$m -name "*.h" -or -name "*.cc" | xargs -P8 python $OUTPUT --filter=-build/header_guard,-readability/todo,-build/c++11 --linelength=100
exec find ${SCRIPT_DIR}/../src/hbase/$m -name "*.h" -or -name "*.cc" | xargs -P8 python $OUTPUT --filter=-build/header_guard,-readability/todo,-build/c++11 --linelength=100
fi
if [ $m != "test-util" ]; then
exec find include/hbase/$m -name "*.h" -or -name "*.cc" | xargs -P8 python $OUTPUT --filter=-build/header_guard,-readability/todo,-build/c++11 --linelength=100
exec find ${SCRIPT_DIR}/../include/hbase/$m -name "*.h" -or -name "*.cc" | xargs -P8 python $OUTPUT --filter=-build/header_guard,-readability/todo,-build/c++11 --linelength=100
fi
done
80 changes: 80 additions & 0 deletions hbase-native-client/cmake/BuildTests.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
### test functions
MACRO(GETSOURCEFILES result curdir)
FILE(GLOB children RELATIVE ${curdir} ${curdir}/*)
SET(dirlist "")
FOREACH(child ${children})
IF( "${child}" MATCHES ^[^.].*\\.cc)

LIST(APPEND dirlist ${child})
ENDIF()
ENDFOREACH()
SET(${result} ${dirlist})
ENDMACRO()
find_package(GMock REQUIRED)
add_library(testutil STATIC ${TEST_UTIL})
target_include_directories(testutil PRIVATE BEFORE "include")
target_include_directories(testutil PRIVATE BEFORE "${Java_INCLUDE_DIRS}")
target_include_directories(testutil PRIVATE BEFORE "${JNI_INCLUDE_DIRS}")
target_include_directories(testutil PRIVATE BEFORE "${Boost_INCLUDE_DIR}")
target_include_directories(testutil PRIVATE BEFORE "${GTEST_INCLUDE_DIRS}")
target_include_directories(testutil PRIVATE BEFORE${PROTOBUF_INCLUDE_DIRS})
target_include_directories(testutil PRIVATE BEFORE${Zookeeper_INCLUDE_DIRS})
target_include_directories(testutil PRIVATE BEFORE${KRB5_INCLUDE_DIRS})
target_include_directories(testutil PRIVATE BEFORE${Java_INCLUDE_DIRS})
target_include_directories(testutil PRIVATE BEFORE${FOLLY_INCLUDE_DIRS})
target_link_libraries(testutil hbaseclient-static ${CMAKE_THREAD_LIBS_INIT} ${Java_LIBRARIES} ${JNI_LIBRARIES} ${PROTOBUF_LIBRARY} ${Boost_LIBRARIES} ${GFLAGS_SHARED_LIB} ${GMOCK_SHARED_LIB} ${GTEST_BOTH_LIBRARIES} ${SASL_LIBS} ${GFLAGS_SHARED_LIB} ${KRB5_LIBRARIES} ${OPENSSL_LIBRARIES} ${Zookeeper_LIBRARIES})
function(createTests testName)
message ("-- Including Test: ${testName}")
target_include_directories(${testName} PRIVATE BEFORE "include")
target_include_directories(${testName} PRIVATE BEFORE "${Java_INCLUDE_DIRS}")
target_include_directories(${testName} PRIVATE BEFORE "${JNI_INCLUDE_DIRS}")
target_include_directories(${testName} PRIVATE BEFORE "${Boost_INCLUDE_DIR}")
target_include_directories(${testName} PRIVATE BEFORE "${GTEST_INCLUDE_DIRS}")
target_include_directories(${testName} PRIVATE BEFORE "${OPENSSL_INCLUDE_DIR}")

target_link_libraries(hbaseclient-static ${PROTOBUF_LIBRARY})
target_link_libraries(hbaseclient-static ${FOLLY_LIBRARIES})

target_link_libraries(${testName} hbaseclient-static testutil ${CMAKE_THREAD_LIBS_INIT}
${Java_LIBRARIES}
${JNI_LIBRARIES}
${PROTOBUF_LIBRARY}
${Boost_LIBRARIES}
${GFLAGS_SHARED_LIB}
${GTEST_BOTH_LIBRARIES}
${SASL_LIBS}
${GFLAGS_SHARED_LIB}
${KRB5_LIBRARIES}
${Zookeeper_LIBRARIES} ${OPENSSL_LIBRARIES}
${WANGLE_LIBRARIES}
${FOLLY_LIBRARIES}
${GLOG_SHARED_LIB})
endfunction()
enable_testing(test)
SET(TEST_DIR ${CMAKE_SOURCE_DIR}/src/test)
GETSOURCEFILES(UNIT_TESTS "${TEST_DIR}")
SET(UNIT_TEST_COUNT 0)
FOREACH(testfile ${UNIT_TESTS})
get_filename_component(testfilename "${testfile}" NAME_WE)
add_executable("${testfilename}" "${TEST_DIR}/${testfile}")
createTests("${testfilename}")
MATH(EXPR UNIT_TEST_COUNT "${UNIT_TEST_COUNT}+1")
add_test(NAME "${testfilename}" COMMAND "${testfilename}" WORKING_DIRECTORY ${TEST_DIR})
ENDFOREACH()
message("-- Finished building ${UNIT_TEST_COUNT} unit test file(s)...")
48 changes: 48 additions & 0 deletions hbase-native-client/cmake/FindFolly.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Licensed to the Apache Software Foundation (ASF) under one
#
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
find_path(FOLLY_ROOT_DIR
NAMES include/folly/AtomicHashMap.h
)
find_library(FOLLY_LIBRARIES
NAMES folly
HINTS ${FOLLY_ROOT_DIR}/lib /usr/lib/ /usr/local/lib/ /usr/lib/x86_64-linux-gnu/
)
find_library(FOLLY_BENCHMARK_LIBRARIES
NAMES follybenchmark
HINTS ${FOLLY_ROOT_DIR}/lib
)
find_path(FOLLY_INCLUDE_DIR
NAMES folly/AtomicHashMap.h
HINTS ${FOLLY_ROOT_DIR}/include
)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Folly DEFAULT_MSG
FOLLY_LIBRARIES
FOLLY_INCLUDE_DIR
)
mark_as_advanced(
FOLLY_ROOT_DIR
FOLLY_LIBRARIES
FOLLY_BENCHMARK_LIBRARIES
FOLLY_INCLUDE_DIR
)
if (FOLLY_LIBRARIES)
set(FOLLY_FOUND "true")
message("-- Folly found, ${FOLLY_LIBRARIES}")
endif(FOLLY_LIBRARIES)
23 changes: 23 additions & 0 deletions hbase-native-client/cmake/FindGMock.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
find_path(GMOCK_INCLUDE_DIR gmock/gmock.h)
# make sure we don't accidentally pick up a different version
find_library(GMOCK_SHARED_LIB gmock)
find_library(GMOCK_STATIC_LIB libgmock.a)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(GMOCK REQUIRED_VARS
GMOCK_SHARED_LIB GMOCK_STATIC_LIB GMOCK_INCLUDE_DIR)
23 changes: 23 additions & 0 deletions hbase-native-client/cmake/FindGflags.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
find_path(GFLAGS_INCLUDE_DIR gflags/gflags.h)
# make sure we don't accidentally pick up a different version
find_library(GFLAGS_SHARED_LIB gflags)
find_library(GFLAGS_STATIC_LIB libgflags.a)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(GFLAGS REQUIRED_VARS
GFLAGS_SHARED_LIB GFLAGS_STATIC_LIB GFLAGS_INCLUDE_DIR)
Loading

0 comments on commit 5ed5927

Please sign in to comment.