-
Notifications
You must be signed in to change notification settings - Fork 263
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 targets so the build directory can be used directly #2774
Conversation
We historically discourage people from using the build directory directly, and encourage people to use the install directory instead; this has been a best practice for a very long time. I'm not opposed to making it easier for people to use their |
The major reason to enable using the build directory directly is to allow embedding in another project, for example as part of a superbuild or a bundled dependency. There are at least a couple of ways to do this in practice, either with a git submodule (or just bundled) and Basically, in modern CMake, it's a really nice user experience to be able to use the build directory for a project, as well as installing it.
Sorry, I was not very clear here! Just so we're all on the same page (and for others reading this), pre-CMake 3 and the introduction of targets, the standard way of using a dependency was with variables like So, if we delete the It is possible to keep the variables, but it would involve generating the config file twice, once for the build directory, once for the install directory. Not a problem, it's just more code to do so!
Nope! Just adds another way to consume netCDF |
I don't think that this will address using Regardless, this change is still necessary to do functional tests of examples, e.g. to test the packaging example. If you want to address
|
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.
There is also configure_package_config_file
which seems excessive with
PATH_VARS
CMAKE_INSTALL_PREFIX
CMAKE_INSTALL_INCLUDEDIR
CMAKE_INSTALL_LIBDIR
And since it uses PACKAGE_INIT
it should no have NO_CHECK_REQUIRED_COMPONENTS_MACRO
Otherwise, functionally 👍 this PR should work as is
Fixes comments from review
* main: (110 commits) Escape a character causing a doxygen error. Updated release notes. Added a comment block for future reference. more syntax fixes Update CMakeLists.txt CMake: Find HDF5 header we can safely include for other checks moving functions and macros to new file, lowercase things Update release notes. lowercase lower case lowercase moving functions and macros to a file moving the dependencies inclusion CMake: Add support for UNITY_BUILD removing debug messages actually adding the dependencies file... putting dependencies into separate file Define USE_SZIP variable for nc-config.cmake.in matching cmake variables in autotools configuration moving the version into the project command in cmake ...
Thanks for the comments here @LecrisUT!
Previously, I was just checking that include(FetchContent)
FetchContent_Declare(
netcdf
GIT_REPOSITORY https://github.com/ZedThree/netcdf-c
GIT_TAG 25dc1faa603ff885197cbc09983ecb848f570470
)
set(ENABLE_TESTS OFF CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(netcdf)
(+ commenting out the existing machinery for finding This does work, but I did also have to turn off tests in
This is a good idea! Worth adding here, or in a separate PR perhaps? Ideally, I guess this sort of test would check several ways of consuming the package (build dir vs install, for example).
I think @K20shores is already looking into most of these? The |
Just some short clarifications:
FetchContent has different inclusion methods, i.e. it uses
All except for install. For that one I run tests on Fedora packaging on top of that (which calls the same test-suite). See the
Not really, the workaround is a bit verbose but this one you can support both versions with policy |
@ZedThree yes, I am looking into those things you mentioned |
Along with #2751, this fully enables using the build directory directly in other projects, allowing other projects to include netCDF using things like
FetchContent
.I've had to delete the paths in
netCDFConfig.cmake.in
because they won't exist until netCDF is installed (sort of defeating the point of using the build directory!) -- this should be fine as long as people are using thenetCDF::netcdf
target rather than these variables. It might be possible to support both, but it might get a bit complicated!