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 2016/11/29 00:20:41 UTC

[12/23] mesos git commit: CMake: Revised compilation configuration file.

CMake: Revised compilation configuration file.

This moves global configuration options into one place and
logically groups the various operations: by Posix, Linux, Windows,
and then "general" groups.

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


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

Branch: refs/heads/master
Commit: 1f8ebae496a9bd22cdccedf4371dc995ffc52e59
Parents: 6ad7c74
Author: Joseph Wu <jo...@mesosphere.io>
Authored: Mon Nov 28 15:32:44 2016 -0800
Committer: Joseph Wu <jo...@apache.org>
Committed: Mon Nov 28 15:40:06 2016 -0800

----------------------------------------------------------------------
 CMakeLists.txt                   |  54 +--------
 cmake/CompilationConfigure.cmake | 201 ++++++++++++++++++++++------------
 2 files changed, 136 insertions(+), 119 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/1f8ebae4/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/CMakeLists.txt b/CMakeLists.txt
index ba08260..c6b1eb6 100755
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -28,57 +28,10 @@ set(PACKAGE_VERSION
 set(MESOS_PACKAGE_VERSION ${PACKAGE_VERSION})
 set(MESOS_PACKAGE_SOVERSION 0)
 
-# MESOS BUILD CONFIGURATION OPTIONS.
-####################################
-option(_DEBUG "Set default build configuration to debug" ON)
-option(VERBOSE "Enable verbose CMake statements and compilation output" TRUE)
-option(
-  REBUNDLED
-  "Build dependencies from tar.gz files in 3rdparty folder instead of downloading"
-  TRUE
-  )
-option(
-  ENABLE_LIBEVENT
-  "Use libevent instead of default libev as the core event loop implementation"
-  FALSE
-  )
-set(CMAKE_VERBOSE_MAKEFILE ${VERBOSE})
-set(
-  3RDPARTY_DEPENDENCIES "https://github.com/3rdparty/mesos-3rdparty/raw/master"
-  CACHE STRING "Pass in a URL or filesystem path that points at a mirror of the canonical third-party dependency repository (https://github.com/3rdparty/mesos-3rdparty); this will cause Mesos to build against the third-party tarballs we find in the mirror, instead of going to the Internet or building against the rebundled tarballs in the Mesos repository.\n\nThis is especially useful for Windows builds, because building on MSVC 1900 requires newer versions of ZK, glog, and libevent, than the ones rebundled in the Mesos repository, and so in that case we normally would have to go to the Internet to get them. Using this flag, however, means we can avoid this.\nNOTE: If you use this in conjunction with the `REBUNDLED` flag, then we will only go to this repository when we would go to the Internet normally; on most Unix builds, this will mean you never go to the Internet, but on Windows, it means you will in the case of glog, ZK, and libevent. To build purely against the mirror, do not u
 se the `REBUNDLED` flag."
-  )
-
-if (REBUNDLED AND ENABLE_LIBEVENT)
-  message(
-    WARNING
-    "Both `ENABLE_LIBEVENT` and `REBUNDLED` (set to TRUE by default) flags "
-    "have been set. But, libevent does not come rebundled in Mesos, so it must "
-    "be downloaded."
-    )
-endif (REBUNDLED AND ENABLE_LIBEVENT)
-
-if (WIN32 AND REBUNDLED)
-  message(
-    WARNING
-    "The current supported version of ZK does not compile on Windows, and does "
-    "not come rebundled in the Mesos repository. It must be downloaded from "
-    "the Internet, even though the `REBUNDLED` flag was set."
-    )
-endif (WIN32 AND REBUNDLED)
-
-if (WIN32 AND (NOT ENABLE_LIBEVENT))
-  message(
-    FATAL_ERROR
-    "Windows builds of Mesos currently do not support libev, the default event "
-    "loop used by Mesos. To opt into using libevent, pass "
-    "`-DENABLE_LIBEVENT=1` as an argument when you run CMake. NOTE: although "
-    "the plan is to eventually transition to libevent, it is still in "
-    "experimental support, and the code path is much less well-exercised."
-    )
-endif (WIN32 AND (NOT ENABLE_LIBEVENT))
 
 # CMAKE MODULE SETUP.
 #####################
+# Paths that are searched when `include(...)` is called.
 list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
 list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/3rdparty/cmake)
 list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/3rdparty/libprocess/cmake)
@@ -102,12 +55,15 @@ include(VsBuildCommand)
 # Configuration.
 include(MesosConfigure)
 
+
 # SUBDIRECTORIES.
 #################
 add_subdirectory(3rdparty)
-
 add_subdirectory(src)
 
