mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-04 19:25: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
25 lines
984 B
CMake
25 lines
984 B
CMake
# Link a library to its modules (see: `add_module`)
|
|
# and remove the module sources from the library's sources.
|
|
#
|
|
# add_module(parent a)
|
|
# add_module(parent b)
|
|
# target_link_libraries(project.libparent.b PUBLIC project.libparent.a)
|
|
# add_library(project.libparent)
|
|
# target_link_modules(parent PUBLIC a b)
|
|
function(target_link_modules parent scope)
|
|
set(library ${PROJECT_NAME}.lib${parent})
|
|
foreach(name ${ARGN})
|
|
set(module ${library}.${name})
|
|
get_target_property(sources ${library} SOURCES)
|
|
list(LENGTH sources before)
|
|
get_target_property(dupes ${module} SOURCES)
|
|
list(LENGTH dupes expected)
|
|
list(REMOVE_ITEM sources ${dupes})
|
|
list(LENGTH sources after)
|
|
math(EXPR actual "${before} - ${after}")
|
|
message(STATUS "${module} with ${expected} sources took ${actual} sources from ${library}")
|
|
set_target_properties(${library} PROPERTIES SOURCES "${sources}")
|
|
target_link_libraries(${library} ${scope} ${module})
|
|
endforeach()
|
|
endfunction()
|