-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enforce levelization in libxrpl with CMake #5111
Open
thejohnfreeman
wants to merge
15
commits into
XRPLF:develop
Choose a base branch
from
thejohnfreeman:levels
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+364
−214
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
e364dbd
Enforce levelization with CMake
thejohnfreeman 3560a56
Merge branch 'develop'
thejohnfreeman 1368e2b
Merge branch 'develop'
thejohnfreeman 4e11039
Rename module isolation directory
thejohnfreeman e0f3c56
Disable private headers for libxrpl
thejohnfreeman cbdd49f
Merge branch 'develop'
thejohnfreeman 947440a
Disable non-module headers for libxrpl
thejohnfreeman 529af81
Merge branch 'develop'
thejohnfreeman 0929033
Merge branch 'develop'
thejohnfreeman b0a2105
Fix symlinks on non-admin Windows
thejohnfreeman 9cd6f06
Merge branch 'develop'
thejohnfreeman 8890adc
Fix symbolic links of install
thejohnfreeman 0e11fa7
Merge branch 'develop'
thejohnfreeman 1f953dc
Merge branch 'develop'
thejohnfreeman ad16bbd
Move IOUAmount from basics module to protocol
thejohnfreeman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,37 @@ | ||
include(isolate_headers) | ||
|
||
# Create an OBJECT library target named | ||
# | ||
# ${PROJECT_NAME}.lib${parent}.${name} | ||
# | ||
# with sources in src/lib${parent}/${name} | ||
# and headers in include/${parent}/${name} | ||
# that cannot include headers from other directories in include/ | ||
# unless they come through linked libraries. | ||
# | ||
# add_module(parent a) | ||
# add_module(parent b) | ||
# target_link_libraries(project.libparent.b PUBLIC project.libparent.a) | ||
function(add_module parent name) | ||
set(target ${PROJECT_NAME}.lib${parent}.${name}) | ||
add_library(${target} OBJECT) | ||
file(GLOB_RECURSE sources CONFIGURE_DEPENDS | ||
"${CMAKE_CURRENT_SOURCE_DIR}/src/lib${parent}/${name}/*.cpp" | ||
) | ||
target_sources(${target} PRIVATE ${sources}) | ||
target_include_directories(${target} PUBLIC | ||
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>" | ||
) | ||
isolate_headers( | ||
${target} | ||
"${CMAKE_CURRENT_SOURCE_DIR}/include" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/include/${parent}/${name}" | ||
PUBLIC | ||
) | ||
isolate_headers( | ||
${target} | ||
"${CMAKE_CURRENT_SOURCE_DIR}/src" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/src/lib${parent}/${name}" | ||
PRIVATE | ||
) | ||
Bronek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
endfunction() |
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,20 @@ | ||
# file(CREATE_SYMLINK) only works on Windows with administrator privileges. | ||
# https://stackoverflow.com/a/61244115/618906 | ||
function(create_symbolic_link target link) | ||
if(WIN32) | ||
if(NOT IS_SYMLINK "${link}") | ||
if(NOT IS_ABSOLUTE "${target}") | ||
# Relative links work do not work on Windows. | ||
set(target "${link}/../${target}") | ||
endif() | ||
file(TO_NATIVE_PATH "${target}" target) | ||
file(TO_NATIVE_PATH "${link}" link) | ||
execute_process(COMMAND cmd.exe /c mklink /J "${link}" "${target}") | ||
endif() | ||
else() | ||
file(CREATE_LINK "${target}" "${link}" SYMBOLIC) | ||
endif() | ||
if(NOT IS_SYMLINK "${link}") | ||
message(ERROR "failed to create symlink: <${link}>") | ||
endif() | ||
endfunction() |
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,48 @@ | ||
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() |
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,24 @@ | ||
# 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() |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be even nicer if you could optionally pass the libraries to link the target with right here too? Is it possible to add the
PUBLIC lib1 lib2
through args somehow?