+
+# TESTS.
+########
 add_custom_target(
   check ${STOUT_TESTS_TARGET}
   COMMAND ${PROCESS_TESTS_TARGET}

http://git-wip-us.apache.org/repos/asf/mesos/blob/1f8ebae4/cmake/CompilationConfigure.cmake
----------------------------------------------------------------------
diff --git a/cmake/CompilationConfigure.cmake b/cmake/CompilationConfigure.cmake
index 11a8507..69d27ca 100644
--- a/cmake/CompilationConfigure.cmake
+++ b/cmake/CompilationConfigure.cmake
@@ -14,12 +14,67 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-# CONFIGURE COMPILATION.
-########################
-option(BUILD_SHARED_LIBS "Build shared libraries (DLLs)." FALSE)
+# GENERAL OPTIONS.
+##################
+option(VERBOSE "Enable verbose CMake statements and compilation output" ON)
+set(CMAKE_VERBOSE_MAKEFILE ${VERBOSE})
 
-string(COMPARE EQUAL ${CMAKE_SYSTEM_NAME} "Linux" LINUX)
+option(ENABLE_DEBUG "Set default build configuration to debug" ON)
+if (ENABLE_DEBUG)
+  set(CMAKE_BUILD_TYPE Debug)
+endif (ENABLE_DEBUG)
+
+option(BUILD_SHARED_LIBS "Build shared libraries." OFF)
+
+
+# 3RDPARTY OPTIONS.
+###################
+option(
+  REBUNDLED
+  "Use dependencies from the 3rdparty folder (instead of internet)"
+  TRUE)
+
+option(
+  ENABLE_LIBEVENT
+  "Use libevent instead of libev as the core event loop implementation"
+  FALSE)
+
+# If 'REBUNDLED' is set to FALSE, this will cause Mesos to build against
+# the specified dependency repository.  This is especially useful for
+# Windows builds, because building on MSVC 1900 requires newer versions
+# of ZK, glog, and libevent, than the ones bundled in the Mesos repository.
+set(
+  3RDPARTY_DEPENDENCIES "https://github.com/3rdparty/mesos-3rdparty/raw/master"
+  CACHE STRING
+    "URL or filesystem path with a fork of the canonical 3rdparty repository")
+
+if (REBUNDLED AND ENABLE_LIBEVENT)
+  message(
+    WARNING
+    "Both `ENABLE_LIBEVENT` and `REBUNDLED` (set to TRUE by default) flags "
+    "have been set.  Libevent does not come rebundled in Mesos, so it will "
+    "be downloaded.")
+endif (REBUNDLED AND ENABLE_LIBEVENT)
 
+if (WIN32 AND REBUNDLED)
+  message(
+    WARNING
+    "The current supported version of ZK does not compile on Windows, and does "
+    "not come rebundled in the Mesos repository.  It will be downloaded from "
+    "the Internet, even though the `REBUNDLED` flag was set.")
+endif (WIN32 AND REBUNDLED)
+
+if (WIN32 AND (NOT ENABLE_LIBEVENT))
+  message(
+    FATAL_ERROR
+    "Windows builds of Mesos currently do not support libev, the default event "
+    "loop used by Mesos.  To opt into using libevent, pass "
+    "`-DENABLE_LIBEVENT=1` as an argument when you run CMake.")
+endif (WIN32 AND (NOT ENABLE_LIBEVENT))
+
+
+# SYSTEM CHECKS.
+################
 # Check that we are targeting a 64-bit architecture.
 if (NOT (CMAKE_SIZEOF_VOID_P EQUAL 8))
   message(
@@ -34,27 +89,19 @@ if (NOT (CMAKE_SIZEOF_VOID_P EQUAL 8))
     "    `cmake -DCMAKE_OSX_ARCHITECTURES=x86_64`.\n")
 endif (NOT (CMAKE_SIZEOF_VOID_P EQUAL 8))
 
-if (_DEBUG)
-  set(CMAKE_BUILD_TYPE Debug)
-endif (_DEBUG)
-
-# Make sure C++ 11 features we need are supported. This is split into two
-# cases: Windows and "other platforms".
+# Make sure C++ 11 features we need are supported.
+# This is split into two cases: Windows and "other platforms".
 #   * For "other platforms", we simply check if the C++11 flags work
-#   * For Windows, it looks like (1) C++11 is enabled by default on MSVC 1900 or
-#     later, and (2) C++11 is totally broken for 1800 or earlier (i.e., Mesos
-#     will not compile on MSVC pre-1900). So, when in Windows, we just check the
-#     MSVC version, and don't try to check or pass in C++11 flags at all.
+#   * For Windows, C++11 is enabled by default on MSVC 1900.
+#     We just check the MSVC version.
 CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
 if (WIN32)
-  # Windows case first.
-
   # We don't support compilation against mingw headers (which, e.g., Clang on
   # Windows does at this point), because this is likely to cost us more effort
   # to support than it will be worth at least in the short term.
   if (NOT CMAKE_CXX_COMPILER_ID MATCHES MSVC)
     message(
-      WARNING
+      FATAL_ERROR
       "Mesos does not support compiling on Windows with "
       "${CMAKE_CXX_COMPILER_ID}. Please use MSVC.")
   endif (NOT CMAKE_CXX_COMPILER_ID MATCHES MSVC)
@@ -63,62 +110,87 @@ if (WIN32)
   # use anything else.
   if (${MSVC_VERSION} LESS 1900)
     message(
-      WARNING
+      FATAL_ERROR
       "Mesos does not support compiling on MSVC versions earlier than 1900. "
       "Please use MSVC 1900 (included with Visual Studio 2015 or later).")
   endif (${MSVC_VERSION} LESS 1900)
+endif (WIN32)
+
+
+# POSIX CONFIGURATION.
+######################
+if (NOT WIN32)
+  if (NOT COMPILER_SUPPORTS_CXX11)
+    message(
+      FATAL_ERROR
+      "The compiler ${CMAKE_CXX_COMPILER} does not support the `-std=c++11` "
+      "flag. Please use a different C++ compiler.")
+  endif (NOT COMPILER_SUPPORTS_CXX11)
+
+  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
+
+  # Directory structure for some build artifacts.
+  # This is defined for use in tests.
+  set(EXEC_INSTALL_PREFIX  ${CMAKE_INSTALL_PREFIX})
+  set(SHARE_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX}/share)
+  set(DATA_INSTALL_PREFIX  ${SHARE_INSTALL_PREFIX}/mesos)
+
+  set(LIBEXEC_INSTALL_DIR     ${EXEC_INSTALL_PREFIX}/libexec)
+  set(PKG_LIBEXEC_INSTALL_DIR ${LIBEXEC_INSTALL_DIR}/mesos)
+  set(LIB_INSTALL_DIR         ${EXEC_INSTALL_PREFIX}/libmesos)
+
+  # TODO(hausdorff): Remove our hard dependency on SASL, as some platforms
+  # (namely Windows) will not support it in the forseeable future. As a
+  # stop-gap, we conditionally compile the code in libmesos that depends on
+  # SASL, by always setting `HAS_AUTHENTICATION` on non-Windows platforms, and
+  # never setting it on Windows platforms. This means that non-Windows builds
+  # of libmesos will still take a hard dependency on SASL, while Windows builds
+  # won't. Currently, the dependency is still assumed throughout the tests,
+  # though the plan is to remove this hard dependency as well. See MESOS-5450.
+  add_definitions(-DHAS_AUTHENTICATION=1)
+endif (NOT WIN32)
 
