Enforce levelization in libxrpl with CMake (#5111)

Adds two CMake functions:

* add_module(library subdirectory): Declares an OBJECT "library" (a CMake abstraction for a collection of object files) with sources from the given subdirectory of the given library, representing a module. Isolates the module's headers by creating a subdirectory in the build directory, e.g. .build/tmp123, that contains just a symlink, e.g. .build/tmp123/basics, to the module's header directory, e.g. include/xrpl/basics, in the source directory, and putting .build/tmp123 (but not include/xrpl) on the include path of the module sources. This prevents the module sources from including headers not explicitly linked to the module in CMake with target_link_libraries.
* target_link_modules(library scope modules...): Links the library target to each of the module targets, and removes their sources from its source list (so they are not compiled and linked twice).

Uses these functions to separate and explicitly link modules in libxrpl:

    Level 01: beast
    Level 02: basics
    Level 03: json, crypto
    Level 04: protocol
    Level 05: resource, server
This commit is contained in:
John Freeman
2024-12-06 16:54:40 -06:00
committed by GitHub
parent 6d58065909
commit ea1fffeebf
61 changed files with 351 additions and 203 deletions

View File

@@ -20,9 +20,11 @@
#ifndef RIPPLE_BASICS_PARTITIONED_UNORDERED_MAP_H
#define RIPPLE_BASICS_PARTITIONED_UNORDERED_MAP_H
#include <xrpl/beast/hash/uhash.h>
#include <xrpl/beast/utility/instrumentation.h>
#include <functional>
#include <optional>
#include <string>
#include <thread>
#include <unordered_map>
#include <utility>
@@ -31,8 +33,18 @@
namespace ripple {
template <typename Key>
std::size_t
partitioner(Key const& key, std::size_t const numPartitions);
static std::size_t
extract(Key const& key)
{
return key;
}
template <>
inline std::size_t
extract(std::string const& key)
{
return ::beast::uhash<>{}(key);
}
template <
typename Key,
@@ -211,7 +223,7 @@ private:
std::size_t
partitioner(Key const& key) const
{
return ripple::partitioner(key, partitions_);
return extract(key) % partitions_;
}
template <class T>