cpm-cmake / CPM.cmake

📦 CMake's missing package manager. A small CMake script for setup-free, cross-platform, reproducible dependency management.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CPM_SOURCE_CACHE is ignored if SOURCE_DIR is set

gerhardol opened this issue · comments

CPM.cmake is great but I see some improvements:

  • When using CPM_SOURCE_CACHE it would be nice to see the version in the cachepath, so you see what version there is on the filesystem
  • If SOURCE_DIR is set, the behavior is basically the same as FetchContent. CPM_SOURCE_CACHE is effectively ignored, you have to implement locking and files are downloaded again each time the command runs.
  • With CPM_SOURCE_CACHE the download dir is a sha from the arguments. If e.g. the patch command has a path, the sha is different also if the contents is identical. The contents of files are not checked though, so the sha is not reliable.

One way to solve all of this is to use SOURCE_DIR as the path if CPM_SOURCE_CACHE is set, at least if SOURCE_DIR starts with CPM_SOURCE_CACHE . Then it is up to the caller to set a unique path that is viewable.
(I also would like to add the version to the sha if not set as an extra measure.)
That would change the behavior slightly, but a new configuration could be confusing too.
Edit: I will start by adding a new argument to CPMAddPackage like CACHE_DIR_NAME, that can be described in a sane way and no backward compatibility issues.

I want to use this to download a 1GB package with compiler etc. That will be shared with maybe 50 application repos so there should be only one copy and must be locked when downloading.
(Annoyingly, the toolchain requires env vars and CMake does not set those so the build script has to download them as a separate step before configure and due to #541 (probably CMake) this must be done in a project()).
So far I have added some private patches but it would be nice to avoid these patches. I can make a PR.