Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modernize CMake Build #2579

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
772 changes: 1 addition & 771 deletions Builds/CMake/CMakeFuncs.cmake

Large diffs are not rendered by default.

2,098 changes: 2,098 additions & 0 deletions Builds/CMake/FindBoost.cmake

Large diffs are not rendered by default.

55 changes: 55 additions & 0 deletions Builds/CMake/RippleConfig.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
include (CMakeFindDependencyMacro)
# need to represent system dependencies of the lib here
#[=========================================================[
Boost
#]=========================================================]
if (static OR APPLE OR MSVC)
set (Boost_USE_STATIC_LIBS ON)
endif ()
set (Boost_USE_MULTITHREADED ON)
if (static OR MSVC)
set (Boost_USE_STATIC_RUNTIME ON)
else ()
set (Boost_USE_STATIC_RUNTIME OFF)
endif ()
find_dependency (Boost 1.67
COMPONENTS
chrono
context
coroutine
date_time
filesystem
program_options
regex
serialization
system
thread)
#[=========================================================[
OpenSSL
#]=========================================================]
if (APPLE AND NOT DEFINED ENV{OPENSSL_ROOT_DIR})
find_program (HOMEBREW brew)
if (NOT HOMEBREW STREQUAL "HOMEBREW-NOTFOUND")
execute_process (COMMAND ${HOMEBREW} --prefix openssl
OUTPUT_VARIABLE OPENSSL_ROOT_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE)
endif ()
endif ()

if ((NOT DEFINED OPENSSL_ROOT) AND (DEFINED ENV{OPENSSL_ROOT}))
set (OPENSSL_ROOT $ENV{OPENSSL_ROOT})
endif ()
file (TO_CMAKE_PATH "${OPENSSL_ROOT}" OPENSSL_ROOT)

if (static OR APPLE OR MSVC)
set (OPENSSL_USE_STATIC_LIBS ON)
endif ()
set (OPENSSL_MSVC_STATIC_RT ON)
find_dependency (OpenSSL 1.0.2 REQUIRED)
find_dependency (ZLIB)
if (TARGET ZLIB::ZLIB)
set_target_properties(OpenSSL::Crypto PROPERTIES
INTERFACE_LINK_LIBRARIES ZLIB::ZLIB)
endif ()

include ("${CMAKE_CURRENT_LIST_DIR}/RippleTargets.cmake")
29 changes: 24 additions & 5 deletions Builds/Test.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ def powerset(iterable):
# CMake
if IS_WINDOWS:
CMAKE_UNITY_CONFIGS = ['Debug', 'Release']
CMAKE_NONUNITY_CONFIGS = ['DebugClassic', 'ReleaseClassic']
CMAKE_NONUNITY_CONFIGS = ['Debug', 'Release']
else:
CMAKE_UNITY_CONFIGS = []
CMAKE_NONUNITY_CONFIGS = []
CMAKE_UNITY_COMBOS = { '' : [['rippled', 'rippled_classic'], CMAKE_UNITY_CONFIGS],
'.nounity' : [['rippled', 'rippled_unity'], CMAKE_NONUNITY_CONFIGS] }
CMAKE_UNITY_COMBOS = { '' : [['rippled'], CMAKE_UNITY_CONFIGS],
'.nounity' : [['rippled'], CMAKE_NONUNITY_CONFIGS] }

