-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HBASE-18901 [C++] Provide CMAKE infrastructure
* 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
- Loading branch information
Showing
50 changed files
with
695 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,229 @@ | ||
# 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 2.6) | ||
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) | ||
|
||
|
||
#### Establish Project Configuration #### | ||
# Enable usage of the VERSION specifier | ||
# https://cmake.org/cmake/help/v3.0/policy/CMP0048.html#policy:CMP0048 | ||
IF(POLICY CMP0048) | ||
CMAKE_POLICY(SET CMP0048 OLD) | ||
ENDIF(POLICY CMP0048) | ||
|
||
include(CheckCXXCompilerFlag) | ||
CHECK_CXX_COMPILER_FLAG("-std=c++14 " COMPILER_SUPPORTS_CXX14) | ||
#CHECK_CXX_COMPILER_FLAG("-std=c++11 " COMPILER_SUPPORTS_CXX11) | ||
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) | ||
|
||
option(Protobuf_DEBUG "protobuf debug" ON) | ||
option(protobuf_BUILD_SHARED_LIBS "build shared libs" ON) | ||
## 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 ${PROTOCOL_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) | ||
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*") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
# 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() | ||
|
||
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 ${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)...") | ||
|
||
|
Oops, something went wrong.