Skip to content

Commit

Permalink
document cmake install setup
Browse files Browse the repository at this point in the history
  • Loading branch information
Wumpf committed Nov 23, 2023
1 parent 502f81f commit adeb5c2
Showing 1 changed file with 44 additions and 5 deletions.
49 changes: 44 additions & 5 deletions docs/content/reference/cpp-sdk-cmake.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ The Rerun C++ SDK is meant to be built from source and everything described on t
Its [CMake build script](https://github.com/rerun-io/rerun/blob/latest/rerun_cpp/CMakeLists.txt)
is ready to be used from outside of the Rerun repo.

## Adding with FetchContent
# Ways of building & using rerun_sdk

The easiest way to add Rerun to your project is using `FetchContent`:
## Download & build via `FetchContent`

By far the easiest way to add Rerun to your project is using `FetchContent`:
```cmake
include(FetchContent)
FetchContent_Declare(rerun_sdk URL
Expand All @@ -19,9 +21,12 @@ FetchContent_MakeAvailable(rerun_sdk)

This will download a bundle with pre-built Rerun C static libraries for most desktop platforms,
all Rerun C++ sources and headers, as well as CMake build instructions for them.
By default this will also download & build [Apache Arrow](https://arrow.apache.org/)'s C++ library which is required to build the Rerun C++. See [Install arrow-cpp](../howto/arrow-cpp-install.md) to learn more about this step and how to use an existing install.
By default this will also download & build [Apache Arrow](https://arrow.apache.org/)'s C++ library which is required to build the Rerun C++. See [Install arrow-cpp](../howto/arrow-cpp-install.md) to learn more about this step and how to use an existing install.

We recommend this `FetchContent` workflow for all usecases since it is the easiest and works without any additional configuration.

Check warning on line 26 in docs/content/reference/cpp-sdk-cmake.md

View workflow job for this annotation

GitHub Actions / Spellcheck

Unknown word (usecases)
All other workflows and configuration are there to best address more specific needs a project setup may haves.

## Adding via subdirectory
## From rerun repository via `add_subdirectory`

Alternatively, you can add the source of `https://github.com/rerun-io/rerun/blob/latest/rerun_cpp/` directly to your own
project and then use `add_subdirectory`.
Expand All @@ -43,12 +48,44 @@ before adding the subdirectory.
but also make additional assumptions about your build environment. For example it will always try to build
`rerun_c` (which the C++ SDK depends on) from its Rust source.

## CMake configuration options
## CMake install for `rerun_sdk`

If you want to pre-build `rerun_sdk` for use with a different build system, or simply have a lot of projects using the same
`rerun_sdk`, it can be useful to use CMake's install command to install a re-usable version of `rerun_sdk` on your system.

To do so, follow these following steps:
* Download and unpack the desired `rerun_cpp_sdk.zip` (e.g https://github.com/rerun-io/rerun/releases/latest/download/rerun_cpp_sdk.zip for the latest version)
* In the directory of the unpacked `rerun_cpp_sdk` run:
* Configure:
* `cmake -B build -S . -DCMAKE_BUILD_TYPE=Release`

Check warning on line 60 in docs/content/reference/cpp-sdk-cmake.md

View workflow job for this annotation

GitHub Actions / Spellcheck

Unknown word (DCMAKE)
* Build:
* `cmake --build build --config Release --target rerun_sdk`
* Install:
* `cmake --install build`
* make sure you have permissions or use a target path, e.g. `--prefix ../rerun_sdk_install`
* Now that you have an install you can use `find_package(rerun_sdk REQUIRED)` in your project
* Make sure that the prefix path or the rerun_sdk location is correctly configured.
* Depending on your install path and OS this may work out of the box or require setting additional CMake variables (e.g. `-DDCMAKE_PREFIX_PATH=rerun_sdk_install`)

Check warning on line 68 in docs/content/reference/cpp-sdk-cmake.md

View workflow job for this annotation

GitHub Actions / Spellcheck

Unknown word (DDCMAKE)

The exact CMake invocations may need to be adjusted for your needs.

Naturally, you can also integrate `rerun_sdk`'s install into the install of your own libraries and executables.
This is generally only recommended for more advanced CMake setups.

As mentioned previously, by default Rerun's CMake script will download and build Arrow during its build.
Unless configured otherwise (see below) the resulting libraries are part of the `rerun_sdk` install.
⚠️ This does currently not work for dynamic arrow libraries, i.e. if either one of
`RERUN_DOWNLOAD_AND_BUILD_ARROW=OFF` or `RERUN_ARROW_LINK_SHARED=ON` is set,
the install will use `find_package(Arrow)` to locate the Arrow library on your system.

# CMake configuration options

The C++ SDK provides a handful of configuration options.
All of them come with meaningful defaults, so typically you don't have to change any of them,
but they provide important hooks for more complex build setups.

Unless noted otherwise, a CMake install of `rerun_sdk` does **not** expose any of these options.

### `RERUN_DOWNLOAD_AND_BUILD_ARROW`
If enabled, will download a pinned version of the Apache Arrow C++ library and add it to the build.
Otherwise, `find_package` will be used to search for a pre-installed Arrow library.
Expand All @@ -65,6 +102,8 @@ Although enabling shared libraries makes linking faster and reduces binary size,
related to locating the shared libraries at runtime. Depending on your system configuration it is even possible
to pick up a system-version of Arrow instead of the one you built against.

`rerun_sdk` installs that use a system installed Arrow library, can be configured using this option as well.

### `RERUN_C_LIB`
Path to the static Rerun C library to link against.

Expand Down

0 comments on commit adeb5c2

Please sign in to comment.