if IS_WINDOWS:
CMAKE_DIR_TARGETS = { ('msvc' + unity,) : targets for unity, targets in
Expand Down Expand Up @@ -198,7 +198,7 @@ def decodeString(line):
else:
return line.decode()

def shell(cmd, args=(), silent=False):
def shell(cmd, args=(), silent=False, cust_env=None):
""""Execute a shell command and return the output."""
silent = ARGS.silent or silent
verbose = not silent and ARGS.verbose
Expand All @@ -213,6 +213,7 @@ def shell(cmd, args=(), silent=False):
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
env=cust_env,
shell=IS_WINDOWS)
lines = []
count = 0
Expand Down Expand Up @@ -252,7 +253,25 @@ def run_cmake(directory, cmake_dir, args):
args += ( '-GNinja', )
else:
args += ( '-GVisual Studio 14 2015 Win64', )
args += ( '-Dtarget=' + cmake_dir, os.path.join('..', '..', '..'), )
# hack to extract cmake options/args from the legacy target format
if re.search('\.unity', cmake_dir):
args += ( '-Dunity=ON', )
if re.search('\.nounity', cmake_dir):
args += ( '-Dunity=OFF', )
if re.search('coverage', cmake_dir):
args += ( '-Dcoverage=ON', )
if re.search('profile', cmake_dir):
args += ( '-Dprofile=ON', )
if re.search('debug', cmake_dir):
args += ( '-DCMAKE_BUILD_TYPE=Debug', )
if re.search('release', cmake_dir):
args += ( '-DCMAKE_BUILD_TYPE=Release', )
if re.search('gcc', cmake_dir):
args += ( '-DCMAKE_C_COMPILER=gcc', '-DCMAKE_CXX_COMPILER=g++', )
if re.search('clang', cmake_dir):
args += ( '-DCMAKE_C_COMPILER=clang', '-DCMAKE_CXX_COMPILER=clang++', )

args += ( os.path.join('..', '..', '..'), )
resultcode, lines = shell('cmake', args)

if resultcode:
Expand Down
98 changes: 89 additions & 9 deletions Builds/linux/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,16 @@ cd my_build
followed by:

```
cmake -Dtarget=gcc.debug.unity ..
cmake -DCMAKE_BUILD_TYPE=Debug ..
```

The target variable can be adjusted as needed for `gcc` vs `clang`, `debug` vs.
`release` and `unity` vs. `nounity` builds. `unity` builds are faster to
compile since they combine multiple sources into a single compiliation unit.
`nounity` builds can be helpful for detecting include omissions or for finding
other build-related issues, but aren't generally needed for testing and
running.
`CMAKE_BUILD_TYPE` can be changed as desired for `Debug` vs.
`Release` builds (all four standard cmake build types are supported).

To select a different compiler (most likely gcc will be found by default), pass
`-DCMAKE_C_COMPILER=<path/to/c-compiler>` and
`-DCMAKE_CXX_COMPILER=</path/to/cxx-compiler>` when configuring. If you prefer,
you can instead set `CC` and `CXX` environment variables which cmake will honor.

Once you have generated the build system, you can run the build via cmake:

Expand All @@ -130,15 +131,94 @@ properly configured) or to run unit tests.

#### Options During Configuration:

There are a number of config variables that our CMake files support. These
can be added to the cmake generation command as needed:
The CMake file defines a number of configure-time options which can be
examined by running `cmake-gui` or `ccmake` to generated the build. In
particular, the `unity` option allows you to select between the unity and
non-unity builds. `unity` builds are faster to compile since they combine
multiple sources into a single compiliation unit - this is the default if you
don't specify. `nounity` builds can be helpful for detecting include omissions
or for finding other build-related issues, but aren't generally needed for
testing and running.

* `-Dunity=ON` to enable/disable unity builds (defaults to ON)
* `-Dassert=ON` to enable asserts
* `-Djemalloc=ON` to enable jemalloc support for heap checking
* `-Dsan=thread` to enable the thread sanitizer with clang
* `-Dsan=address` to enable the address sanitizer with clang
* `-Dstatic=ON` to enable static linking library dependencies

Several other infrequently used options are available - run `ccmake` or
`cmake-gui` for a list of all options.

#### Optional Installation

The rippled cmake build supports an installation target that will install
rippled as well as a support library that can be used to sign transactions. In
order to build and install the files, specify the `install` target when
building, e.g.:

```
cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=/opt/local ..
cmake --build . --target install -- -j <parallel jobs>
```

We recommend specifying `CMAKE_INSTALL_PREFIX` when configuring in order to
explicitly control the install location for your files. Without this setting,
cmake will typically install in `/usr/local`. It is also possible to "rehome"
the installation by specifying the `DESTDIR` env variable during the install phase,
e.g.:

