-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
fix cmake install directory (for real this time) #944
Conversation
Why is the renaming from |
Since the code includes |
Sorry to ask so stupid questions... Why should the code include |
No worries :) The relative include directory issue mentioned in #928 is fixed by using "absolute" includes. But now that the source code is split, the compiler doesn't know where to find files included by So we have to correctly install files in Sorry if it's still confusing :/ |
Hm... I do not like the idea of changing the repository to make CMake happy. Is this possible without? |
It is not possible, it is forced by the includes and C++, not CMake. To make it less confusing, we could (again) rename And for users that are harcoding the |
Hm. So far, the location of the header was always |
It worked before by accident, because there was only one file. We were not including any other file, so include directories that we defined did not matter much. With #700, we included split headers relative to the directory where However, users who installed the project by running
User code: #include <nlohmann/json.hpp> User command line might look like:
And they will get something like that:
They could fix it by adding By including everything from the root folder (e.g. With that being saidThere is one way to fix it without changing the current include method though: // detail/meta.hpp
#include "../json_fwd.hpp" which is awful, or by adding a PS: I just thought about that after writing everything else... The latter approach will fix #928, but the questions raised in #942 remain. |
I also have to think about this in detail. I actually wanted to release 3.1.0 tomorrow... |
Ah, I think this is a mandatory issue for 3.1.0 :p |
As far as I can see, this issue only occurs when the CMake flag |
I have no idea how Catch2 is doing it, but there they have an |
Catch2 only has two headers exposed: I thought about two possible solutions: Each will prevent breakage for those who simply include "json.hpp", and will install the project with the following structure:
The First oneIt still needs the That way, we can use Second oneIf renaming the (Unless I missed something of course) |
The issue is that I do not want to adjust the repository to people's assumptions about how they can use the code in their CMake projects. This reminds me of the discussion that the repository is too large for people to use it as git submodule. So far, everything is fine, and now I see that adjustment of the repo is required to support the JSON_MultipleHeaders feature. Did I miss anything? |
I'm not proposing adjustments for CMake projects that include this library. They should use variables/targets defined in the My main issue is about making the |
Alright... I had a look at some other repositories. There seem to be three approaches:
I personally like the first approach The only "problem" left is what to do with the multiple-header version... |
So would it be possible to rename |
I'll go over all the arguments that have been discussed, in an attempt to be very clear. Current state (3.0.1)Since commit b1a2e9a by @robertmrk, there is a CMake
As you can see, Which means that anyone using this installation method must include it like this: #include <nlohmann/json.hpp> And add the following include directive: There was no need to have a Develop branch state (future 3.1.0)With PR #700, the source code is split in several headers, to ease development, and to permit users to only include files they need. The primary use-case being including There's two issues that arose with the split headers: How should they include each other?There is two ways, The second one is much more refactoring and maintenance proof, because the first one treats paths relatively to the current directory. That means that if This is, in my opinion, atrocious. I once had a project like that, and spent two days replacing relative includes with So the only way left is to use However, we need to decide the name of How should we name it then?I think we don't have a choice, here's why: Let's say we keep the It will build, run, pass tests on Travis etc... But, where do we install it? The CMake target used to install headers in the We don't want users to If we simply put Wrapping upThe only solution I see is to have an Frankly, I fail to understand how this can be an issue, the About the |
Thanks for the patience. I really appreciate this. My problem is that I never fully understood CMake, and now I am "forced" to make changes to the repository to "please" CMake. Even worse (for me), it seems I have to do it to support the (to me) rare use case of someone (1) wanting to use the non-single headers and (2) wants does not want to change the include code for this. I really need to sit down and better understand CMake until I am comfortable im making the required changes. As for the naming, I wonder why Catch can work with |
As I see in Catch2, all header files in internal/ never include anything from one-level up folder. However, the mutual includes between internal/*.hpp still exists with "xxx.hpp" naming. Therefore, even after moving everything to the In nlohmann/json, the headers in The workaround of adding |
No problem :)
Please not that this is not related to CMake, the same problem would arise with Autotools, Meson or any existing build system. It's compilers we're trying to make happy here.
I think @przemkovv explained well why we certainly do not want to have two include directives ( Also, it's the library's responsability to ensure such compatibility between single and multi-header versions. Indeed, even people who just include For Catch2, they only have one level of header nesting, and don't include files from parent directories. Note that installing Catch2 with CMake installs everything in a So you have to use |
So would moving json_fwd.hpp into the develop folder solve the issue? |
So we could fix this by renaming:
|
Would naming it |
@gregmarr Sure, the clearer the better.
It is already in the The fix is to rename:
I think there is no need to add a Also, the single header has most likely been drag-and-dropped as-is in some projects (e.g. at my work, we currently use |
I understand the idea of @gregmarr, but I think this is too conceptional. A final question: if we do not need So:
|
It would work too, it's just a matter of preference and clarity. It seems weird to me that a generated file is located in a But this could easily be changed later on if needed. |
Good argument! So let's do this:
|
Great, I'll rebase and push tomorrow morning :) |
Ok. Then I can prepare the release for tomorrow. |
Great conversation and agree with everything that has been said, I'm very happy this fix gets in. |
@patrikhuber I agree. |
It's not really necessary since we can still install But this might prevent drag and drop the I'll push in a few minutes. |
* Rename 'develop' folder to 'include/nlohmann' * Rename 'src' folder to 'single_include/nlohmann' * Use <nlohmann/*> headers in sources and tests * Change amalgamate config file
e77365f
to
14cd019
Compare
Here it is, I have installed with/without multiple headers. I've patched test files to include I haven't looked at the |
But it prevents using the single header from a submodule in a consistent way with |
I finally went with your suggestion, it makes everything easier, even in the CMake :) |
My 2 cents: I'm using I wonder how many users are doing like I do, compared to users who do |
@pboettch So what do you propose? |
What I tried to say is that maybe changing the paths inside this repo (and thus maybe breaking compatibility) is not a big deal, because only a few people are using it directly as compared to the multiple 10k (!) non-contributing/silent users who just use In the intro-animation I read "What if JSON would be part of modern C++?" I hear would be part of standard C++ libraries. I'd expect to be able to do: #include <json_fwd> in header-files and in source-files #include <json> (similarly to and this is exactly what I'm doing in my project(s) (*), I place the library's files so that exactly that works and I'm adding (*) - I'm not yet using |
I'm not sure following the C++ standard include model is a good idea. The main point in having a top-level directory to include is to avoid clashes. This library is not part of the standard, we cannot assume that |
@theodelrieu I see your point. A more generic approach then would be to prefix with And that was exactly my original motivation when entering this discussion. I think there is no problem with moving files inside the repo to be coherent. |
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.
Should fix #928 and #942.
Pull request checklist
Read the Contribution Guidelines for detailed information.
develop
directory, runmake amalgamate
to create the single-header filesrc/json.hpp
. The whole process is described here.Please don't
#ifdef
s or other means.