Skip to content

Conversation

Arniiiii
Copy link
Contributor

@Arniiiii Arniiiii commented Jan 21, 2025

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 via include(GNUInstallDirs)

But can't find /usr/share/cmake/Modules/PackageProject.cmake via include(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 via find_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 of CPM_LOCAL_PACKAGES_ONLY=1.

I guess it's a win-win.

Cons

  • Current new pull requests that are not merged are going to be broken.

Pros

  • It's installable
  • Can be found via find_package(PackageProject.cmake) which is almost compatible with popular use via CPM
  • Still works via add_subdirectory or downloading via CPM/FetchContent.
  • Tests are fixed
  • CI test added.
  • (fixed) if in CPMAddPackage(PackageProject.cmake) was VERSION 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 put project(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 installing PackageProject.cmakeConfigVersion.cmake aside PackageProject.cmakeConfig.cmake )

Ping @TheLartians

@Arniiiii Arniiiii force-pushed the master branch 2 times, most recently from e885cd1 to 47838fd Compare January 21, 2025 17:28
add CI test for installed PackageProject.cmake utility module

CI: expand a prefix folder to fullpath

Style fix

CI: expand a relative path to fullpath

an attempt to fix

WIP an attempt to fix 2

WIP an attempt to fix 3

style fix

WIP test

WIP maybe pre-final-fix

WIP: CI fix

WIP: what if install to /usr/local ?

Small fix

fix: the project is PackageProject.cmake not PackageProject

style fix
make CPM_DOWNLOAD_LOCATION overridable
@Arniiiii Arniiiii marked this pull request as draft January 24, 2025 20:26
@Arniiiii Arniiiii marked this pull request as ready for review January 24, 2025 23:39
@Arniiiii Arniiiii marked this pull request as draft January 26, 2025 13:21
@Arniiiii Arniiiii marked this pull request as ready for review January 26, 2025 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant