-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Add support to use system provided nlohmann_json library if requested #14155
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
Open
rhabacker
wants to merge
2
commits into
IntelRealSense:development
Choose a base branch
from
rhabacker:system-nlohmann-json
base: development
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.
Open
Changes from all commits
Commits
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 hidden or 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 hidden or 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 hidden or 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.
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.
Did you check that this actually changes what is used?
(The lz4 option is not enough to keep the build from using the vendored headers, #13803 (comment))
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.
I assume you are refering to this statement at
librealsense/third-party/rsutils/CMakeLists.txt
Line 7 in 6dcf714
Normally as the nlohmann_json library provides a cmake target required include directories are added out of the box, but after uncommenting
I get
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.
According to https://stackoverflow.com/questions/5378528/install-export-problem-for-library-with-dependencies#comment134383587_71080574 the reason for this problem is that rsutils is built and installed as a static library, which requires the export of all dependent libraries.
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.
No. I refer to what kind of
#includestatements actually refer to nlohmann-json headers. See my linked comment for how devendoring is currently incomplete for lz4.(Maybe that comment refers to an old installation which doesn't have nlohmann-json.)
Actually pretty standard situation, and not related to your change. When the exported interface of a build target (rsutils) refers to another build target (nlohmann_json), the other target must be exported to.
Your change introduces a similar problem but with another imported target. You must use
find_dependencyor similar in the installed config file when an exported interface refers to an imported target.Unless you take more control of the exported interface:
PUBLIClink library? This implies downstream use for include dirs, so it introduces a dependency regardless of dynamic or static libs.PRIVATEwould reduce the exported transitive dependency to a link-only property for static libs.$<BUILD_ONLY:...>link lib, not being exported with CMake config.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.
This change (without the cmake option) has been used to build binaries at https://build.opensuse.org/package/show/hardware/librealsense since 2024-09-30.
Uh oh!
There was an error while loading. Please reload this page.
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.
Using an external package is a must, as cmake has no internet access to fetch data, at least on remote build systems like build.opensuse.org.
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.
I'm familiar with DEB and RPM packaging on build.opensuse.org. And with CMake and vcpkg. In fact, the vcpkg port is even more aggressive in devendoring ATM.
In this PR, the result of
find_packageisn't used. It has no effect on the include dirs. This is a problem when you don't want to use or install nlohmann-json in standard system locations.Uh oh!
There was an error while loading. Please reload this page.
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.
Using nlohmann as an external package creates in /usr/lib64/cmake/nlohmann_json/nlohmann_jsonConfig.cmake
Include directories are defined in /usr/lib64/cmake/nlohmann_json/nlohmann_jsonTargets.cmake
The package is movable (by IMPORT_PREFIX) and should therefore provide correct include paths when moved to another location. Have I overlooked something?
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.
You overlooked that nothing here makes use of the imported variables and properties.
Nothing is added to the actual include dirs of the build.
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.
When using the embedded nlohman_json library the same target is created, so it would be addable as private library too, but it cannot be added to rsutils because it takes place before the definition of nlohman_json and therefore cannot be found, see
librealsense/third-party/CMakeLists.txt
Line 4 in 6dcf714
librealsense/third-party/CMakeLists.txt
Line 8 in 6dcf714
After switching the order, nlohmann_json can be added as private library in both cases.