mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-05 03:35:51 +00:00
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
49 lines
1.4 KiB
CMake
49 lines
1.4 KiB
CMake
include(create_symbolic_link)
|
|
|
|
# Consider include directory B nested under prefix A:
|
|
#
|
|
# /path/to/A/then/to/B/...
|
|
#
|
|
# Call C the relative path from A to B.
|
|
# C is what we want to write in `#include` directives:
|
|
#
|
|
# #include <then/to/B/...>
|
|
#
|
|
# Examples, all from the `jobqueue` module:
|
|
#
|
|
# - Library public headers:
|
|
# B = /include/xrpl/jobqueue
|
|
# A = /include/
|
|
# C = xrpl/jobqueue
|
|
#
|
|
# - Library private headers:
|
|
# B = /src/libxrpl/jobqueue
|
|
# A = /src/
|
|
# C = libxrpl/jobqueue
|
|
#
|
|
# - Test private headers:
|
|
# B = /tests/jobqueue
|
|
# A = /
|
|
# C = tests/jobqueue
|
|
#
|
|
# To isolate headers from each other,
|
|
# we want to create a symlink Y that points to B,
|
|
# within a subdirectory X of the `CMAKE_BINARY_DIR`,
|
|
# that has the same relative path C between X and Y,
|
|
# and then add X as an include directory of the target,
|
|
# sometimes `PUBLIC` and sometimes `PRIVATE`.
|
|
# The Cs are all guaranteed to be unique.
|
|
# We can guarantee a unique X per target by using
|
|
# `${CMAKE_CURRENT_BINARY_DIR}/include/${target}`.
|
|
#
|
|
# isolate_headers(target A B scope)
|
|
function(isolate_headers target A B scope)
|
|
file(RELATIVE_PATH C "${A}" "${B}")
|
|
set(X "${CMAKE_CURRENT_BINARY_DIR}/modules/${target}")
|
|
set(Y "${X}/${C}")
|
|
cmake_path(GET Y PARENT_PATH parent)
|
|
file(MAKE_DIRECTORY "${parent}")
|
|
create_symbolic_link("${B}" "${Y}")
|
|
target_include_directories(${target} ${scope} "$<BUILD_INTERFACE:${X}>")
|
|
endfunction()
|