-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: add interface library libxrpl: (#4449)
Make it easy for projects to depend on libxrpl by adding an `ALIAS` target named `xrpl::libxrpl` for projects to link. The name was chosen because: * The current library target is named `xrpl_core`. There is no other "non-core" library target against which we need to distinguish the "core" library. We only export one library target, and it should just be named after the project to keep things simple and predictable. * Underscores in target or library names are generally discouraged. * Every target exported in CMake should be prefixed with the project name. By adding an `ALIAS` target, existing consumers who use the `xrpl_core` target will not be affected. * In the future, there can be a migration plan to make `xrpl_core` the `ALIAS` target (and `libxrpl` the "real" target, which will affect the filename of the compiled binary), and eventually remove it entirely. Also: * Fix the Conan recipe so that consumers using Conan import a target named `xrpl::libxrpl`. This way, every consumer can use the same instructions. * Document the two easiest methods to depend on libxrpl. Both have been tested. * See #4443.
- Loading branch information
1 parent
7745c72
commit d772583
Showing
3 changed files
with
111 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ |