-
Notifications
You must be signed in to change notification settings - Fork 15
cmake: export into build directory #27
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
cmake: export into build directory #27
Conversation
|
@1uc, would you mind having a look? (You appeared at the top of the contributors list ;)) |
|
There's a reasonably large set of ways we test that integration of HighFive into other projects works: Clearly, we're missing something. @dglaeser could you please provide a sketch of a minimal CMakeLists.txt that exhibits the issue? If we're to support FetchContent it seems prudent to also check it in future. |
|
@1uc thanks a lot for your quick reply! I have compiled a minimal working example: See the Let me know if this is helpful. |
As far as I recall when making these changes, the first error I got was when the downstream project creates an export set, it then complained that HighFive wouldn't be in any export set (you should see this error when you use my script with the current main branch of HighFive). At first glance it seems to me that this should be covered in your cmake integration tests, not sure yet why this doesn't seem to pop up on your end. The solution was to have the config file in the build directory upon configuration (the added The other issues we faced were related to shipping HighFive alongside a downstream project and integrating it yet further downstream. Your integration tests probably only cover direct dependencies?
|
|
Thank you, this is very helpful! I think I see what's happening; and while we do test that libraries can be installed and used, we only check this for libraries that themselves use I was never sure if a library could sensibly install HighFive, and I'm still not fully convinced. (Except if Thank you for the nice fix. |
|
@dglaeser I replaced the use of GNUInstallDirs with a variable (similar to what nlohmann/json) does. The default is what it would have been with GNUInstallDirs, i.e. I noticed that all the breakage happens because I wasn't aware the CMake can use build directories (and not only install directories) as the source for dependencies of downstream projects. Is there a (particularly) convincing reason to do so? I'm wondering if I've been missing out of something. |
|
@dglaeser to me it looks mergable, thank you for your work! Please let me know if you want to test the small change to make sure it's compatible with your code. |
CMakeLists.txt
Outdated
|
|
||
| option(HIGHFIVE_FIND_HDF5 "Find and link with HDF5." On) | ||
|
|
||
| set(HIGHFIVE_CMAKE_INSTALL_DIR "share/HighFive/cmake" CACHE STRING |
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.
Small nitpick: we originally had lib/cmake/HighFive...
I personally feel that swapping the order will make the share directory a bit more manageable.
| set(HIGHFIVE_CMAKE_INSTALL_DIR "share/HighFive/cmake" CACHE STRING | |
| set(HIGHFIVE_CMAKE_INSTALL_DIR "share/cmake/HighFive" CACHE STRING |
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.
If I look at say /usr/share, mine looks something like this:
$ ls -1 /usr/share
aclocal
alsa
autoconf
avahi
awk
... and indeed somewhere in there I find:
$ ls -1 /usr/share/cmake/
nlohmann_json
TBB
(and a small number of others). While,
$ ls -1 /usr/share/*/cmake/
/usr/share/eigen3/cmake:
Eigen3Config.cmake
...
and maybe one or two more. Neither seems to be popular.
On this system the overwhelming majority of libraries put their CMake stuff in /lib/cmake/<name> (like we did before). Maybe we just revert back to the old location, but keep the variable, then everyone can put it where they like.
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.
Come to think of it, lib seems more appropriate - that is also where pkgconfig canonically seems to expect its library configuration files. The share/cmake would also host the CMake internals (at least on my system)
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.
Thanks a lot for the comments! I just checked again where cmake looks for config files in calls to find_package in config mode, and it seems that it looks in a relatively large number of places: https://cmake.org/cmake/help/latest/command/find_package.html#config-mode-search-procedure
So I guess lib/cmake/<name> should be fine as well as all the other options that came up as far as I can see. Sorry for making this change too hasty, didn't seem necessary.
The share/cmake would also host the CMake internals (at least on my system)
Yes that's why I originally used share/<name>/cmake (although share came from CMAKE_INSTALL_DATAROOTDIR)
So the issue with the build directory came up in a use case of one of our users: dglaeser/gridformat#299 They have a modular code framework with several core modules and a whole ecoystem of optional modules, each of which is defined in a separate repository. But all of these must be configured together so that (for development) code edits in any of the modules would retrigger any affected target to be rebuilt. Their use case required us to add the possibility to link against the build directory (i.e. export the targets into the build dir), we also didn't consider that originally. But since it only involved one additional export and had no negative side effects on our originally considered use cases, we just added it. I also saw that in On our end, after dglaeser/gridformat#299 was reported, we discussed whether we should stop including
Yes you're right. The first issue I mention in my comment above (#27 (comment)) also would not appear if the In fact, I think both branch, the PR and the description are misnomers. |
I tested it, still works fine, thanks! |
|
@dglaeser thank you for the detailed explanations; and I'm happy you decided to report the issue with a fix. The usecase you describe makes sense and I see no reason to prevent it. The removal of
I looked at this, and agree, in our case the point of calling The PR is fine like this, because it'll get squash merged and I'll be asked to edit the commit message anyway. (Github seems to be wonky, right now and isn't picking up the 6th commit. So we'll let it sit a little until that sorts itself out.) |
|
@1uc, ok great! Thanks a lot for your help on this! |
|



We are using highfive in a downstream repository, either via cmake's
fetchcontentor by including it in the build viaadd_subdirectory. Both approaches worked for us with older versions, but with the currentmainwe run into several issues.With the changes in the PR we have tested the following scenarios, which failed without these changes:
HighFivein the build of a downstream project, linking against that one - in the build directory; without installation - in yet another downstream projectHighFivein the build of a downstream project, installing it into some non-standard location, and then consuming the downstream project in yet another downstream project by usingfind_packagewith-Ddownstream_ROOT=....