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

Make it easy for projects to depend on libxrpl #4449

Merged
merged 3 commits into from
Mar 23, 2023
Merged
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
4 changes: 4 additions & 0 deletions Builds/CMake/RippledCore.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ if (unity)
set_target_properties(xrpl_core PROPERTIES UNITY_BUILD ON)
endif ()

add_library(libxrpl INTERFACE)
target_link_libraries(libxrpl INTERFACE xrpl_core)
add_library(xrpl::libxrpl ALIAS libxrpl)


#[===============================[
beast/legacy FILES:
Expand Down
13 changes: 9 additions & 4 deletions conanfile.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from conans import ConanFile
from conan import ConanFile
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
import re

Expand Down Expand Up @@ -108,7 +108,9 @@ def requirements(self):
if self.options.rocksdb:
self.requires('rocksdb/6.27.3')

exports_sources = 'CMakeLists.txt', 'Builds/CMake/*', 'src/*', 'cfg/*'
exports_sources = (
'CMakeLists.txt', 'Builds/*', 'bin/getRippledInfo', 'src/*', 'cfg/*'
)

def layout(self):
cmake_layout(self)
Expand Down Expand Up @@ -142,8 +144,11 @@ def package(self):
cmake.install()

def package_info(self):
self.cpp_info.libs = [
libxrpl = self.cpp_info.components['libxrpl']
libxrpl.libs = [
'libxrpl_core.a',
'libed25519-donna.a',
'libed25519.a',
'libsecp256k1.a',
]
libxrpl.includedirs = ['include']
libxrpl.requires = ['boost::boost']
98 changes: 98 additions & 0 deletions docs/build/depend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
We recommend two different methods to depend on libxrpl in your own [CMake][]
project.
Both methods add a CMake library target named `xrpl::libxrpl`.


## Conan requirement

The first method adds libxrpl as a [Conan][] requirement.
With this method, there is no need for a Git [submodule][].
It is good for when you just need a dependency on libxrpl as-is.

```
# This conanfile.txt is just an example.
[requires]
xrpl/1.10.0

[generators]
CMakeDeps
CMakeToolchain
```

```
# If you want to depend on a version of libxrpl that is not in ConanCenter,
# then you can export the recipe from the rippled project.
conan export <path>
```

```cmake
# Find and link the library in your CMake project.
find_package(xrpl)
target_link_libraries(<target> PUBLIC xrpl::libxrpl)
```

```
# Download, build, and connect dependencies with Conan.
mkdir .build
cd .build
mkdir -p build/generators
conan install \
--install-folder build/generators \
--build missing \
--settings build_type=Release \
..
cmake \
-DCMAKE_TOOLCHAIN_FILE=build/generators/conan_toolchain.cmake \
-DCMAKE_BUILD_TYPE=Release \
..
cmake --build . --parallel
```


## CMake subdirectory

The second method adds the [rippled][] project as a CMake
[subdirectory][add_subdirectory].
This method works well when you keep the rippled project as a Git
[submodule][].
It's good for when you want to make changes to libxrpl as part of your own
project.
Be careful, though.
Your project will inherit all of the same CMake options,
so watch out for name collisions.
We still recommend using [Conan][] to download, build, and connect dependencies.

```
# Add the project as a Git submodule.
mkdir submodules
git submodule add https://github.com/XRPLF/rippled.git submodules/rippled
```

```cmake
# Add and link the library in your CMake project.
add_subdirectory(submodules/rippled)
target_link_libraries(<target> PUBLIC xrpl::libxrpl)
```

```
# Download, build, and connect dependencies with Conan.
mkdir .build
cd .build
conan install \
--output-folder . \
--build missing \
--settings build_type=Release \
../submodules/rippled
cmake \
-DCMAKE_TOOLCHAIN_FILE=build/generators/conan_toolchain.cmake \
-DCMAKE_BUILD_TYPE=Release \
..
cmake --build . --parallel
```


[add_subdirectory]: https://cmake.org/cmake/help/latest/command/add_subdirectory.html
[submodule]: https://git-scm.com/book/en/v2/Git-Tools-Submodules
[rippled]: https://github.com/ripple/rippled
[Conan]: https://docs.conan.io/
[CMake]: https://cmake.org/cmake/help/latest/