-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
Export package to allow builds without installing #1202
Conversation
I have little experience with CMake, so I do not just want to merge this PR without understanding it. However, I fail to reproduce the issue. Could you provide a minimal CMakeLists.txt file that demonstrates the issue with the current |
Note: If you fail to reproduce the example, make sure that the json package is not present in the local registry. At least remove I've created a minimal example. It's at https://github.com/dennisfischer/example-json In general, a call to However, in certain cases you do not want or cannot have dependencies installed, i.e. the entries for Master branch creates following error during configuration:
We see that cmake finds the uses the Note that the In contrast to the main branch, the subdirectory branch contains the json repository with my commit included, i.e.
|
Thanks so much for this comprehensive answer! Indeed, there were leftovers in my |
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.
Looks good to me.
Thanks a lot! |
This pull requests modifies the CMakeLists.txt to export the package.
Problem:
As of right now, the repository needs to be installed such that
find_package(nlohmann_json)
can be used. This creates a problem if this project is used as a git submodule or if it is used without installing. Example: This repository is cloned to a folder namedproject/json/
. In the root directory of the project the CMakeLists.txt is changed to include the json folder by addingadd_subdirectory(json)
. However, because the json project does not export the package the call tofind_package(..)
fails.Solution:
Export the package
export(PACKAGE ${PROJECT_NAME})
.Pull request checklist
Read the Contribution Guidelines for detailed information.
include/nlohmann
directory, runmake amalgamate
to create the single-header filesingle_include/nlohmann/json.hpp
. The whole process is described here.