+
+# LINUX CONFIGURATION.
+######################
+string(COMPARE EQUAL ${CMAKE_SYSTEM_NAME} "Linux" LINUX)
+
+
+# WINDOWS CONFIGURATION.
+########################
+if (WIN32)
   # COFF/PE and friends are somewhat limited in the number of sections they
   # allow for an object file. We use this to avoid those problems.
-  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj -DGOOGLE_GLOG_DLL_DECL= -DCURL_STATICLIB /vd2 /MP")
+  set(CMAKE_CXX_FLAGS
+    "${CMAKE_CXX_FLAGS} /bigobj -DGOOGLE_GLOG_DLL_DECL= -DCURL_STATICLIB /vd2")
+
+  # Enable multi-threaded compilation.
+  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
 
+  # Build against the multi-threaded, static version of the runtime library.
   set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")
   set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
-elseif (COMPILER_SUPPORTS_CXX11)
-  # Finally, on non-Windows platforms, we must check that the current compiler
-  # supports C++11.
-  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
-else (WIN32)
-  message(
-    FATAL_ERROR
-    "The compiler ${CMAKE_CXX_COMPILER} does not support the `-std=c++11` "
-    "flag. Please use a different C++ compiler.")
-endif (WIN32)
 
-# Convenience flags to simplify Windows support in C++ source, used to #ifdef
-# out some platform-specific parts of Mesos. We choose to define a new flag
-# rather than using an existing flag (e.g., `_WIN32`) because we want to give
-# the build system fine-grained control over what code is #ifdef'd out in  the
-# future. Using only flags defined by our build system to control this logic is
-# the clearest and most stable way of accomplishing this.
-if (WIN32)
+  # Convenience flags to simplify Windows support in C++ source; used to
+  # `#ifdef` out some platform-specific parts of Mesos.  We choose to define
+  # a new flag rather than using an existing flag (`_WIN32`) because we want
+  # to give the build system fine-grained control over what code is #ifdef'd
+  # out in the future.  Using only flags defined by our build system to control
+  # this logic is the clearest and most stable way of accomplishing this.
   add_definitions(-D__WINDOWS__)
   add_definitions(-DHAVE_LIBZ)
