You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by bb...@apache.org on 2018/06/26 07:10:49 UTC

mesos git commit: Allow for unbundled libevent cmake builds.

Repository: mesos
Updated Branches:
  refs/heads/master 4cdb0f376 -> 9407d5468


Allow for unbundled libevent cmake builds.

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


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

Branch: refs/heads/master
Commit: 9407d54686cf5ee632a6bd8328e1e68655824e9f
Parents: 4cdb0f3
Author: Till Toenshoff <to...@me.com>
Authored: Tue Jun 26 09:08:45 2018 +0200
Committer: Benjamin Bannier <bb...@apache.org>
Committed: Tue Jun 26 09:08:45 2018 +0200

----------------------------------------------------------------------
 3rdparty/CMakeLists.txt           | 101 +++++++++++++++++++--------------
 3rdparty/cmake/FindLIBEVENT.cmake |  51 +++++++++++++++++
 cmake/CompilationConfigure.cmake  |  22 +++++++
 docs/configuration/cmake.md       |  18 ++++++
 4 files changed, 148 insertions(+), 44 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/9407d546/3rdparty/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/3rdparty/CMakeLists.txt b/3rdparty/CMakeLists.txt
index 367df4b..1360d18 100644
--- a/3rdparty/CMakeLists.txt
+++ b/3rdparty/CMakeLists.txt
@@ -509,57 +509,70 @@ if (ENABLE_LIBEVENT)
   # libevent: An event notification library.
   # http://libevent.org/
   ##########################################
-  EXTERNAL(libevent ${LIBEVENT_VERSION} ${CMAKE_CURRENT_BINARY_DIR})
-  add_library(libevent ${LIBRARY_LINKAGE} IMPORTED)
-  add_dependencies(libevent ${LIBEVENT_TARGET})
+  if (NOT UNBUNDLED_LIBEVENT)
+    EXTERNAL(libevent ${LIBEVENT_VERSION} ${CMAKE_CURRENT_BINARY_DIR})
+    add_library(libevent ${LIBRARY_LINKAGE} IMPORTED)
+    add_dependencies(libevent ${LIBEVENT_TARGET})
 
-  set_target_properties(
-    libevent PROPERTIES
-    INTERFACE_INCLUDE_DIRECTORIES "${LIBEVENT_ROOT}/include;${LIBEVENT_ROOT}-build/include")
-
-  if (WIN32)
-    if (CMAKE_GENERATOR MATCHES "Visual Studio")
-      set_target_properties(
-        libevent PROPERTIES
-        IMPORTED_LOCATION_DEBUG ${LIBEVENT_ROOT}-build/lib/Debug/event${LIBRARY_SUFFIX}
-        IMPORTED_LOCATION_RELEASE ${LIBEVENT_ROOT}-build/lib/Release/event${LIBRARY_SUFFIX})
+    set_target_properties(
+      libevent PROPERTIES
+      INTERFACE_INCLUDE_DIRECTORIES "${LIBEVENT_ROOT}/include;${LIBEVENT_ROOT}-build/include")
+
+    if (WIN32)
+      if (CMAKE_GENERATOR MATCHES "Visual Studio")
+        set_target_properties(
+          libevent PROPERTIES
+          IMPORTED_LOCATION_DEBUG ${LIBEVENT_ROOT}-build/lib/Debug/event${LIBRARY_SUFFIX}
+          IMPORTED_LOCATION_RELEASE ${LIBEVENT_ROOT}-build/lib/Release/event${LIBRARY_SUFFIX})
+      else ()
+        set_target_properties(
+          libevent PROPERTIES
+          IMPORTED_LOCATION ${LIBEVENT_ROOT}-build/lib/event${LIBRARY_SUFFIX})
+      endif ()
     else ()
       set_target_properties(
         libevent PROPERTIES
-        IMPORTED_LOCATION ${LIBEVENT_ROOT}-build/lib/event${LIBRARY_SUFFIX})
+        IMPORTED_LOCATION ${LIBEVENT_ROOT}-build/lib/libevent${LIBRARY_SUFFIX})
     endif ()
