CPM.cmake icon indicating copy to clipboard operation
CPM.cmake copied to clipboard

Allow to bootstrap cpm-make using FetchContent

Open flagarde opened this issue 2 years ago • 4 comments

Hi,

It seems not possible to use cpm-cmake using fetchcontent. It seems the version is not added when tagged and only used to generate the released files.

It would be nice to be able to use FetchContent to download/use it directly in CMake

flagarde avatar Apr 06 '22 14:04 flagarde

If I understand correctly, the issue is that you are not able to download the CPM.cmake script using FetchContent? In general it should be possible to download the script by setting the URL to https://github.com/cpm-cmake/CPM.cmake/releases/download/v<VERSION>/CPM.cmake, however I believe it won't be included automatically, as FetchContent expects a directory containing a CMakeLists.txt file.

@flagarde would it solve your issue if we included a zipped directory with this format in the releases as well? That should allow you to import CPM.cmake using the following:

FetchContent_Declare(
  CPM
  URL https://github.com/cpm-cmake/CPM.cmake/releases/download/v<VERSION>/CPM.zip
)

FetchContent_MakeAvailable(CPM)

Obligatory note that this might prevent configuring projects when offline, even if all dependencies are already cached, as opposed to using the get_cpm.cmake script.

TheLartians avatar Apr 10 '22 18:04 TheLartians

Hi, I will try this but one advantage I see using github tags is that CMake can verify the download are performed without problems. Maybe it could be nice to add the sha256sum check in get_cpm.cmake to avoid any trouble.

flagarde avatar Apr 24 '22 07:04 flagarde

FetchContent_Declare(
  CPM
  URL https://github.com/cpm-cmake/CPM.cmake/releases/download/v<VERSION>/CPM.zip
)

FetchContent_MakeAvailable(CPM)

Obligatory note that this might prevent configuring projects when offline, even if all dependencies are already cached, as opposed to using the get_cpm.cmake script.

Note: this would not work at many companies because of limited or disabled access to internet on CI!

On my company we use a git mirror can only use git clone with git redirect.

One other solution is available with cmake v3.24 : dependency-providers

@TheLartians is your FetchContens emulation working with this?

ClausKlein avatar Sep 20 '22 20:09 ClausKlein

@TheLartians is your FetchContens emulation working with this?

I don't think so, and am unsure if it's compatible with CPM's approach, but I also haven't had the time to do a deep dive into the feature. See also the relevant discussion.

TheLartians avatar Sep 27 '22 18:09 TheLartians