```
DESTDIR=~/mylibs cmake --build . --target install -- -j <parallel jobs>
```

in which case, the files would be installed in the `CMAKE_INSTALL_PREFIX` within
the specified `DESTDIR` path.

#### Signing Library

If you want to use the signing support library to create an application, there
are two simple mechanisms with cmake + git that facilitate this.

With either option below, you will have access to a library from the
rippled project that you can link to in your own project's CMakeLists.txt, e.g.:

```
target_link_libraries (my-signing-app Ripple::xrpl_core)
```

##### Option 1: git submodules + add_subdirectory

First, add the rippled repo as a submodule to your project repo:

```
git submodule add -b master https:/ripple/rippled.git vendor/rippled
```

change the `vendor/rippled` path as desired for your repo layout. Furthermore,
change the branch name if you want to track a different rippled branch, such
as `develop`.

Second, to bring this submodule into your project, just add the rippled subdirectory:

```
add_subdirectory (vendor/rippled)
```

##### Option 2: installed rippled + find_package

First, follow the "Optional Installation" instructions above to
build and install the desired version of rippled.

To make use of the installed files, add the following to your CMakeLists.txt file:

```
set (CMAKE_MODULE_PATH /opt/local/lib/cmake/ripple ${CMAKE_MODULE_PATH})
find_package(Ripple REQUIRED)
```

change the `/opt/local` module path above to match your chosen installation prefix.

## Unit Tests (Recommended)

`rippled` builds a set of unit tests into the server executable. To run these unit
Expand Down
42 changes: 32 additions & 10 deletions Builds/macos/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,21 +142,17 @@ cd my_build
followed by:

```
cmake -G "Unix Makefiles" -Dtarget=clang.debug.unity ..
cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug ..
```

or

```
cmake -G "Ninja" -Dtarget=clang.debug.unity ..
cmake -G "Ninja" -DCMAKE_BUILD_TYPE=Debug ..
```

The target variable can be adjusted as needed for `gcc` vs `clang`, `debug` vs.
`release` and `unity` vs. `nounity` builds. `unity` builds are faster to
compile since they combine multiple sources into a single compiliation unit.
`nounity` builds can be helpful for detecting include omissions or for finding
other build-related issues, but aren't generally needed for testing and
running.
`CMAKE_BUILD_TYPE` can be changed as desired for `Debug` vs.
`Release` builds (all four standard cmake build types are supported).

Once you have generated the build system, you can run the build via cmake:

Expand Down Expand Up @@ -190,16 +186,42 @@ cmake --build . -- -jobs 4
This will invoke the `xcodebuild` utility to compile the project. See `xcodebuild
--help` for details about build options.

#### Optional installation

If you'd like to install the artifacts of the build, we have preliminary
support for standard CMake installation targets. We recommend explicitly
setting the installation location when configuring, e.g.:

```
cmake -DCMAKE_INSTALL_PREFIX=/opt/local ..
```

(change the destination as desired), and then build the `install` target:

```
cmake --build . --target install -- -jobs 4
```

#### Options During Configuration:

There are a number of config variables that our CMake files support. These
can be added to the cmake generation command as needed:
The CMake file defines a number of configure-time options which can be
examined by running `cmake-gui` or `ccmake` to generated the build. In
particular, the `unity` option allows you to select between the unity and
non-unity builds. `unity` builds are faster to compile since they combine
multiple sources into a single compiliation unit - this is the default if you
don't specify. `nounity` builds can be helpful for detecting include omissions
or for finding other build-related issues, but aren't generally needed for
testing and running.

* `-Dunity=ON` to enable/disable unity builds (defaults to ON)
* `-Dassert=ON` to enable asserts
* `-Djemalloc=ON` to enable jemalloc support for heap checking
* `-Dsan=thread` to enable the thread sanitizer with clang
* `-Dsan=address` to enable the address sanitizer with clang

Several other infrequently used options are available - run `ccmake` or
`cmake-gui` for a list of all options.

## Unit Tests (Recommended)

`rippled` builds a set of unit tests into the server executable. To run these unit
Expand Down
Loading