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/10/11 19:28:46 UTC
[3/3] mesos git commit: Added CMake documentation.
Added CMake documentation.
This adds a CMake documentation file with best practices, CMake By
Example, and consolidates, fixes, and updates the CMake configuration
options to the configuration documentation.
Review: https://reviews.apache.org/r/62732/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/5824eaf3
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/5824eaf3
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/5824eaf3
Branch: refs/heads/master
Commit: 5824eaf3fac3473095908ecdb6da4670654e6308
Parents: f1ecdd0
Author: Andrew Schwartzmeyer <an...@schwartzmeyer.com>
Authored: Wed Oct 11 10:09:43 2017 -0700
Committer: Joseph Wu <jo...@apache.org>
Committed: Wed Oct 11 12:27:24 2017 -0700
----------------------------------------------------------------------
docs/cmake-examples.md | 404 +++++++++++++++++++++++++++++++++++++++
docs/cmake.md | 383 +++++++++++++++++++++++++++++++++++++
docs/configuration-cmake.md | 108 -----------
docs/configuration.md | 174 +++++++++++++++--
docs/home.md | 1 +
5 files changed, 951 insertions(+), 119 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/5824eaf3/docs/cmake-examples.md
----------------------------------------------------------------------
diff --git a/docs/cmake-examples.md b/docs/cmake-examples.md
new file mode 100644
index 0000000..fe2cfab
--- /dev/null
+++ b/docs/cmake-examples.md
@@ -0,0 +1,404 @@
+---
+title: Apache Mesos - CMake By Example
+layout: documentation
+---
+
+# Adding a new library or executable
+
+When adding a new library or executable, prefer using the name directly as the
+target. E.g. `libprocess` is `add_library(process)`, and `mesos-agent` is
+`add_executable(mesos-agent)`. Note that, on platforms where it is conventional,
+`add_library` will prepend `lib` when writing the library to disk.
+
+Do not introduce a variable simply to hold the name of the target; if the name
+on disk needs to be a specific value, set the target property `OUTPUT_NAME`.
+
+# Adding a third-party dependency
+
+When adding a third-party dependency, keep the principle of locality in mind.
+All necessary data for building with and linking to the library should
+be defined where the library is imported. A consumer of the dependency should
+only have to add `target_link_libraries(consumer dependency)`, with every other
+build property coming from the graph (library location, include directories,
+compiler definitions, etc.).
+
+The steps to add a new third-party dependency are:
+
+ 1. Add the version and SHA256 hash to `Versions.cmake`.
+ 2. Add the URL/tarball file to the top of `3rdparty/CMakeLists.txt`.
+ 3. Find an appropriate location in `3rdparty/CMakeLists.txt` to declare the
+ library. Add a nice header with the name, description, and home page.
+ 4. Use `add_library(IMPORTED)` to declare an imported target.
+ A header-only library is imported with `add_library(INTERFACE)`.
+ 5. Use [`ExternalProject_Add`][] to obtain, configure, and build the library.
+ 6. Link the consumer to the dependency.
+
+[`ExternalProject_Add`]: https://cmake.org/cmake/help/latest/module/ExternalProject.html
+
+## `INTERFACE` libraries
+
+Using header-only libraries in CMake is a breeze. The special `INTERFACE`
+library lets you declare a header-only library as a proper CMake target, and
+then use it like any other library. Let's look at Boost for an example.
+
+First, we add two lines to `Versions.cmake`:
+
+```
+set(BOOST_VERSION "1.53.0")
+set(BOOST_HASH "SHA256=CED7CE2ED8D7D34815AC9DB1D18D28FCD386FFBB3DE6DA45303E1CF193717038")
+```
+
+This lets us keep the versions (and the SHA256 hash of the tarball) of all our
+third-party dependencies in one location.
+
+Second, we add one line to the top of `3rdparty/CMakeLists.txt` to declare the
+location of the tarball:
+
+```
+set(BOOST_URL ${FETCH_URL}/boost-${BOOST_VERSION}.tar.gz)
+```
+
+The `FETCH_URL` variable lets the `REBUNDLED` option switch between offline and
+online versions. The use of `BOOST_VERSION` shows why this variable is declared
+early; it's used a few times.
+
+Third, we find a location in `3rdparty/CMakeLists.txt` to declare the Boost
+library.
+
+```
+# Boost: C++ Libraries.
+# http://www.boost.org
+#######################
+...
+```
+
+We start with a proper header naming and describing the library, complete with
+its home page URL. This is for other developers to easily identify why this
+third-party dependency exists.
+
+```
+...
+EXTERNAL(boost ${BOOST_VERSION} ${CMAKE_CURRENT_BINARY_DIR})
+add_library(boost INTERFACE)
+add_dependencies(boost ${BOOST_TARGET})
+target_include_directories(boost SYSTEM INTERFACE ${BOOST_ROOT})
+...
+```
+
+Fourth, we declare the Boost target.
+
+To make things easier, we invoke our custom CMake function `EXTERNAL` to setup
+some variables for us: `BOOST_TARGET`, `BOOST_ROOT`, and `BOOST_CMAKE_ROOT`. See
+[the docs](cmake.md#EXTERNAL) for more explanation of `EXTERNAL`.
+
+Then we call `add_library(boost INTERFACE)`. This creates a header-only CMake
+target, usable like any other library. We use `add_dependencies(boost
+${BOOST_TARGET})` to add a manual dependency on the `ExternalProject_Add` step;
+this is necessary as CMake is lazy and won't execute code unless it must (say,
+because of a dependency). The final part of creating this header-only library in
+our build system is `target_include_directories(boost SYSTEM INTERFACE
+${BOOST_ROOT})`, which sets the `BOOST_ROOT` folder (the destination of the
+extracted headers) as the include interface for the `boost` target. All
+dependencies on Boost will now automatically include this folder during
+compilation.
+
+Fifth, we setup the `ExternalProject_Add` step. This CMake module is incredibly
+flexible, but we're using it in the simplest case.
+
+```
+...
+ExternalProject_Add(
+ ${BOOST_TARGET}
+ PREFIX ${BOOST_CMAKE_ROOT}
+ CONFIGURE_COMMAND ${CMAKE_NOOP}
+ BUILD_COMMAND ${CMAKE_NOOP}
+ INSTALL_COMMAND ${CMAKE_NOOP}
+ URL ${BOOST_URL}
+ URL_HASH ${BOOST_HASH})
+```
+
+The name of the custom target this creates is `BOOST_TARGET`, and the prefix
+directory for all the subsequent steps is `BOOST_CMAKE_ROOT`. Because this is a
+header-only library, and `ExternalProject_Add` defaults to invoking `cmake`, we
+use `CMAKE_NOOP` to disable the configure, build, and install commands. See [the
+docs](cmake.md#cmake_noop) for more explanation of `CMAKE_NOOP`. Thus this code
+will simply verify the tarball with `BOOST_HASH`, and then extract it from
+`BOOST_URL` to `BOOST_ROOT` (a sub-folder of `BOOST_CMAKE_ROOT`).
+
+Sixth, and finally, we link `stout` to `boost`. This is the _only_ change
+necessary to `3rdparty/stout/CMakeLists.txt`, as the include directory
+information is embedded in the CMake graph.
+
+```
+target_link_libraries(
+ stout INTERFACE
+ ...
+ boost
+ ...)
+```
+
+This dependency need not be specified again, as `libprocess` and `libmesos` link
+to `stout`, and so `boost` is picked up transitively.
+
+### Stout
+
+Stout is a header-only library. Like Boost, it is a real CMake target, declared
+in `3rdparty/stout/CMakeLists.txt`, just without the external bits.
+
+```
+add_library(stout INTERFACE)
+target_include_directories(stout INTERFACE include)
+target_link_libraries(
+ stout INTERFACE
+ apr
+ boost
+ curl
+ elfio
+ glog
+ ...)
+```
+
+It is added as an `INTERFACE` library. Its include directory is specified as an
+`INTERFACE` (the `PUBLIC` property cannot be used as the library itself is just
+an interface). Its "link" dependencies (despite not being a real, linkable
+library) are specified as an `INTERFACE`.
+
+This notion of an interface in the CMake dependency graph is what makes the
+build system reasonable. The Mesos library and executables, and `libprocess`, do
+not have to repeat these lower level dependencies that come from `stout`.
+
+## `IMPORTED` libraries
+
+Third-party dependencies that we build are only more complicated because we have
+to encode their build steps too. We'll examine `glog`, and go over the
+differences from the interface library `boost`.
+
+Notably, when we declare the library, we use:
+
+```
+add_library(glog ${LIBRARY_LINKAGE} IMPORTED GLOBAL)
+```
+
+Instead of `INTERFACE` we specify `IMPORTED` as it is an actual library. We add
+`GLOBAL` to enable our pre-compiled header module `cotire` to find the targets
+(as they would otherwise be scoped only to `3rdparty` and below). And most
+oddly, we use `${LIBRARY_LINKAGE}` to set it as `SHARED` or `STATIC` based on
+`BUILD_SHARED_LIBS`, as we can build this dependency in both manners. See [the
+docs](cmake.md#library_linkage) for more information.
+
+We must patch our bundled version of `glog` so we call:
+
+```
+PATCH_CMD(GLOG_PATCH_CMD glog-${GLOG_VERSION}.patch)
+```
+
+This generates a patch command. See [the docs](cmake.md#patch_cmd) for more
+information.
+
+This library is an example of where we differ on Windows and other platforms. On
+Windows, we build `glog` with CMake, and have several properties we must set:
+
+```
+set_target_properties(
+ glog PROPERTIES
+ IMPORTED_LOCATION_DEBUG ${GLOG_ROOT}-build/Debug/glog${LIBRARY_SUFFIX}
+ IMPORTED_LOCATION_RELEASE ${GLOG_ROOT}-build/Release/glog${LIBRARY_SUFFIX}
+ IMPORTED_IMPLIB_DEBUG ${GLOG_ROOT}-build/Debug/glog${CMAKE_IMPORT_LIBRARY_SUFFIX}
+ IMPORTED_IMPLIB_RELEASE ${GLOG_ROOT}-build/Release/glog${CMAKE_IMPORT_LIBRARY_SUFFIX}
+ INTERFACE_INCLUDE_DIRECTORIES ${GLOG_ROOT}/src/windows
+ # TODO(andschwa): Remove this when glog is updated.
+ IMPORTED_LINK_INTERFACE_LIBRARIES DbgHelp
+ INTERFACE_COMPILE_DEFINITIONS "${GLOG_COMPILE_DEFINITIONS}")
+```
+
+The location of an imported library _must_ be set for the build system to link
+to it. There is no notion of search through link directories for imported
+libraries.
+
+Windows requires both the `DEBUG` and `RELEASE` locations of the library
+specified, and since we have (experimental) support to build `glog` as a shared
+library on Windows, we also have to declare the `IMPLIB` location. Fortunately,
+these locations are programmatic based of `GLOG_ROOT`, set from our call to
+`EXTERNAL`.
+
+Note that we cannot use `target_include_directories` with an imported target. We
+have to set `INTERFACE_INCLUDE_DIRECTORIES` manually instead.
+
+This version of `glog` on Windows depends on `DbgHelp` but does not use a
+`#pragma` to include it, so we set it as an interface library that must also be
+linked, using the `IMPORTED_LINK_INTERFACE_LIBRARIES` property.
+
+For Windows there are multiple compile definitions that must be set when
+building with the `glog` headers, these are specified with the
+`INTERFACE_COMPILE_DEFINITIONS` property.
+
+For non-Windows platforms, we just set the Autotools commands to configure,
+make, and install `glog`. These commands depend on the project requirements. We
+also set the `IMPORTED_LOCATION` and `INTERFACE_INCLUDE_DIRECTORIES`.
+
+```
+set(GLOG_CONFIG_CMD ${GLOG_ROOT}/src/../configure --with-pic GTEST_CONFIG=no --prefix=${GLOG_ROOT}-build)
+set(GLOG_BUILD_CMD make)
+set(GLOG_INSTALL_CMD make install)
+
+set_target_properties(
+ glog PROPERTIES
+ IMPORTED_LOCATION ${GLOG_ROOT}-build/lib/libglog${LIBRARY_SUFFIX}
+ INTERFACE_INCLUDE_DIRECTORIES ${GLOG_ROOT}-build/include)
+```
+
+To work around some issues, we have to call `MAKE_INCLUDE_DIR(glog)` to create
+the include directory immediately so as to satisfy CMake's requirement that it
+exists (it will be populated by `ExternalProject_Add` during the build, but must
+exist first). See [the docs](cmake.md#make_include_dir) for more information.
+
+Then call `GET_BYPRODUCTS(glog)` to create the `GLOG_BYPRODUCTS` variable, which
+is sent to `ExternalProject_Add` to make the Ninja build generator happy. See
+[the docs](cmake.md#get_byproducts) for more information.
+
+```
+MAKE_INCLUDE_DIR(glog)
+GET_BYPRODUCTS(glog)
+```
+
+Like with Boost, we call `ExternalProject_Add`:
+
+```
+ExternalProject_Add(
+ ${GLOG_TARGET}
+ PREFIX ${GLOG_CMAKE_ROOT}
+ BUILD_BYPRODUCTS ${GLOG_BYPRODUCTS}
+ PATCH_COMMAND ${GLOG_PATCH_CMD}
+ CMAKE_ARGS ${CMAKE_FORWARD_ARGS};-DBUILD_TESTING=OFF
+ CONFIGURE_COMMAND ${GLOG_CONFIG_CMD}
+ BUILD_COMMAND ${GLOG_BUILD_CMD}
+ INSTALL_COMMAND ${GLOG_INSTALL_CMD}
+ URL ${GLOG_URL}
+ URL_HASH ${GLOG_HASH})
+```
+
+In contrast to an interface library, we need to send all the build information,
+which we set in variables prior. This includes the `BUILD_BYPRODUCTS`, and the
+`PATCH_COMMAND` as we have to patch `glog`.
+
+Since we build `glog` with CMake on Windows, we have to set `CMAKE_ARGS` with
+the `CMAKE_FORWARD_ARGS`, and particular to `glog`, we disable its tests with
+`-DBUILD_TESTING=OFF`, though this is not a canonical CMake option.
+
+On Linux, we set the config, build, and install commands, and send them too.
+These are empty on Windows, so `ExternalProject_Add` will fallback to using
+CMake, as we needed.
+
+Finally, we add `glog` to as a link library to `stout`:
+
+```
+target_link_libraries(
+ stout INTERFACE
+ ...
+ glog
+ ...)
+```
+
+No other code is necessary, we have completed adding, building, and linking to
+`glog`. The same patterns can be adapted for any other third-party dependency.
+
+# Building debug or release configurations
+
+The default configuration is always `Debug`, which means with debug symbols and
+without (many) optimizations. Of course, when deploying Mesos an optimized
+`Release` build is desired. This is one of the few inconsistencies in CMake, and
+it's due to the difference between so-called "single-configuration generators"
+(such as GNU Make) and "multi-configuration generators" (such as Visual Studio).
+
+## Configuration-time configurations
+
+In single-configuration generators, the configuration (debug or release) is
+chosen at configuration time (that is, when initially calling `cmake` to
+configure the build), and it is not changeable without re-configuring. So
+building a `Release` configuration on Linux (with GNU Make) is done via:
+
+```
+cmake -DCMAKE_BUILD_TYPE=Release ..
+cmake --build .
+```
+
+## Build-time configurations
+
+However, the Visual Studio generator on Windows allows the developer to change
+the release at build-time, making it a multi-configuration generator. CMake
+generates a configuration-agnostic solution (and so `CMAKE_BUILD_TYPE` is
+ignored), and the user switches the configuration when building. This can be
+done with the familiar configuration menu in the Visual Studio IDE, or with
+CMake via:
+
+```
+cmake ..
+cmake --build . --config Release
+```
+
+In the same build folder, a `Debug` build can also be built, with the binaries
+stored in `Debug` and `Release` folders respectively. Unfortunately, the current
+CMake build explicitly sets the final binary destination directories, and so the
+final libraries and executables will overwrite each other when building
+different configurations.
+
+Note that Visual Studio is not the only IDE that uses a multi-configuration
+generator, Xcode on Mac OS X does as well.
+See [MESOS-7943][] for more information.
+
+[MESOS-7943]: https://issues.apache.org/jira/browse/MESOS-7943
+
+## Building with shared or static libraries
+
+On Linux, the configuration option `-DBUILD_SHARED_LIBS=FALSE` can be used to
+switch to static libraries where possible. Otherwise Linux builds shared
+libraries by default.
+
+On Windows, static libraries are the default. Building with shared libraries on
+Windows is not yet supported, as it requires code change to import symbols
+properly.
+
+## Building with Java
+
+When building with Java on Windows, you must add the [Maven][] build tool to
+your path. The `JAVA_HOME` environment variable must also be manually set.
+An installation of the Java SDK can be found form [Oracle][].
+
+[maven]: https://maven.apache.org/guides/getting-started/windows-prerequisites.html
+[oracle]: http://www.oracle.com/technetwork/java/javase/downloads/index.html
+
+As of this writing, Java 9 is not yet supported, but Java 8 has been tested.
+
+The Java build defaults to `OFF` because it is slow, to build the Java
+components on Windows, turn it `ON`:
+
+```powershell
+mkdir build; cd build
+$env:PATH += ";C:\...\apache-maven-3.3.9\bin\"
+$env:JAVA_HOME = "C:\Program Files\Java\jdk1.8.0_144"
+cmake .. -DENABLE_JAVA=ON -DENABLE_LIBEVENT=ON -G "Visual Studio 15 2017 Win64" -T "host=x64"
+cmake --build . --target mesos-java
+```
+
+Note that the `mesos-java` library does not have to be manually built; as
+`libmesos` will link it when Java is enabled.
+
+At runtime, if `JAVA_JVM_LIBRARY` is not set correctly, it can also be set as an
+environment variable, and should be of the form:
+
+```
+C:\Program Files\Java\jdk1.8.0_144\jre\bin\server\jvm.dll
+```
+
+## Building with OpenSSL
+
+When building with OpenSSL on Windows, you must build or install a distribution
+of OpenSSL for Windows. A commonly chosen distribution is [Shining Light
+Productions' OpenSSL][openssl].
+
+[openssl]: https://slproweb.com/products/Win32OpenSSL.html
+
+As of this writing, OpenSSL 1.1.x is not yet supported, but 1.0.2L has been
+tested.
+
+Use `-DENABLE_SSL=ON` when running CMake to build with OpenSSL.
http://git-wip-us.apache.org/repos/asf/mesos/blob/5824eaf3/docs/cmake.md
----------------------------------------------------------------------
diff --git a/docs/cmake.md b/docs/cmake.md
new file mode 100644
index 0000000..3e7e229
--- /dev/null
+++ b/docs/cmake.md
@@ -0,0 +1,383 @@
+---
+title: Apache Mesos - CMake
+layout: documentation
+---
+
+# Install CMake 3.7+
+
+[cmake-download]: https://cmake.org/download/
+
+## Linux
+
+Install the latest version of CMake from [CMake.org][cmake-download].
+A self-extracting tarball is available to make this process painless.
+
+Currently, few of the common Linux flavors package a sufficient CMake
+version. Ubuntu versions 12.04 and 14.04 package CMake 2;
+Ubuntu 16.04 packages CMake 3.5. If you already installed cmake from packages,
+you may remove it via: `apt-get purge cmake`.
+
+The standard CentOS package is CMake 2, and unfortunately even the `cmake3`
+package in EPEL is only CMake 3.6, you may remove them via:
+`yum remove cmake cmake3`.
+
+## Mac OS X
+
+HomeBrew's CMake version is sufficient: `brew install cmake`.
+
+## Windows
+
+Download and install the MSI from [CMake.org][cmake-download].
+
+**NOTE:** Windows needs CMake 3.8+, rather than 3.7+.
+
+# Supported options
+
+See [configuration options](configuration.md#cmake-configuration-options).
+
+# Examples
+
+See [CMake By Example](cmake-examples.md).
+
+# Documentation
+
+The [CMake documentation][] is written as a reference module. The most commonly
+used sections are:
+
+* [buildsystem overview](https://cmake.org/cmake/help/latest/manual/cmake-buildsystem.7.html)
+* [commands](https://cmake.org/cmake/help/latest/manual/cmake-commands.7.html)
+* [properties](https://cmake.org/cmake/help/latest/manual/cmake-properties.7.html)
+* [variables](https://cmake.org/cmake/help/latest/manual/cmake-variables.7.html)
+
+The wiki also has a set of [useful variables][].
+
+[CMake documentation]: https://cmake.org/cmake/help/latest/
+[useful variables]: https://cmake.org/Wiki/CMake_Useful_Variables
+
+# Dependency graph
+
+Like any build system, CMake has a dependency graph. The difference is
+that targets in CMake's dependency graph are _much richer_ compared to other
+build systems. CMake targets have the notion of 'interfaces', where build
+properties are saved as part of the target, and these properties can be
+inherited transitively within the graph.
+
+For example, say there is a library `mylib`, and anything which links it must
+include its headers, located in `mylib/include`. When building the library, some
+private headers must also be included, but not when linking to it. When
+compiling the executable `myprogram`, `mylib`'s public headers must be included,
+but not its private headers. There is no manual step to add `mylib/include` to
+`myprogram` (and any other program which links to `mylib`), it is instead
+deduced from the public interface property of `mylib`. This is represented by
+the following code:
+
+```
+# A new library with a single source file (headers are found automatically).
+add_library(mylib mylib.cpp)
+
+# The folder of private headers, not exposed to consumers of `mylib`.
+target_include_directories(mylib PRIVATE mylib/private)
+
+# The folder of public headers, added to the compilation of any consumer.
+target_include_directories(mylib PUBLIC mylib/include)
+
+# A new exectuable with a single source file.
+add_executable(myprogram main.cpp)
+
+# The creation of the link dependency `myprogram` -> `mylib`.
+target_link_libraries(myprogram mylib)
+
+# There is no additional step to add `mylib/include` to `myprogram`.
+```
+
+This same notion applies to practically every build property:
+compile definitions via [`target_compile_definitions`][],
+include directories via [`target_include_directories`][],
+link libraries via [`target_link_libraries`][],
+compile options via [`target_compile_options`][],
+and compile features via [`target_compile_features`][].
+
+All of these commands also take an optional argument of
+`<INTERFACE|PUBLIC|PRIVATE>`, which constrains their transitivity in the graph.
+That is, a `PRIVATE` include directory is recorded for the target, but not
+shared transitively to anything depending on the target, `PUBLIC` is used
+for both the target and dependencies on it, and `INTERFACE` is used only
+for dependencies.
+
+Notably missing from this list are link directories. CMake explicitly prefers
+finding and using the absolute paths to libraries, obsoleting link directories.
+
+[`target_compile_definitions`]: https://cmake.org/cmake/help/latest/command/target_compile_definitions.html
+[`target_include_directories`]: https://cmake.org/cmake/help/latest/command/target_include_directories.html
+[`target_link_libraries`]: https://cmake.org/cmake/help/latest/command/target_link_libraries.html
+[`target_compile_options`]: https://cmake.org/cmake/help/latest/command/target_compile_options.html
+[`target_compile_features`]: https://cmake.org/cmake/help/latest/command/target_compile_features.html
+
+# Common mistakes
+
+## Booleans
+
+CMake treats `ON`, `OFF`, `TRUE`, `FALSE`, `1`, and `0` all as true/false
+booleans. Furthermore, variables of the form `<target>-NOTFOUND` are also
+treated as false (this is used for finding packages).
+
+In Mesos, we prefer the boolean types `TRUE` and `FALSE`.
+
+See [`if`](https://cmake.org/cmake/help/latest/command/if.html) for more info.
+
+## Conditionals
+
+For historical reasons, CMake conditionals such as `if` and `elseif`
+automatically interpolate variable names. It is therefore dangerous to
+interpolate them manually, because if `${FOO}` evaluates to `BAR`, and `BAR` is
+another variable name, then `if (${FOO})` becomes `if (BAR)`, and `BAR` is then
+evaluated again by the `if`. Stick to `if (FOO)` to check the value of `${FOO}`.
+Do not use `if (${FOO})`.
+
+Also see the CMake policies
+[CMP0012](https://cmake.org/cmake/help/latest/policy/CMP0012.html) and
+[CMP0054](https://cmake.org/cmake/help/latest/policy/CMP0054.html).
+
+## Definitions
+
+When using `add_definitions()` (which should be used rarely, as it is for
+"global" compile definitions), the flags must be prefixed with `-D` to be
+treated as preprocessor definitions. However, when using
+`target_compile_definitions()` (which should be preferred, as it is
+for specific targets), the flags do not need the prefix.
+
+# Style
+
+In general, wrap at 80 lines, and use a two-space indent. When wrapping
+arguments, put the command on a separate line and arguments on subsequent lines:
+
+```
+target_link_libraries(
+ program PRIVATE
+ alpha
+ beta
+ gamma)
+```
+
+Otherwise keep it together:
+
+```
+target_link_libraries(program PUBLIC library)
+```
+
+Always keep the trailing parenthesis with the last argument.
+
+Use a single space between conditionals and their open parenthesis, e.g.
+`if (FOO)`, but not for commands, e.g. `add_executable(program)`.
+
+CAPITALIZE the declaration and use of custom functions and macros (e.g.
+`EXTERNAL` and `PATCH_CMD`), and do not capitalize the use of CMake built-in
+(including modules) functions and macros. CAPITALIZE variables.
+
+# CMake anti-patterns
+
+[anti-patterns]: http://voices.canonical.com/jussi.pakkanen/2013/03/26/a-list-of-common-cmake-antipatterns/
+
+Because CMake handles much more of the grunt work for you than other build
+systems, there are unfortunately a lot of CMake [anti-patterns][] you should
+look out for when writing new CMake code. These are some common problems
+that should be avoided when writing new CMake code:
+
+## Superfluous use of `add_dependencies`
+
+When you've linked library `a` to library `b` with `target_link_libraries(a b)`,
+the CMake graph is already updated with the dependency information. It is
+redundant to use `add_dependencies(a b)` to (re)specify the dependency. In fact,
+this command should _rarely_ be used.
+
+The exceptions to this are:
+
+ 1. Setting a dependency from an imported library to a target added via
+ `ExternalProject_Add`.
+ 2. Setting a dependency on Mesos modules since no explicit linking is done.
+ 3. Setting a dependency between executables (e.g. the `mesos-agent` requiring the
+ `mesos-containerizer` executable). In general, runtime dependencies need
+ to be setup with `add_dependency`, but never link dependencies.
+
+## Use of `link_libraries` or `link_directories`
+
+Neither of these commands should ever be used. The only appropriate command used
+to link libraries is [`target_link_libraries`][], which records the information
+in the CMake dependency graph. Furthermore, imported third-party libraries
+should have correct locations recorded in their respective targets, so the use
+of `link_directories` should never be necessary. The
+[official documentation][link-directories] states:
+
+> Note that this command is rarely necessary. Library locations returned by
+> `find_package()` and `find_library()` are absolute paths. Pass these absolute
+> library file paths directly to the `target_link_libraries()` command. CMake
+> will ensure the linker finds them.
+
+[link-directories]: https://cmake.org/cmake/help/latest/command/link_directories.html
+
+The difference is that the former sets global (or directory level) side effects,
+and the latter sets specific target information stored in the graph.
+
+## Use of `include_directories`
+
+This is similar to the above: the [`target_include_directories`][] should always
+be preferred so that the include directory information remains localized to the
+appropriate targets.
+
+## Adding anything to `endif ()`
+
+Old versions of CMake expected the style `if (FOO) ... endif (FOO)`, where the
+`endif` contained the same expression as the `if` command. However, this is
+tortuously redundant, so leave the parentheses in `endif ()` empty. This goes
+for other endings too, such as `endforeach ()`, `endwhile ()`, `endmacro ()` and
+`endfunction ()`.
+
+## Specifying header files superfluously
+
+One of the distinct advantages of using CMake for C and C++ projects is that
+adding header files to the source list for a target is unnecessary. CMake is
+designed to parse the source files (`.c`, `.cpp`, etc.) and determine their
+required headers automatically. The exception to this is headers generated as
+part of the build (such as protobuf or the JNI headers).
+
+## Checking `CMAKE_BUILD_TYPE`
+
+See the ["Building debug or release configurations"][config] example for more
+information. In short, not all generators respect the variable
+`CMAKE_BUILD_TYPE` at configuration time, and thus it must not be used in CMake
+logic. A usable alternative (where supported) is a [generator expression][] such
+as `$<$<CONFIG:Debug>:DEBUG_MODE>`.
+
+[config]: cmake-examples.md#building-debug-or-release-configurations
+[generator expression]: https://cmake.org/cmake/help/latest/manual/cmake-generator-expressions.7.html#logical-expressions
+
+# Remaining hacks
+
+## `3RDPARTY_DEPENDENCIES`
+
+Until Mesos on Windows is stable, we keep some dependencies in an external
+repository, [mesos-3rdparty](https://github.com/3rdparty/mesos-3rdparty). When
+all dependencies are bundled with Mesos, this extra repository will no longer be
+necessary. Until then, the CMake variable `3RDPARTY_DEPENDENCIES` points by
+default to this URL, but it can also point to the on-disk location of a local
+clone of the repo. With this option you can avoid pulling from GitHub for every
+clean build.
+
+## `EXTERNAL`
+
+The CMake function `EXTERNAL` defines a few variables that make it easy for us
+to track the directory structure of a dependency. In particular, if our
+library's name is `boost`, we invoke:
+
+```
+EXTERNAL(boost ${BOOST_VERSION} ${CMAKE_CURRENT_BINARY_DIR})
+```
+
+Which will define the following variables as side-effects in the current scope:
+
+* `BOOST_TARGET` (a target folder name to put dep in e.g., `boost-1.53.0`)
+* `BOOST_CMAKE_ROOT` (where to have CMake put the uncompressed source, e.g.,
+ `build/3rdparty/boost-1.53.0`)
+* `BOOST_ROOT` (where the code goes in various stages of build, e.g.,
+ `build/.../boost-1.53.0/src`, which might contain folders
+ `build-1.53.0-build`, `-lib`, and so on, for each build
+ step that dependency has)
+
+The implementation is in `3rdparty/cmake/External.cmake`.
+
+This is not to be confused with the CMake module [ExternalProject][], from which
+we use `ExternalProject_Add` to download, extract, configure, and build our
+dependencies.
+
+[ExternalProject]: https://cmake.org/cmake/help/latest/module/ExternalProject.html
+
+## `CMAKE_NOOP`
+
+This is a CMake variable we define in `3rdparty/CMakeLists.txt` so that we can
+cancel steps of `ExternalProject`. `ExternalProject`'s default behavior is to
+attempt to configure, build, and install a project using CMake. So when one of
+these steps must be skipped, we use set it to `CMAKE_NOOP` so that nothing
+is run instead.
+
+## `CMAKE_FORWARD_ARGS`
+
+The `CMAKE_FORWARD_ARGS` variable defined in `3rdparty/CMakeLists.txt` is sent
+as the `CMAKE_ARGS` argument to the `ExternalProject_Add` macro (along with any
+per-project arguments), and is used when the external project is configured as a
+CMake project. If either the `CONFIGURE_COMMAND` or `BUILD_COMMAND` arguments of
+`ExternalProject_Add` are used, then the `CMAKE_ARGS` argument will be ignored.
+This variable ensures that compilation configurations are properly propagated to
+third-party dependencies, such as compiler flags.
+
+## `LIBRARY_LINKAGE`
+
+This variable is a shortcut used in `3rdparty/CMakeLists.txt`. It is set to
+`SHARED` when `BUILD_SHARED_LIBS` is true, and otherwise it is set to `STATIC`.
+The `SHARED` and `STATIC` keywords are used to declare how a library should be
+built; however, if left out then the type is deduced automatically from
+`BUILD_SHARED_LIBS`.
+
+## `MAKE_INCLUDE_DIR`
+
+This function works around a [CMake issue][cmake-15052] with setting include
+directories of imported libraries built with `ExternalProject_Add`. We have to
+call this for each `IMPORTED` third-party dependency which has set
+`INTERFACE_INCLUDE_DIRECTORIES`, just to make CMake happy. An example is Glog:
+
+```
+MAKE_INCLUDE_DIR(glog)
+```
+
+[cmake-15052]: https://gitlab.kitware.com/cmake/cmake/issues/15052
+
+## `GET_BYPRODUCTS`
+
+This function works around a [CMake issue][cmake-060234] with the Ninja
+generator where it does not understand imported libraries, and instead needs
+`BUILD_BYPRODUCTS` explicitly set. This simply allows us to use
+`ExternalProject_Add` and Ninja. For Glog, it looks like this:
+
+```
+GET_BYPRODUCTS(glog)
+```
+
+Also see the CMake policy [CMP0058][].
+
+[cmake-060234]: https://cmake.org/pipermail/cmake/2015-April/060234.html
+[CMP0058]: https://cmake.org/cmake/help/latest/policy/CMP0058.html
+
+## `PATCH_CMD`
+
+The CMake function `PATCH_CMD` generates a patch command given a patch file.
+If the path is not absolute, it's resolved to the current source directory.
+It stores the command in the variable name supplied. This is used to easily
+patch third-party dependencies. For Glog, it looks like this:
+
+```
+PATCH_CMD(GLOG_PATCH_CMD glog-${GLOG_VERSION}.patch)
+ExternalProject_Add(
+ ${GLOG_TARGET}
+ ...
+ PATCH_COMMAND ${GLOG_PATCH_CMD})
+```
+
+The implementation is in `3rdparty/cmake/PatchCommand.cmake`.
+
+### Windows `patch.exe`
+
+While using `patch` on Linux is straightforward, doing the same on Windows takes
+a bit of work. `PATH_CMD` encapsulates this:
+
+* Checks the cache variable `PATCHEXE_PATH` for `patch.exe`.
+* Searches for `patch.exe` in its default locations.
+* Copies `patch.exe` and a custom manifest to the temporary directory.
+* Applies the manifest to avoid the UAC prompt.
+* Uses the patched `patch.exe`.
+
+As such, `PATCH_CMD` lets us apply patches as we do on Linux, without requiring
+an administrative prompt.
+
+Note that on Windows, the patch file must have CRLF line endings. A file with LF
+line endings will cause the error: "Assertion failed, hunk, file patch.c, line
+343". For this reason, it is required to checkout the Mesos repo with `git
+config core.autocrlf true`.
http://git-wip-us.apache.org/repos/asf/mesos/blob/5824eaf3/docs/configuration-cmake.md
----------------------------------------------------------------------
diff --git a/docs/configuration-cmake.md b/docs/configuration-cmake.md
deleted file mode 100644
index 1b10221..0000000
--- a/docs/configuration-cmake.md
+++ /dev/null
@@ -1,108 +0,0 @@
----
-title: Apache Mesos - CMake Configuration
-layout: documentation
----
-
-# Mesos CMake Build Configuration Options
-
-Mesos currently exposes two build systems, one written in
-[autotools](configuration.md), and one written in CMake.
-This document describes the configuration flags available in
-the CMake build system.
-
-
-## CMake configuration options
-
-<table class="table table-striped">
- <thead>
- <tr>
- <th width="30%">
- Flag
- </th>
- <th>
- Explanation
- </th>
- </tr>
- </thead>
- <tr>
- <td>
- -D3RDPARTY_DEPENDENCIES[=path_or_url]
- </td>
- <td>
- Location of the dependency mirror. In some cases, the Mesos build system
- needs to acquire third-party dependencies that aren't rebundled as
- tarballs in the Mesos repository. For example, on Windows, we must aquire
- newer versions of some dependencies, and since Windows does not have a
- package manager, we must acquire system dependencies like cURL. This
- parameter can be either a URL (for example, pointing at the Mesos official
- [third-party dependency mirror](https://github.com/3rdparty/mesos-3rdparty)),
- or a local folder (for example, a local clone of the dependency mirror).
- [default=https://github.com/3rdparty/mesos-3rdparty]
- </td>
- </tr>
- <tr>
- <td>
- -DCPACK_BINARY_(BUNDLE|DEB|DRAGNDROP|IFW|NSIS|OSXX11|PACKAGEMAKER|RPM|STGZ|TBZ2|TGZ|TXZ)
- </td>
- <td>
- This modifies the 'package' target to generate binary package of
- the specified format. A binary package contains everything that
- would be installed via CMake's 'install' target.
- [default=OFF]
- </td>
- </tr>
- <tr>
- <td>
- -DCPACK_SOURCE_(TBZ2|TXZ|TZ|ZIP)
- </td>
- <td>
- This modifies the 'package_source' target to generate a package of the
- sources required to build and test Mesos, in the specified format.
- [default=OFF]
- </td>
- </tr>
- <tr>
- <td>
- -DENABLE_LIBEVENT
- </td>
- <td>
- Use libevent instead of libev for the event loop. [default=FALSE]
- </td>
- </tr>
- <tr>
- <td>
- -DENABLE_SSL
- </td>
- <td>
- Build libprocess with SSL support. [default=FALSE]
- </td>
- </tr>
- <tr>
- <td>
- -DREBUNDLED
- </td>
- <td>
- Attempt to build against the third-party dependencies included as
- tarballs in the Mesos repository.
-
- NOTE: This is not always possible. For example, a dependency might
- not be included as a tarball in the Mesos repository; additionally,
- Windows does not have a package manager, so we do not expect system
- dependencies like APR to exist natively, and we therefore must acquire
- them. In these cases (or when `REBUNDLED` is set to `FALSE`), we will
- acquire the dependency from the location specified by the
- `3RDPARTY_DEPENDENCIES`, which by default points to the official Mesos
- [third-party dependency mirror](https://github.com/3rdparty/mesos-3rdparty).
- [default=TRUE]
- </td>
- </tr>
- <tr>
- <td>
- -DVERBOSE
- </td>
- <td>
- Generate a build solution that produces verbose output
- (for example, verbose Makefiles). [default=TRUE]
- </td>
- </tr>
-</table>
http://git-wip-us.apache.org/repos/asf/mesos/blob/5824eaf3/docs/configuration.md
----------------------------------------------------------------------
diff --git a/docs/configuration.md b/docs/configuration.md
index e1fd9f7..62562b0 100644
--- a/docs/configuration.md
+++ b/docs/configuration.md
@@ -2688,7 +2688,7 @@ quotas for container sandbox directories. Valid project IDs range from
</tr>
<tr>
<td>
- --with-sysroot=DIR
+ --with-sysroot[=DIR]
</td>
<td>
Search for dependent libraries within <code>DIR</code>
@@ -2697,7 +2697,7 @@ quotas for container sandbox directories. Valid project IDs range from
</tr>
<tr>
<td>
- --with-apr=[=DIR]
+ --with-apr[=DIR]
</td>
<td>
Specify where to locate the apr-1 library.
@@ -2723,7 +2723,7 @@ quotas for container sandbox directories. Valid project IDs range from
</tr>
<tr>
<td>
- --with-curl=[=DIR]
+ --with-curl[=DIR]
</td>
<td>
Specify where to locate the curl library.
@@ -2785,7 +2785,7 @@ quotas for container sandbox directories. Valid project IDs range from
</tr>
<tr>
<td>
- --with-libevent=[=DIR]
+ --with-libevent[=DIR]
</td>
<td>
Specify where to locate the libevent library.
@@ -2793,7 +2793,7 @@ quotas for container sandbox directories. Valid project IDs range from
</tr>
<tr>
<td>
- --with-libprocess=[=DIR]
+ --with-libprocess[=DIR]
</td>
<td>
Specify where to locate the libprocess library.
@@ -2809,7 +2809,7 @@ quotas for container sandbox directories. Valid project IDs range from
</tr>
<tr>
<td>
- --with-nl=[DIR]
+ --with-nl[=DIR]
</td>
<td>
Specify where to locate the
@@ -2846,7 +2846,7 @@ quotas for container sandbox directories. Valid project IDs range from
</tr>
<tr>
<td>
- --with-sasl=[=DIR]
+ --with-sasl[=DIR]
</td>
<td>
Specify where to locate the sasl2 library.
@@ -2854,7 +2854,7 @@ quotas for container sandbox directories. Valid project IDs range from
</tr>
<tr>
<td>
- --with-ssl=[=DIR]
+ --with-ssl[=DIR]
</td>
<td>
Specify where to locate the ssl library.
@@ -2862,7 +2862,7 @@ quotas for container sandbox directories. Valid project IDs range from
</tr>
<tr>
<td>
- --with-stout=[=DIR]
+ --with-stout[=DIR]
</td>
<td>
Specify where to locate stout library.
@@ -2870,7 +2870,7 @@ quotas for container sandbox directories. Valid project IDs range from
</tr>
<tr>
<td>
- --with-svn=[=DIR]
+ --with-svn[=DIR]
</td>
<td>
Specify where to locate the svn-1 library.
@@ -2878,7 +2878,7 @@ quotas for container sandbox directories. Valid project IDs range from
</tr>
<tr>
<td>
- --with-zlib=[=DIR]
+ --with-zlib[=DIR]
</td>
<td>
Specify where to locate the zlib library.
@@ -2969,3 +2969,155 @@ it to find libraries and programs with nonstandard names/locations.
</td>
</tr>
</table>
+
+### CMake configuration options
+
+<table class="table table-striped">
+ <thead>
+ <tr>
+ <th width="30%">
+ Flag
+ </th>
+ <th>
+ Explanation
+ </th>
+ </tr>
+ </thead>
+ <tr>
+ <td>
+ -DVERBOSE=(TRUE|FALSE)
+ </td>
+ <td>
+ Generate a build solution that produces verbose output
+ (for example, verbose Makefiles). [default=TRUE]
+ </td>
+ </tr>
+ <tr>
+ <td>
+ -DBUILD_SHARED_LIBS=(TRUE|FALSE)
+ </td>
+ <td>
+ Build shared libraries (where possible).
+ [default=FALSE for Windows, TRUE otherwise]
+ </td>
+ </tr>
+ <tr>
+ <td>
+ -DENABLE_PRECOMPILED_HEADERS=(TRUE|FALSE)
+ </td>
+ <td>
+ Enable auto-generated precompiled headers using cotire.
+ [default=TRUE for Windows, FALSE otherwise]
+ </td>
+ </tr>
+ <tr>
+ <td>
+ -DCPACK_BINARY_[TYPE]=(TRUE|FALSE)
+ </td>
+ <td>
+ Where [TYPE] is one of BUNDLE, DEB, DRAGNDROP, IFW, NSIS, OSXX11,
+ PACKAGEMAKER, RPM, STGZ, TBZ2, TGZ, TXZ. This modifies the 'package'
+ target to generate binary package of the specified format. A binary
+ package contains everything that would be installed via CMake's 'install'
+ target. [default=FALSE]
+ </td>
+ </tr>
+ <tr>
+ <td>
+ -DCPACK_SOURCE_[TYPE]=(TRUE|FALSE)
+ </td>
+ <td>
+ Where [TYPE] is one of TBZ2, TXZ, TZ, ZIP. This modifies the
+ 'package_source' target to generate a package of the sources required to
+ build and test Mesos, in the specified format. [default=FALSE]
+ </td>
+ </tr>
+ <tr>
+ <td>
+ -DREBUNDLED=(TRUE|FALSE)
+ </td>
+ <td>
+ Attempt to build against the third-party dependencies included as tarballs
+ in the Mesos repository. NOTE: This is not always possible. For example, a
+ dependency might not be included as a tarball in the Mesos repository;
+ additionally, Windows does not have a package manager, so we do not expect
+ system dependencies like APR to exist natively, and we therefore must
+ acquire them. In these cases (or when <code>-DREBUNDLED=FALSE</code>), we
+ will acquire the dependency from the location specified by the
+ <code>3RDPARTY_DEPENDENCIES</code>, which by default points to the
+ official Mesos <a
+ href="https://github.com/3rdparty/mesos-3rdparty">third-party dependency
+ mirror</a>. [default=TRUE]
+ </td>
+ </tr>
+ <tr>
+ <td>
+ -DENABLE_LIBEVENT=(TRUE|FALSE)
+ </td>
+ <td>
+ Use <a href="https://github.com/libevent/libevent">libevent</a> instead of
+ libev for the event loop. This is required (but not the default) on
+ Windows. [default=FALSE]
+ </td>
+ </tr>
+ <tr>
+ <td>
+ -DENABLE_SSL=(TRUE|FALSE)
+ </td>
+ <td>
+ Build libprocess with SSL support. [default=FALSE]
+ </td>
+ </tr>
+ <tr>
+ <td>
+ -DOPENSSL_ROOT_DIR=[path]
+ </td>
+ <td>
+ Specify the path to OpenSSL, e.g. "C:\OpenSSL-Win64".
+ [default=unspecified]
+ </td>
+ </tr>
+ <tr>
+ <td>
+ -DENABLE_LOCK_FREE_RUN_QUEUE=(TRUE|FALSE)
+ </td>
+ <td>
+ Build libprocess with lock free run queue. [default=FALSE]
+ </td>
+ </tr>
+ <tr>
+ <td>
+ -DENABLE_JAVA=(TRUE|FALSE)
+ </td>
+ <td>
+ Build Java components. Warning: this is SLOW. [default=FALSE]
+ </td>
+ </tr>
+ <tr>
+ <td>
+ -D3RDPARTY_DEPENDENCIES=[path_or_url]
+ </td>
+ <td>
+ Location of the dependency mirror. In some cases, the Mesos build system
+ needs to acquire third-party dependencies that aren't rebundled as
+ tarballs in the Mesos repository. For example, on Windows, we must aquire
+ newer versions of some dependencies, and since Windows does not have a
+ package manager, we must acquire system dependencies like cURL. This
+ parameter can be either a URL (for example, pointing at the Mesos official
+ <a href="https://github.com/3rdparty/mesos-3rdparty">third-party
+ dependency mirror</a>), or a local folder (for example, a local clone of
+ the dependency mirror).
+ [default="https://github.com/3rdparty/mesos-3rdparty/raw/master"]
+ </td>
+ </tr>
+ <tr>
+ <td>
+ -DPATCHEXE_PATH=[path]
+ </td>
+ <td>
+ Location of
+ <a href="http://gnuwin32.sourceforge.net/packages/patch.htm">GNU Patch for
+ Windows</a> binary. [default=%PROGRAMFILESX86%/GnuWin32/bin/patch.exe]
+ </td>
+ </tr>
+</table>
http://git-wip-us.apache.org/repos/asf/mesos/blob/5824eaf3/docs/home.md
----------------------------------------------------------------------
diff --git a/docs/home.md b/docs/home.md
index f9b35e3..ad81d63 100644
--- a/docs/home.md
+++ b/docs/home.md
@@ -18,6 +18,7 @@ layout: documentation
* [Agent Recovery](agent-recovery.md) for doing seamless agent upgrades and allowing executors to survive `mesos-agent` crashes.
* [Authentication](authentication.md)
* [Authorization](authorization.md)
+* [CMake](cmake.md) for details about using the new CMake build system.
* [Configuration](configuration.md) and [CMake configuration](configuration-cmake.md) for command-line arguments.
* [Container Image](container-image.md) for supporting container images in Mesos containerizer.
* [Container Volume](container-volume.md) for using container volumes.