-endif (WIN32)
 
-# Defines to disable warnings generated by Visual Studio when using
-# deprecated functions in CRT and the use of insecure functions in CRT.
-# TODO(dpravat): Once the entire codebase is changed to use secure CRT
-# functions, these defines should be removed.
-if (WIN32)
+  # Defines to disable warnings generated by Visual Studio when using
+  # deprecated functions in CRT and the use of insecure functions in CRT.
+  # TODO(dpravat): Once the entire codebase is changed to use secure CRT
+  # functions, these defines should be removed.
   add_definitions(-D_SCL_SECURE_NO_WARNINGS)
   add_definitions(-D_CRT_SECURE_NO_WARNINGS)
   add_definitions(-D_CRT_NONSTDC_NO_WARNINGS)
-endif (WIN32)
 
-# Configure directory structure for different platforms.
-########################################################
-if (NOT WIN32)
-  set(EXEC_INSTALL_PREFIX  ${CMAKE_INSTALL_PREFIX})
-  set(SHARE_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX}/share)
-  set(DATA_INSTALL_PREFIX  ${SHARE_INSTALL_PREFIX}/mesos)
-
-  set(LIBEXEC_INSTALL_DIR     ${EXEC_INSTALL_PREFIX}/libexec)
-  set(PKG_LIBEXEC_INSTALL_DIR ${LIBEXEC_INSTALL_DIR}/mesos)
-  set(LIB_INSTALL_DIR         ${EXEC_INSTALL_PREFIX}/libmesos)
-else (NOT WIN32)
-  # TODO(hausdorff): (MESOS-5455) These are placeholder values. Transition away
-  # from them.
+  # Directory structure definitions.
+  # TODO(hausdorff): (MESOS-5455) These are placeholder values.
+  # Transition away from them.
   set(EXEC_INSTALL_PREFIX     "WARNINGDONOTUSEME")
   set(LIBEXEC_INSTALL_DIR     "WARNINGDONOTUSEME")
   set(PKG_LIBEXEC_INSTALL_DIR "WARNINGDONOTUSEME")
@@ -126,11 +198,7 @@ else (NOT WIN32)
   set(TEST_LIB_EXEC_DIR       "WARNINGDONOTUSEME")
   set(PKG_MODULE_DIR          "WARNINGDONOTUSEME")
   set(S_BIN_DIR               "WARNINGDONOTUSEME")
-endif (NOT WIN32)
 
-# Add preprocessor definitions required to build third-party libraries.
-#######################################################################
-if (WIN32)
   # Windows-specific workaround for a glog issue documented here[1].
   # Basically, Windows.h and glog/logging.h both define ERROR. Since we don't
   # need the Windows ERROR, we can use this flag to avoid defining it at all.
@@ -142,20 +210,13 @@ if (WIN32)
   # [2] https://code.google.com/p/google-glog/source/browse/trunk/src/windows/glog/logging.h?r=113
   add_definitions(-DNOGDI)
   add_definitions(-DNOMINMAX)
-else (WIN32)
-  # TODO(hausdorff): Remove our hard dependency on SASL, as some platforms
-  # (namely Windows) will not support it in the forseeable future. As a
-  # stop-gap, we conditionally compile the code in libmesos that depends on
-  # SASL, by always setting `HAS_AUTHENTICATION` on non-Windows platforms, and
-  # never setting it on Windows platforms. This means that non-Windows builds
-  # of libmesos will still take a hard dependency on SASL, while Windows builds
-  # won't. Currently, the dependency is still assumed throughout the tests,
-  # though the plan is to remove this hard dependency as well. See MESOS-5450.
-  add_definitions(-DHAS_AUTHENTICATION=1)
 endif (WIN32)
 
+# GLOBAL CONFIGURATION.
+#######################
 # Enable the INT64 support for PicoJSON.
 add_definitions(-DPICOJSON_USE_INT64)
+
 # NOTE: PicoJson requires __STDC_FORMAT_MACROS to be defined before importing
 # 'inttypes.h'.  Since other libraries may also import this header, it must
 # be globally defined so that PicoJson has access to the macros, regardless