You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by jo...@apache.org on 2017/03/13 19:53:22 UTC

[3/5] mesos git commit: CMake: Refactored FindApr.cmake and FindSvn.cmake.

CMake: Refactored FindApr.cmake and FindSvn.cmake.

The logic to find APR and SVN headers/libraries are effectively the
same, except for where those headers/libraries might be found.

This commit refactors the two files into a helper that takes several
lists as arguments (lists are passed by reference in CMake) and
outputs two lists of directories.

This also removes the logic for finding `APR-util`, which is not
used in this project.

Review: https://reviews.apache.org/r/57260


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/1a4d2d91
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/1a4d2d91
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/1a4d2d91

Branch: refs/heads/master
Commit: 1a4d2d917b07fbba75b9727693af9c33f550fcca
Parents: 4d6b730
Author: Joseph Wu <jo...@apache.org>
Authored: Thu Mar 2 14:05:46 2017 -0800
Committer: Joseph Wu <jo...@apache.org>
Committed: Mon Mar 13 12:17:37 2017 -0700

----------------------------------------------------------------------
 3rdparty/stout/cmake/FindApr.cmake           | 183 +---------------------
 3rdparty/stout/cmake/FindPackageHelper.cmake | 102 ++++++++++++
 3rdparty/stout/cmake/FindSvn.cmake           | 107 ++-----------
 3 files changed, 115 insertions(+), 277 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/1a4d2d91/3rdparty/stout/cmake/FindApr.cmake
----------------------------------------------------------------------
diff --git a/3rdparty/stout/cmake/FindApr.cmake b/3rdparty/stout/cmake/FindApr.cmake
index 13156a5..10e6d14 100644
--- a/3rdparty/stout/cmake/FindApr.cmake
+++ b/3rdparty/stout/cmake/FindApr.cmake
@@ -14,50 +14,16 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-###############################################################
-# IMPORTANT NOTE: I (hausdorff) have copied a *lot* of stuff in this file from
-#                 code I found at in the Akumuli[1] project. The original version
-#                 of this file was also released under the Apache 2.0 license, and
-#                 licensed to the ASF, making it fully compatible with the Mesos
-#                 project.
-#  [1] https://github.com/akumuli/Akumuli/blob/master/cmake/FindAPR.cmake
-
-# This module helps to find the Apache Portable Runtime (APR) and APR-Util
-# packages.
-#
-# USAGE: to use this module, add the following line to your CMake project:
-#   find_package(Apr)
-#
-# To make linking to APR simple, this module defines:
-#   * APR_FOUND and APRUTIL_FOUND             (if false, linking build will fail)
-#   * APR_INCLUDE_DIR and APRUTIL_INCLUDE_DIR (defineswhere to find apr.h, etc.)
-#   * APR_LIBS and APRUTIL_LIBS     (binaries for APR and friends)
-#
-# Also defined, but not for general use are:
-#   * APR_LIB and APRUTIL_LIB         (where to find the APR library)
-
-# CONFIGURE THE APR SEARCH. Specify what we're looking for, and which directories
-# we're going to look through to find them.
-#############################################################################
-if (APR_FOUND)
-  return()
-endif (APR_FOUND)
-
-unset(APRUTIL_LIB)
-unset(APRUTIL_INCLUDE_DIR)
-unset(APR_LIB)
-unset(APR_INCLUDE_DIR)
-unset(APR_LIBS)
+include(FindPackageHelper)
 
 # NOTE: If this fails, stderr is ignored, and the output variable is empty.
