Add Kudu cmake utilities

This commit imports some CMake utility methods from Kudu, in preparation
for adding KRPC and its dependencies to Impala's build.

The methods are unused in this patch, but will be used both by
thirdparty dependencies (e.g. Protobuf) and by the Kudu libraries
themselves.

Some methods are stubbed out to make it easier to import Kudu's
CMakeLists.txt files without adding extra test targets etc. to Impala's
build.

Change-Id: Ibaae645d650ab1555452e4cc2574d6c84a90d941
Reviewed-on: http://gerrit.cloudera.org:8080/5656
Reviewed-by: Matthew Jacobs <[email protected]>
Tested-by: Impala Public Jenkins


Project: http://git-wip-us.apache.org/repos/asf/incubator-impala/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-impala/commit/44bb99a6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-impala/tree/44bb99a6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-impala/diff/44bb99a6

Branch: refs/heads/master
Commit: 44bb99a61d03ac52097a7d2f7928a0c5be13a7de
Parents: 70ae2e3
Author: Henry Robinson <[email protected]>
Authored: Tue Dec 13 04:20:28 2016 -0800
Committer: Impala Public Jenkins <[email protected]>
Committed: Thu Jan 12 02:53:45 2017 +0000

----------------------------------------------------------------------
 CMakeLists.txt                   |  35 +++++++++-
 cmake_modules/kudu_cmake_fns.txt | 126 ++++++++++++++++++++++++++++++++++
 2 files changed, 160 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/44bb99a6/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 661c9a6..4c5d0d3 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -15,12 +15,14 @@
 # specific language governing permissions and limitations
 # under the License.
 
-cmake_minimum_required(VERSION 2.6)
+cmake_minimum_required(VERSION 3.2.3)
 
 # Explicitly define project() to allow modifying the compiler before the 
project is
 # initialized.
 project(Impala)
 
+include(cmake_modules/kudu_cmake_fns.txt)
+
 if (NOT DEFINED BUILD_SHARED_LIBS)
   set(BUILD_SHARED_LIBS OFF)
 endif()
@@ -125,6 +127,7 @@ include_directories(${BZIP2_INCLUDE_DIR})
 
 find_package(Zlib REQUIRED)
 include_directories(${ZLIB_INCLUDE_DIR})
+message(STATUS "zlib: Static -> ${ZLIB_STATIC}, Other -> ${ZLIB_LIBRARIES}")
 
 if(NOT BUILD_SHARED_LIBS)
   # Panic if we cannot find the static libraries as they are supposed to be
@@ -267,6 +270,36 @@ set(LIBS ${LIBS} ${AVRO_STATIC_LIB})
 message(STATUS "Avro include dir: " ${AVRO_INCLUDE_DIR})
 message(STATUS "Avro static library: " ${AVRO_STATIC_LIB})
 
