Make PackageProject.cmake installable as utility module #52
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Make PackageProject.cmake installable as utility module
Also I added CI testing for this.
Why?
I try to switch a lot of my code to be usable from Portage, not CPM. Though Portage has one small restriction: no downloading during configuration.
I could live with this telling CPM where is the PackageProject.cmake folder via
CPM_PackageProject.cmake_SOURCE
, but it appeared to be really hard to update: in any "recipe" for every package there will be commit hash of PackageProject.cmake, CPM and maybe some other similar scripts .Thus, now I try to make all such CMake scripts installable.
My notes:
CMake is somewhat hypocritical:
It can have
/usr/share/cmake/Modules/GNUInstallDirs.cmake
and be able to find it viainclude(GNUInstallDirs)
But can't find
/usr/share/cmake/Modules/PackageProject.cmake
viainclude(PackageProject)
. Weird.So, I've used
find_package
way: install the script to/usr/share/cmake/PackageProject/PackageProjectConfig.cmake
to be able to find it viafind_package(PackageProject)
. Theoretically speaking, even when PackageProject.cmake is added via CPM, it would work in both next cases:CPM_DOWNLOAD_ALL=1
and in case ofCPM_LOCAL_PACKAGES_ONLY=1
.I guess it's a win-win.
Cons
Pros
find_package(PackageProject.cmake)
which is almost compatible with popular use via CPMadd_subdirectory
or downloading via CPM/FetchContent.CPMAddPackage(PackageProject.cmake)
wasVERSION xx.x.x
and-DCPM_LOCAL_PACKAGES_ONLY=1
, it will fail, because it will find it, but won't be able to get its version, since I can't putproject(PackageProject.cmake VERSION xx.x.x)
in since then the PackageProject's script itself will fail. ( was solved via renaming local variables in the PackageProject's script and installingPackageProject.cmakeConfigVersion.cmake
asidePackageProject.cmakeConfig.cmake
)Ping @TheLartians