CPM.cmake
CPM.cmake copied to clipboard
Allow to bootstrap cpm-make using FetchContent
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
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.
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.
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?
@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.