From 658eb73e00c6e89841cc771154e976f6c641d38b Mon Sep 17 00:00:00 2001 From: Denis Angell Date: Wed, 16 Apr 2025 11:29:35 +0200 Subject: [PATCH] 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. --- Builds/CMake/RippledCore.cmake | 5 +++++ conanfile.py | 13 +++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/Builds/CMake/RippledCore.cmake b/Builds/CMake/RippledCore.cmake index 142409bc0..92593d538 100644 --- a/Builds/CMake/RippledCore.cmake +++ b/Builds/CMake/RippledCore.cmake @@ -23,6 +23,11 @@ else() message(STATUS "ACL not found, continuing without ACL support") endif() +add_library(libxrpl INTERFACE) +target_link_libraries(libxrpl INTERFACE xrpl_core) +add_library(xrpl::libxrpl ALIAS libxrpl) + + #[===============================[ beast/legacy FILES: TODO: review these sources for removal or replacement diff --git a/conanfile.py b/conanfile.py index b27b769c8..9dea082ff 100644 --- a/conanfile.py +++ b/conanfile.py @@ -1,4 +1,4 @@ -from conans import ConanFile +from conan import ConanFile from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout import re @@ -109,7 +109,9 @@ class Xrpl(ConanFile): 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) @@ -143,8 +145,11 @@ class Xrpl(ConanFile): 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']