-
Notifications
You must be signed in to change notification settings - Fork 188
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
[REVIEW] cmake: prefer locally installed thirdparty packages #572
Conversation
The main thing here is that the file is now included, rather than pulled in via add_subdirectory(). The intended consequence of that is that it's not executed in a separate scope, so that `find_package()`, or rather its wrapped form `CPMFindPackage()` will work properly. The one change after the move is removing the `PARENT_SCOPE` from setting `THRUST_INCLUDE_DIR`, since it's now running in the parent scope.
This will prefer using a locally installed version of spdlog -- only if that cannot be found will it download its own copy.
This works relatively easily, since new googletest comes with its own cmake config. In the case where CPM pulls it in via add_subdirectory, we have to create appropriate aliases to the new namespaced names.
Can one of the admins verify this patch? |
1 similar comment
Can one of the admins verify this patch? |
ok to test |
In the CI, it picked up spdlog and gtest, so success so far ;) -- CPM: using local package spdlog@1.7.0
-- CPM: adding package thrust@1.10.0 (1.10.0)
-- CPM: using local package GTest@1.10.0 |
@@ -27,7 +27,7 @@ function(ConfigureBench CMAKE_BENCH_NAME CMAKE_BENCH_SRC) | |||
set_target_properties(${CMAKE_BENCH_NAME} PROPERTIES POSITION_INDEPENDENT_CODE ON) | |||
target_include_directories(${CMAKE_BENCH_NAME} PRIVATE "$<BUILD_INTERFACE:${RMM_SOURCE_DIR}>") | |||
|
|||
target_link_libraries(${CMAKE_BENCH_NAME} benchmark pthread rmm) | |||
target_link_libraries(${CMAKE_BENCH_NAME} benchmark::benchmark pthread rmm) |
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.
Is the benchmark::benchmark
target consistent whether the package is found or added?
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.
Yes, both spdlog and benchmark provide namespaced targets when used via add_subdirectory
. gtest does not, that's why I added the aliases myself.
But I guess it brings up a good point, that is, the CI will not catch if things don't work with downloaded packages. You could add more CI checks that run with CPM_DOWNLOAD_ALL=ON
, that would catch errors on that end.
@harrism can you take a look as well before we merge? |
@germasch after this PR and after building multiple times, I see
Why does it only find local packages for spdlog and gtest? |
It will only say |
For benchmark, I suppose because it's not installed in the environment. I can add it to the For thrust, I'm still working on how to best do handle an external thrust install in the first place, so it's not even trying yet. |
Benchmarks don't look like they're currently being built in CI so it's not trying to grab benchmark at all. @harrism was that from your local dev in rapids-compose? What does |
benchmark doesn't need to be in conda. I am surprised gtest is there. I just thought these would get cached somewhere after the first time they are fetched. Thought that was an advantage of CPM. |
|
They are cached, it will just only say It will say |
Looks like our conda package has the wrong version of benchmark as compared to CPM which is why CPM isn't finding it locally. |
Well, so for one, we ask for 1.5.2. (Which should exist in conda). The other potential issue is that there's at least one bug in what benchmark itself thinks its version is: google/benchmark#1045. There may be something else off -- could you look where benchmark is installed, |
Thrust takes significant time, so it doesn't seem cached... |
Not sure where to find that path. |
If you set |
Is that a cmake variable or an env variable? |
Wherever conda installs its packages. |
We should document this. |
Either works. |
|
0.0.0 apparently. :) |
Yeah, that's what I was afraid of -- that's what happens in |
FWIW, google benchmark releases will hopefully provide their actual version in their cmake config once this gets resolved: google/benchmark#1047 |
This PR essentially just changes
CPMAddPackage
toCPMFindPackage
, except for thrust , which is currently still handled in a separate fashion (DOWNLOAD_ONLY
). This makes CMake search for existing locally installed packages (at proper compatible versions) first, and if those don't exist, it falls back to fetching the packages, ie., to current behavior.In theory, this shouldn't break anyone's workflow, since it falls back to current behavior. It does reduce the amount of duplicated libraries and potential resulting conflicts, and also should shorten build times when pre-installed local libraries can be used. In practice, I wouldn't be surprised to find some hiccups, though.
This is a step towards my goal to make RMM more easily packagable in a cmake-compatible fashion -- when using a package manager, RMM should use, e.g., the spdlog provided by the package manager, not pull in its own. This also applies to integration with conda -- currently the conda environment prescribes
spdlog=1.7.0
, but RMM will download and use its own (which is also 1.7.0).Nevertheless, this PR isn't the only way to support locally installed packages -- one can also stick with the current default by keeping
CPMAddPackage
and setting a CMake variable to prefer locally installed packages when desired (e.g., when packaging).