-  else ()
-    set_target_properties(
-      libevent PROPERTIES
-      IMPORTED_LOCATION ${LIBEVENT_ROOT}-build/lib/libevent${LIBRARY_SUFFIX})
-  endif ()
-
-  set(LIBEVENT_CMAKE_FORWARD_ARGS
-    ${CMAKE_C_FORWARD_ARGS}
-    ${CMAKE_SSL_FORWARD_ARGS}
-    # NOTE: Libevent does not respect the BUILD_SHARED_LIBS global flag.
-    -DEVENT__BUILD_SHARED_LIBRARIES=${BUILD_SHARED_LIBS}
-    -DEVENT__DISABLE_OPENSSL=$<NOT:$<BOOL:${ENABLE_SSL}>>
-    -DEVENT__DISABLE_BENCHMARK=ON
-    -DEVENT__DISABLE_REGRESS=ON
-    -DEVENT__DISABLE_SAMPLES=ON
-    -DEVENT__DISABLE_TESTS=ON)
-
-  if (CMAKE_C_COMPILER_ID MATCHES GNU OR CMAKE_C_COMPILER_ID MATCHES Clang)
-    list(APPEND LIBEVENT_CMAKE_FORWARD_ARGS -DCMAKE_C_FLAGS=-fPIC)
-  endif ()
 
-  MAKE_INCLUDE_DIR(libevent)
-  GET_BYPRODUCTS(libevent)
+    set(LIBEVENT_CMAKE_FORWARD_ARGS
+      ${CMAKE_C_FORWARD_ARGS}
+      ${CMAKE_SSL_FORWARD_ARGS}
+      # NOTE: Libevent does not respect the BUILD_SHARED_LIBS global flag.
+      -DEVENT__BUILD_SHARED_LIBRARIES=${BUILD_SHARED_LIBS}
+      -DEVENT__DISABLE_OPENSSL=$<NOT:$<BOOL:${ENABLE_SSL}>>
+      -DEVENT__DISABLE_BENCHMARK=ON
+      -DEVENT__DISABLE_REGRESS=ON
+      -DEVENT__DISABLE_SAMPLES=ON
+      -DEVENT__DISABLE_TESTS=ON)
+
+    if (CMAKE_C_COMPILER_ID MATCHES GNU OR CMAKE_C_COMPILER_ID MATCHES Clang)
+      list(APPEND LIBEVENT_CMAKE_FORWARD_ARGS -DCMAKE_C_FLAGS=-fPIC)
+    endif ()
 
-  ExternalProject_Add(
-    ${LIBEVENT_TARGET}
-    PREFIX            ${LIBEVENT_CMAKE_ROOT}
-    BUILD_BYPRODUCTS  ${LIBEVENT_BYPRODUCTS}
-    CMAKE_ARGS        ${LIBEVENT_CMAKE_FORWARD_ARGS}
-    INSTALL_COMMAND   ${CMAKE_NOOP}
-    URL               ${LIBEVENT_URL}
-    URL_HASH          ${LIBEVENT_HASH})
+    MAKE_INCLUDE_DIR(libevent)
+    GET_BYPRODUCTS(libevent)
+
+    ExternalProject_Add(
+      ${LIBEVENT_TARGET}
+      PREFIX            ${LIBEVENT_CMAKE_ROOT}
+      BUILD_BYPRODUCTS  ${LIBEVENT_BYPRODUCTS}
+      CMAKE_ARGS        ${LIBEVENT_CMAKE_FORWARD_ARGS}
+      INSTALL_COMMAND   ${CMAKE_NOOP}
+      URL               ${LIBEVENT_URL}
+      URL_HASH          ${LIBEVENT_HASH})
+  else ()
+    find_package(LIBEVENT REQUIRED)
+
+    foreach (lib ${LIBEVENT_LIBS})
+      get_filename_component(LIBEVENT_LIB ${lib} NAME_WE)
+      add_library(${LIBEVENT_LIB} SHARED IMPORTED)
+      set_target_properties(${LIBEVENT_LIB} PROPERTIES
+        IMPORTED_LOCATION ${lib}
+        INTERFACE_INCLUDE_DIRECTORIES ${LIBEVENT_INCLUDE_DIR})
+      target_link_libraries(libevent INTERFACE ${LIBEVENT_LIB})
+    endforeach ()
+  endif ()
 else ()
   # libev: Full-featured high-performance event loop.
   # https://github.com/enki/libev