+###################################################################
+# These dependencies use Kudu's CMake functions
+
+ADD_THIRDPARTY_LIB(glog
+  STATIC_LIB ${GLOG_STATIC_LIB})
+ADD_THIRDPARTY_LIB(gflags
+  STATIC_LIB ${GFLAGS_STATIC_LIB})
+ADD_THIRDPARTY_LIB(zlib
+  STATIC_LIB ${ZLIB_STATIC_LIBRARIES})
+ADD_THIRDPARTY_LIB(cyrus_sasl
+  SHARED_LIB ${SASL_SHARED_LIB})
+
+if (NOT APPLE)
+  find_library(RT_LIB_PATH rt)
+  if(NOT RT_LIB_PATH)
+    message(FATAL_ERROR "Could not find librt on the system path")
+  endif()
+  ADD_THIRDPARTY_LIB(rt
+    SHARED_LIB "${RT_LIB_PATH}")
+
+  find_library(DL_LIB_PATH dl)
+  if(NOT DL_LIB_PATH)
+    message(FATAL_ERROR "Could not find libdl on the system path")
+  endif()
+  ADD_THIRDPARTY_LIB(dl
+    SHARED_LIB "${DL_LIB_PATH}")
+endif()
+
+###################################################################
+
 # KuduClient can use GLOG
 add_definitions(-DKUDU_HEADERS_USE_GLOG)
 if(NOT $ENV{KUDU_CLIENT_DIR} EQUAL "")

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/44bb99a6/cmake_modules/kudu_cmake_fns.txt
----------------------------------------------------------------------
diff --git a/cmake_modules/kudu_cmake_fns.txt b/cmake_modules/kudu_cmake_fns.txt
new file mode 100644
index 0000000..8cd2cbc
--- /dev/null
+++ b/cmake_modules/kudu_cmake_fns.txt
@@ -0,0 +1,126 @@
+# 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.
+
+# This file was adapted from 
https://github.com/apache/kudu/blob/master/CMakeLists.txt.
+# It adds two useful cmake methods (ADD_EXPORTABLE_LIBRARY and 
ADD_THIRDPARTY_LIB), and
+# also defines a shim method (ADD_KUDU_TEST) to simplify importing Kudu's 
utility
+# libraries.
+
+cmake_minimum_required(VERSION 3.2.3)
+include(CMakeParseArguments)
+
+# add_library() wrapper provided for compatibility with Kudu. In the original 
version,
+# this would add a second variant of the library, which is compiled with 
special
+# visibility flags to hide all symbols except those that are part of the 
public ABI. Here
+# it is a shim that simply calls add_library() to make the library available 
for internal
+# linking.
+#
+# Arguments:
+#
+# LIB_NAME is the name of the library. It must come first. Required.
+#
+# SRCS is the list of source files to compile into the library. Required.
+#
+# DEPS is the list of targets that both library variants depend on. Required.
+#
+# The following arguments are all optional, and supported for compatibility, 
but don't
+# have any effect:
+#
+#  NONLINK_DEPS, COMPILE_FLAGS, EXPORTED_SHARED, EXPORTED_OUTPUT_NAME,
+#  EXPORTED_OUTPUT_DIRECTORY, EXPORTED_DEPS
+function(ADD_EXPORTABLE_LIBRARY LIB_NAME)
+  set(options EXPORTED_SHARED)
+  set(one_value_args COMPILE_FLAGS EXPORTED_OUTPUT_NAME 
EXPORTED_OUTPUT_DIRECTORY)
+  set(multi_value_args SRCS DEPS EXPORTED_DEPS NONLINK_DEPS)
+  cmake_parse_arguments(ARG "${options}" "${one_value_args}" 
"${multi_value_args}" ${ARGN})
+  if(ARG_UNPARSED_ARGUMENTS)
+    message(SEND_ERROR "Error: unrecognized arguments: 
${ARG_UNPARSED_ARGUMENTS}")
+  endif()
+
+  set(LIBRARY_OUTPUT_PATH "${BUILD_OUTPUT_ROOT_DIRECTORY}/${LIB_NAME}")
+  set(EXECUTABLE_OUTPUT_PATH "${BUILD_OUTPUT_ROOT_DIRECTORY}/${LIB_NAME}")
+
+  add_library(${LIB_NAME} ${ARG_SRCS})
+  if (ARG_DEPS)
+    add_dependencies(${LIB_NAME} ${ARG_DEPS})
+  endif()
+endfunction()
+
+############################################################
+# Testing
+############################################################
+
+function(ADD_KUDU_TEST REL_TEST_NAME)
+  # Shim for compatibility, doesn't do anything.
+endfunction()
+
+
+############################################################
+# Dependencies
+############################################################
+function(ADD_THIRDPARTY_LIB LIB_NAME)
+  set(options)
+  set(one_value_args SHARED_LIB STATIC_LIB)
+  set(multi_value_args DEPS)
+  cmake_parse_arguments(ARG "${options}" "${one_value_args}" 
"${multi_value_args}" ${ARGN})
+  if(ARG_UNPARSED_ARGUMENTS)
+    message(SEND_ERROR "Error: unrecognized arguments: 
${ARG_UNPARSED_ARGUMENTS}")
+  endif()
+
+  if(("${KUDU_LINK}" STREQUAL "s" AND ARG_STATIC_LIB) OR (NOT ARG_SHARED_LIB))
+    if(NOT ARG_STATIC_LIB)
+      message(FATAL_ERROR "No static or shared library provided for 
${LIB_NAME}")
+    endif()
+    add_library(${LIB_NAME} STATIC IMPORTED)
+    set_target_properties(${LIB_NAME}
+      PROPERTIES IMPORTED_LOCATION "${ARG_STATIC_LIB}")
+    message("Added static library dependency ${LIB_NAME}: ${ARG_STATIC_LIB}")
+  else()
+    add_library(${LIB_NAME} SHARED IMPORTED)
+    set_target_properties(${LIB_NAME}
+      PROPERTIES IMPORTED_LOCATION "${ARG_SHARED_LIB}")
+    message("Added shared library dependency ${LIB_NAME}: ${ARG_SHARED_LIB}")
+  endif()
+
+  if(ARG_DEPS)
+    set_target_properties(${LIB_NAME}
+      PROPERTIES IMPORTED_LINK_INTERFACE_LIBRARIES "${ARG_DEPS}")
+  endif()
+
+  # Set up an "exported variant" for this thirdparty library (see "Visibility"
+  # above). It's the same as the real target, just with an "_exported" suffix.
+  # We prefer the static archive if it exists (as it's akin to an "internal"
+  # library), but we'll settle for the shared object if we must.
+  #
+  # A shared object exported variant will force any "leaf" library that
+  # transitively depends on it to also depend on it at runtime; this is
+  # desirable for some libraries (e.g. cyrus_sasl).
+  set(LIB_NAME_EXPORTED ${LIB_NAME}_exported)
+  if(ARG_STATIC_LIB)
+    add_library(${LIB_NAME_EXPORTED} STATIC IMPORTED)
+    set_target_properties(${LIB_NAME_EXPORTED}
+      PROPERTIES IMPORTED_LOCATION "${ARG_STATIC_LIB}")
+  else()
+    add_library(${LIB_NAME_EXPORTED} SHARED IMPORTED)
+    set_target_properties(${LIB_NAME_EXPORTED}
+      PROPERTIES IMPORTED_LOCATION "${ARG_SHARED_LIB}")
+  endif()
+  if(ARG_DEPS)
+    set_target_properties(${LIB_NAME_EXPORTED}
+      PROPERTIES IMPORTED_LINK_INTERFACE_LIBRARIES "${ARG_DEPS}")
+  endif()
+endfunction()

Reply via email to