-# This has no deleterious effect our path search.
+# This has no deleterious effect on our path search.
 execute_process(
   COMMAND brew --prefix apr
   OUTPUT_VARIABLE APR_PREFIX
   OUTPUT_STRIP_TRAILING_WHITESPACE)
 
 set(POSSIBLE_APR_INCLUDE_DIRS
-  ${POSSIBLE_APR_INCLUDE_DIRS}
   ${APR_PREFIX}/libexec/include/apr-1
   /usr/local/include/apr-1
   /usr/local/include/apr-1.0
@@ -66,154 +32,13 @@ set(POSSIBLE_APR_INCLUDE_DIRS
   /usr/include/apr-1.0
   )
 
-set(APR_LIB_NAMES ${APR_LIB_NAMES} apr-1)
-
 set(POSSIBLE_APR_LIB_DIRS
-  ${POSSIBLE_APR_LIB_DIRS}
   ${APR_PREFIX}/libexec/lib
   /usr/local/apr/lib
   /usr/local/lib
   /usr/lib
   )
 
-# SEARCH FOR APR LIBRARIES.
-###########################
-find_path(APR_INCLUDE_DIR apr.h ${POSSIBLE_APR_INCLUDE_DIRS})
-
-find_library(
-  APR_LIB
-  NAMES ${APR_LIB_NAMES}
-  HINTS ${POSSIBLE_APR_LIB_DIRS}
-  )
-
-# Did we find the include directory?
-string(
-  COMPARE NOTEQUAL
-  "APR_INCLUDE_DIR-NOTFOUND"
-  ${APR_INCLUDE_DIR} # Value set to APR_INCLUDE_DIR-NOTFOUND if not found.
-  APR_INCLUDE_DIR_FOUND
-  )
-
-# Did we find the library?
-string(
-  COMPARE NOTEQUAL
-  "APR_LIB-NOTFOUND"
-  ${APR_LIB} # Value set to `APR_LIB-NOTFOUND` if not found.
-  APR_LIB_FOUND
-  )
-
-# APR is considered "found" if we've both an include directory and an APR binary.
-if ("${APR_LIB_FOUND}" AND "${APR_INCLUDE_DIR_FOUND}")
-  set(APR_LIBS ${APR_LIB})
-  set(APR_FOUND 1)
-else ("${APR_LIB_FOUND}" AND "${APR_INCLUDE_DIR_FOUND}")
-  set(APR_FOUND 0)
-endif ("${APR_LIB_FOUND}" AND "${APR_INCLUDE_DIR_FOUND}")
-
-# Results.
-if (APR_FOUND)
-  if (NOT Apr_FIND_QUIETLY)
-    message(STATUS "Found APR headers: ${APR_INCLUDE_DIR}")
-    message(STATUS "Found APR library: ${APR_LIBS}")
-  endif (NOT Apr_FIND_QUIETLY)
-else (APR_FOUND)
-  if (Apr_FIND_REQUIRED)
-    message(FATAL_ERROR "Could not find APR library")
-  endif (Apr_FIND_REQUIRED)
-endif (APR_FOUND)
-
-# (Deprecated declarations.)
-set(NATIVE_APR_INCLUDE_PATH ${APR_INCLUDE_DIR} )
-get_filename_component(NATIVE_APR_LIB_PATH ${APR_LIB} PATH)
-
-# Export libraries variables.
-mark_as_advanced(
-  APR_LIB
-  APR_INCLUDE_DIR
-  )
-
-# CONFIGURE THE APR-UTIL SEARCH. Specify what we're looking for, and which
-# directories we're going to look through to find them.
-#############################################################################
-# NOTE: If this fails, stderr is ignored, and the output variable is empty.
-# This has no deleterious effect our path search.
-execute_process(
-  COMMAND brew --prefix apr-util
-  OUTPUT_VARIABLE APR_UTIL_PREFIX
-  OUTPUT_STRIP_TRAILING_WHITESPACE)
-
-set(POSSIBLE_APRUTIL_INCLUDE_DIRS
-  ${POSSIBLE_APRUTIL_INCLUDE_DIRS}
-  ${APR_UTIL_PREFIX}/libexec/include/apr-1
-  /usr/local/apr/include/apr-1
-  /usr/local/include/apr-1
-  /usr/local/include/apr-1.0
-  /usr/include/apr-1
-  /usr/include/apr-1.0
-  )
-
-set(APRUTIL_LIB_NAMES ${APRUTIL_LIB_NAMES} aprutil-1)
-
-set(POSSIBLE_APRUTIL_LIB_DIRS
-  ${POSSIBLE_APRUTIL_LIB_DIRS}
-  ${APR_UTIL_PREFIX}/libexec/lib
-  /usr/local/apr/lib
-  /usr/local/lib
-  /usr/lib
-  )
-
-# SEARCH FOR APR-UTIL LIBRARIES.
-################################
-find_path(APRUTIL_INCLUDE_DIR apu.h ${POSSIBLE_APRUTIL_INCLUDE_DIRS})
-
-find_library(
-  APRUTIL_LIB
-  NAMES ${APRUTIL_LIB_NAMES}
-  HINTS ${POSSIBLE_APRUTIL_LIB_DIRS}
-  )
-
-# Did we find the include directory?
-string(
-  COMPARE NOTEQUAL
-  "APRUTIL_INCLUDE_DIR-NOTFOUND"
-  ${APRUTIL_INCLUDE_DIR} # Value set to APR_INCLUDE_DIR-NOTFOUND if not found.
-  APRUTIL_INCLUDE_DIR_FOUND
-  )
-
-# Did we find the library?
-string(
-  COMPARE NOTEQUAL
-  "APRUTIL_LIB-NOTFOUND"
-  ${APRUTIL_LIB} # Value set to `APR_LIB-NOTFOUND` if not found.
-  APRUTIL_LIB_FOUND
-  )
-
-# APR-UTIL is "found" if we've both an include directory and an APR-UTIL binary.
-if ("${APRUTIL_LIB_FOUND}" AND "${APRUTIL_INCLUDE_DIR_FOUND}")
-  set(APRUTIL_LIBS ${APRUTIL_LIB})
-  set(APRUTIL_FOUND 1)
-else ("${APRUTIL_LIB_FOUND}" AND "${APRUTIL_INCLUDE_DIR_FOUND}")
-  set(APRUTIL_FOUND 0)
-endif ("${APRUTIL_LIB_FOUND}" AND "${APRUTIL_INCLUDE_DIR_FOUND}")
-
-# Results.
-if (APRUTIL_FOUND)
-  if (NOT Apr_FIND_QUIETLY)
-    message(STATUS "Found APRUTIL headers: ${APRUTIL_INCLUDE_DIR}")
-    message(STATUS "Found APRUTIL library: ${APRUTIL_LIBS}")
-  endif (NOT Apr_FIND_QUIETLY)
-else (APRUTIL_FOUND)
-  if (Apr_FIND_REQUIRED)
-    message(FATAL_ERROR "Could not find APRUTIL library")
-  endif (Apr_FIND_REQUIRED)
-endif (APRUTIL_FOUND)
-
-# (Deprecated declarations.)
-set(NATIVE_APRUTIL_INCLUDE_PATH ${APRUTIL_INCLUDE_DIR})
-get_filename_component(NATIVE_APRUTIL_LIB_PATH ${APRUTIL_LIB} PATH)
+set(APR_LIBRARY_NAMES apr-1)
 
-# Export libraries variables.
-mark_as_advanced(
-  APRUTIL_LIB
-  APRUTIL_INCLUDE_DIR
-  )
\ No newline at end of file
+FIND_PACKAGE_HELPER(APR apr.h)

http://git-wip-us.apache.org/repos/asf/mesos/blob/1a4d2d91/3rdparty/stout/cmake/FindPackageHelper.cmake
----------------------------------------------------------------------
diff --git a/3rdparty/stout/cmake/FindPackageHelper.cmake b/3rdparty/stout/cmake/FindPackageHelper.cmake
new file mode 100644
index 0000000..eb8bbe2
--- /dev/null
+++ b/3rdparty/stout/cmake/FindPackageHelper.cmake
@@ -0,0 +1,102 @@
+# 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_PACKAGE_HELPER is a convenience function that is intended for use
+# in conjunction with the `find_package` CMake command.  Our usage of
+# `find_package(<package>)` will search for files named `Find<package>.cmake`
+# in our configured CMake include directories and load those files as modules.
+#
+# The `Find<package>.cmake` files should call this helper function only after
+# defining a set of variables:
+#   * POSSIBLE_${PACKAGE_NAME}_INCLUDE_DIRS
+#     A list of possible locations to find the `HEADER_FILE`.
+#   * POSSIBLE_${PACKAGE_NAME}_LIB_DIRS
+#     A list of possible locations to find the libraries (below).
+#   * ${PACKAGE_NAME}_LIBRARY_NAMES
+#     A list of all the library names to search for.
+#
+# Upon returning, this function will set the following variables in
+# the caller's scope:
+#   * ${PACKAGE_NAME}_INCLUDE_DIR - Defines where to find header files.
+#   * ${PACKAGE_NAME}_LIBS        - Defines the name of library files.
+function(FIND_PACKAGE_HELPER PACKAGE_NAME HEADER_FILE)
+  # Return early if the package has already been found.
+  if (${PACKAGE_NAME}_FOUND)
+    return()
+  endif (${PACKAGE_NAME}_FOUND)
+
+  # Put the return variables in a known state (empty).
+  unset(${PACKAGE_NAME}_INCLUDE_DIR)
+  unset(${PACKAGE_NAME}_LIBS)
+
+  # Search for the header file in the possible include directories.
+  find_path(
+    ${PACKAGE_NAME}_INCLUDE_DIR
+    ${HEADER_FILE}
+    HINTS ${POSSIBLE_${PACKAGE_NAME}_INCLUDE_DIRS}
+    )
+
+  # Check if the header file was found.
+  string(
+    COMPARE NOTEQUAL
+    "${PACKAGE_NAME}_INCLUDE_DIR-NOTFOUND"
+    ${${PACKAGE_NAME}_INCLUDE_DIR}
+    ${PACKAGE_NAME}_INCLUDE_DIR_FOUND # Output variable.
+    )
+
+  # Error out if the header is not found.
+  if (NOT ${${PACKAGE_NAME}_INCLUDE_DIR_FOUND})
+    message(FATAL_ERROR "Could not find ${PACKAGE_NAME} header ${HEADER_FILE}")
+  endif (NOT ${${PACKAGE_NAME}_INCLUDE_DIR_FOUND})
+
+  # Search for all the libraries in the possible library directories.
+  foreach (LIBRARY_NAME ${${PACKAGE_NAME}_LIBRARY_NAMES})
+    # NOTE: `find_library` will set the output variable in the cache,
+    # meaning that subsequent calls to `find_library` with the same
+    # output variable give the same result. Therefore, we unset the
+    # cached variable each time before calling `find_library`.
+    unset(${PACKAGE_NAME}_LIB_PATH CACHE)
+
+    find_library(
+      ${PACKAGE_NAME}_LIB_PATH
+      NAMES ${LIBRARY_NAME}
+      PATHS ${POSSIBLE_${PACKAGE_NAME}_LIB_DIRS}
+      )
+
+    # Check if the library was found.
+    string(
+      COMPARE NOTEQUAL
+      "${PACKAGE_NAME}_LIB_PATH-NOTFOUND"
+      ${${PACKAGE_NAME}_LIB_PATH}
+      ${PACKAGE_NAME}_LIB_PATH_FOUND # Output variable.
+      )
+
+    # Error out if any of the libraries are not found.
+    if (NOT ${${PACKAGE_NAME}_LIB_PATH_FOUND})
+      message(FATAL_ERROR "Could not find ${PACKAGE_NAME} library ${LIBRARY_NAME}")
+    endif (NOT ${${PACKAGE_NAME}_LIB_PATH_FOUND})
+
+    list(APPEND ${PACKAGE_NAME}_LIBS ${${PACKAGE_NAME}_LIB_PATH})
+  endforeach (LIBRARY_NAME ${PACKAGE_NAME}_LIBRARY_NAMES)
+
+  set(${PACKAGE_NAME}_FOUND 1 PARENT_SCOPE)
+  message(STATUS "Found ${PACKAGE_NAME} library: ${${PACKAGE_NAME}_LIBS}")
+  message(STATUS "Found ${PACKAGE_NAME} header: ${${PACKAGE_NAME}_INCLUDE_DIR}")
+
+  # Export the return variables.
+  set(${PACKAGE_NAME}_LIBS ${${PACKAGE_NAME}_LIBS} PARENT_SCOPE)
+  set(${PACKAGE_NAME}_INCLUDE_DIR ${${PACKAGE_NAME}_INCLUDE_DIR} PARENT_SCOPE)
+endfunction()

http://git-wip-us.apache.org/repos/asf/mesos/blob/1a4d2d91/3rdparty/stout/cmake/FindSvn.cmake
----------------------------------------------------------------------
diff --git a/3rdparty/stout/cmake/FindSvn.cmake b/3rdparty/stout/cmake/FindSvn.cmake
index d57eed9..63aff9d 100644
--- a/3rdparty/stout/cmake/FindSvn.cmake
+++ b/3rdparty/stout/cmake/FindSvn.cmake
@@ -14,111 +14,22 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-###############################################################
-# IMPORTANT NOTE: Much of this file is taken almost-directly from the
-#                 FindApr.cmake file in this project. This file is itself taken
-#                 from an external source; see comments for details.
+include(FindPackageHelper)
 
-# This module helps to find the Subversion packages.
-#
-# USAGE: to use this module, add the following line to your CMake project:
-#   find_package(Svn)
-#
-# To make linking to Subversion simple, this module defines:
-#   * SVN_FOUND       (if false, linking build will fail)
-#   * SVN_INCLUDE_DIR (defineswhere to find svn_client.h, etc.)
-#   * SVN_LIBS   (binaries for SVN and friends)
-#
-# Also defined, but not for general use are:
-#   * SVN_LIB (where to find the APR library)
-
-# CONFIGURE OUR SEARCH. Specify what we're looking for, and which directories
-# we're going to look through to find them.
-#############################################################################
-if (SVN_FOUND)
-  return()
-endif (SVN_FOUND)
-
-unset(SVN_LIB)
-unset(SVN_INCLUDE_DIR)
-unset(SVN_LIBS)
-
-set(POSSIBLE_SVN_INCLUDE_DIRECTORIES
-  ${POSSIBLE_SVN_INCLUDE_DIRECTORIES}
-  /usr/local/include/subversion-1
+set(POSSIBLE_SVN_INCLUDE_DIRS
   /usr/include/subversion-1
+  /usr/local/include/subversion-1
   )
 
-set(SVN_LIB_NAMES
-  ${SVN_LIB_NAMES}
-  svn_delta-1
-  svn_diff-1
-  svn_subr-1
-   )
-
-
-set(POSSIBLE_SVN_LIB_DIRECTORIES
-  ${POSSIBLE_SVN_LIB_DIRECTORIES}
+set(POSSIBLE_SVN_LIB_DIRS
   /usr/lib
   /usr/local/lib
   )
 
-# SEARCH FOR SVN LIBRARIES.
-###########################
-find_path(SVN_INCLUDE_DIR svn_client.h ${POSSIBLE_SVN_INCLUDE_DIRECTORIES})
-
-# Did we find the include directory?
-string(
-  COMPARE NOTEQUAL
-  "SVN_INCLUDE_DIR-NOTFOUND"
-  ${SVN_INCLUDE_DIR} # Value set to `SVN_INCLUDE_DIR-NOTFOUND` if not found.
-  SVN_INCLUDE_DIR_FOUND
+set(SVN_LIBRARY_NAMES
+  svn_delta-1
+  svn_diff-1
+  svn_subr-1
   )
 
-foreach (LIB_NAME ${SVN_LIB_NAMES})
-  find_library(
-    ${LIB_NAME}_PATH
-    NAMES ${LIB_NAME}
-    PATHS ${POSSIBLE_SVN_LIB_DIRECTORIES}
-    )
-
-  # Did we find the library?
-  string(
-    COMPARE NOTEQUAL
-    "${LIB_NAME}_PATH-NOTFOUND"
-    ${${LIB_NAME}_PATH} # Value set to ${${LIB_NAME}_PATH}-NOTFOUND if not found.
-    ${LIB_NAME}_PATH_FOUND
-    )
-
-  if ("${${LIB_NAME}_PATH_FOUND}")
-    message(STATUS "Found SVN lib: ${${LIB_NAME}_PATH}")
-    list(APPEND SVN_LIBS ${${LIB_NAME}_PATH})
-  else ("${${LIB_NAME}_PATH_FOUND}")
-    message(FATAL_ERROR "Could not find SVN library ${${LIB_NAME}_PATH}")
-  endif ("${${LIB_NAME}_PATH_FOUND}")
-endforeach (LIB_NAME ${SVN_LIB_NAMES})
-
-list(LENGTH SVN_LIB_NAMES NUM_REQD_LIBS)
-list(LENGTH SVN_LIBS NUM_FOUND_LIBS)
-
-# Results.
-if ((NUM_FOUND_LIBS AND (NUM_REQD_LIBS EQUAL NUM_FOUND_LIBS)) AND
-    SVN_INCLUDE_DIR_FOUND)
-  if (NOT Svn_FIND_QUIETLY)
-    message(STATUS "Found SVN: ${SVN_LIBS}")
-  endif(NOT Svn_FIND_QUIETLY)
-else ((NUM_FOUND_LIBS AND (NUM_REQD_LIBS EQUAL NUM_FOUND_LIBS)) AND
-      SVN_INCLUDE_DIR_FOUND)
-  if (Svn_FIND_REQUIRED)
-    message(FATAL_ERROR "Could not find SVN library")
-  endif (Svn_FIND_REQUIRED)
-endif ((NUM_FOUND_LIBS AND (NUM_REQD_LIBS EQUAL NUM_FOUND_LIBS)) AND
-       SVN_INCLUDE_DIR_FOUND)
-
-set(SVN_FOUND 1)
-
-# Export variables.
-mark_as_advanced(
-  SVN_LIB
-  SVN_INCLUDE_DIR
-  )
+FIND_PACKAGE_HELPER(SVN svn_client.h)