http://git-wip-us.apache.org/repos/asf/mesos/blob/9407d546/3rdparty/cmake/FindLIBEVENT.cmake
----------------------------------------------------------------------
diff --git a/3rdparty/cmake/FindLIBEVENT.cmake b/3rdparty/cmake/FindLIBEVENT.cmake
new file mode 100644
index 0000000..d6a1e65
--- /dev/null
+++ b/3rdparty/cmake/FindLIBEVENT.cmake
@@ -0,0 +1,51 @@
+# 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.
+
+include(FindPackageHelper)
+
+# TODO(tillt): Consider moving "_ROOT_DIR" logic into FindPackageHelper.
+if ("${LIBEVENT_ROOT_DIR}" STREQUAL "")
+  execute_process(
+    COMMAND brew --prefix libevent
+    OUTPUT_VARIABLE LIBEVENT_PREFIX
+    OUTPUT_STRIP_TRAILING_WHITESPACE)
+
+  if (NOT "${LIBEVENT_PREFIX}" STREQUAL "")
+    set(POSSIBLE_LIBEVENT_INCLUDE_DIRS ${LIBEVENT_PREFIX}/include)
+    set(POSSIBLE_LIBEVENT_LIB_DIRS ${LIBEVENT_PREFIX}/lib)
+  endif()
+
+  list(
+    APPEND POSSIBLE_LIBEVENT_INCLUDE_DIRS
+    /usr/include/libevent
+    /usr/local/include/libevent)
+
+  list(
+    APPEND POSSIBLE_LIBEVENT_LIB_DIRS
+    /usr/lib
+    /usr/local/lib)
+else()
+  set(POSSIBLE_LIBEVENT_INCLUDE_DIRS ${LIBEVENT_ROOT_DIR}/include)
+  set(POSSIBLE_LIBEVENT_LIB_DIRS ${LIBEVENT_ROOT_DIR}/lib)
+endif()
+
+set(LIBEVENT_LIBRARY_NAMES event event_pthreads)
+
+if (ENABLE_SSL)
+  list(APPEND LIBEVENT_LIBRARY_NAMES event_openssl)
+endif()
+
+FIND_PACKAGE_HELPER(LIBEVENT event.h)

http://git-wip-us.apache.org/repos/asf/mesos/blob/9407d546/cmake/CompilationConfigure.cmake
----------------------------------------------------------------------
diff --git a/cmake/CompilationConfigure.cmake b/cmake/CompilationConfigure.cmake
index 2f92acb..e2ee89a 100644
--- a/cmake/CompilationConfigure.cmake
+++ b/cmake/CompilationConfigure.cmake
@@ -84,6 +84,28 @@ option(
   "Use libevent instead of libev as the core event loop implementation."
   FALSE)
 
+if (ENABLE_LIBEVENT)
+  # TODO(tillt): Consider adding Ubuntu 17 to this check. See MESOS-7076.
+  if (NOT APPLE)
+    set(DEFAULT_UNBUNDLED_LIBEVENT FALSE)
+  else ()
+    set(DEFAULT_UNBUNDLED_LIBEVENT TRUE)
+  endif ()
+
+  option(
+    UNBUNDLED_LIBEVENT
+    "Build libprocess with an installed libevent version instead of the bundled."
+    ${DEFAULT_UNBUNDLED_LIBEVENT})
+
+  if (UNBUNDLED_LIBEVENT)
+    set(
+      LIBEVENT_ROOT_DIR
+      ""
+      CACHE STRING
+      "Specify the path to libevent, e.g. \"C:\\libevent-Win64\".")
+  endif()
+endif()
+
 option(
   ENABLE_SSL
   "Build libprocess with SSL support."

http://git-wip-us.apache.org/repos/asf/mesos/blob/9407d546/docs/configuration/cmake.md
----------------------------------------------------------------------
diff --git a/docs/configuration/cmake.md b/docs/configuration/cmake.md
index 74abe65..0cba405 100644
--- a/docs/configuration/cmake.md
+++ b/docs/configuration/cmake.md
@@ -108,6 +108,24 @@ See more information in the [CMake documentation](../cmake.md).
   </tr>
   <tr>
     <td>
+      -DUNBUNDLED_LIBEVENT=(TRUE|FALSE)
+    </td>
+    <td>
+      Build libprocess with an installed libevent version instead of the bundled.
+      [default=TRUE for macOS, FALSE otherwise]
+    </td>
+  </tr>
+  <tr>
+    <td>
+      -DLIBEVENT_ROOT_DIR=[path]
+    </td>
+    <td>
+      Specify the path to libevent, e.g. "C:\libevent-Win64".
+      [default=unspecified]
+    </td>
+  </tr>
+  <tr>
+    <td>
       -DENABLE_SSL=(TRUE|FALSE)
     </td>
     <td>